feature missing notification
This commit is contained in:
parent
f0301e563b
commit
e143963a73
@ -0,0 +1,59 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.AddressService;
|
||||
import com.dh7789dev.xpeditis.dto.app.Address;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@RequestMapping(value = "${apiPrefix}/api/v1/addresses",
|
||||
produces = APPLICATION_JSON_VALUE)
|
||||
public class AddressRestController {
|
||||
|
||||
private final AddressService service;
|
||||
|
||||
public AddressRestController(AddressService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Operation(summary = "Create an address")
|
||||
@PostMapping
|
||||
public ResponseEntity<Address> create(@RequestBody Address address) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(service.create(address));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update an address")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Address> update(@PathVariable Long id, @RequestBody Address address) {
|
||||
return ResponseEntity.ok(service.update(id, address));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get an address by id")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Address> getById(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(service.getById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "List addresses")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Address>> list() {
|
||||
return ResponseEntity.ok(service.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete an address")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> delete(@PathVariable Long id) {
|
||||
service.delete(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.CompanyService;
|
||||
import com.dh7789dev.xpeditis.dto.app.Company;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@RequestMapping(value = "${apiPrefix}/api/v1/companies",
|
||||
produces = APPLICATION_JSON_VALUE)
|
||||
public class CompanyRestController {
|
||||
|
||||
private final CompanyService service;
|
||||
|
||||
public CompanyRestController(CompanyService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Operation(summary = "Create a company")
|
||||
@PostMapping
|
||||
public ResponseEntity<Company> create(@RequestBody Company company) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(service.create(company));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update a company")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Company> update(@PathVariable Long id, @RequestBody Company company) {
|
||||
return ResponseEntity.ok(service.update(id, company));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get a company by id")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Company> getById(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(service.getById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "List companies")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Company>> list() {
|
||||
return ResponseEntity.ok(service.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete a company")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> delete(@PathVariable Long id) {
|
||||
service.delete(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.DocumentService;
|
||||
import com.dh7789dev.xpeditis.dto.app.Document;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@RequestMapping(value = "${apiPrefix}/api/v1/documents",
|
||||
produces = APPLICATION_JSON_VALUE)
|
||||
public class DocumentRestController {
|
||||
|
||||
private final DocumentService service;
|
||||
|
||||
public DocumentRestController(DocumentService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Operation(summary = "Create document")
|
||||
@PostMapping
|
||||
public ResponseEntity<Document> create(@RequestBody Document body) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(service.create(body));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update document")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Document> update(@PathVariable Long id, @RequestBody Document body) {
|
||||
return ResponseEntity.ok(service.update(id, body));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get document by id")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Document> getById(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(service.getById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "List documents")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Document>> list() {
|
||||
return ResponseEntity.ok(service.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete document")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> delete(@PathVariable Long id) {
|
||||
service.delete(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.ExportFolderService;
|
||||
import com.dh7789dev.xpeditis.dto.app.ExportFolder;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@RequestMapping(value = "${apiPrefix}/api/v1/export-folders",
|
||||
produces = APPLICATION_JSON_VALUE)
|
||||
public class ExportFolderRestController {
|
||||
|
||||
private final ExportFolderService service;
|
||||
|
||||
public ExportFolderRestController(ExportFolderService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Operation(summary = "Create export folder")
|
||||
@PostMapping
|
||||
public ResponseEntity<ExportFolder> create(@RequestBody ExportFolder body) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(service.create(body));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update export folder")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<ExportFolder> update(@PathVariable Long id, @RequestBody ExportFolder body) {
|
||||
return ResponseEntity.ok(service.update(id, body));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get export folder by id")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<ExportFolder> getById(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(service.getById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "List export folders")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<ExportFolder>> list() {
|
||||
return ResponseEntity.ok(service.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete export folder")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> delete(@PathVariable Long id) {
|
||||
service.delete(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.LicenseService;
|
||||
import com.dh7789dev.xpeditis.dto.app.License;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@RequestMapping(value = "${apiPrefix}/api/v1/licenses",
|
||||
produces = APPLICATION_JSON_VALUE)
|
||||
public class LicenseRestController {
|
||||
|
||||
private final LicenseService service;
|
||||
|
||||
public LicenseRestController(LicenseService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Operation(summary = "Create license")
|
||||
@PostMapping
|
||||
public ResponseEntity<License> create(@RequestBody License body) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(service.create(body));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update license")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<License> update(@PathVariable Long id, @RequestBody License body) {
|
||||
return ResponseEntity.ok(service.update(id, body));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get license by id")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<License> getById(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(service.getById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "List licenses")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<License>> list() {
|
||||
return ResponseEntity.ok(service.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete license")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> delete(@PathVariable Long id) {
|
||||
service.delete(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.QuoteDetailsService;
|
||||
import com.dh7789dev.xpeditis.dto.app.QuoteDetail;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@RequestMapping(value = "${apiPrefix}/api/v1/quote-details",
|
||||
produces = APPLICATION_JSON_VALUE)
|
||||
public class QuoteDetailRestController {
|
||||
|
||||
private final QuoteDetailsService service;
|
||||
|
||||
public QuoteDetailRestController(QuoteDetailsService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Operation(summary = "Create quote detail")
|
||||
@PostMapping
|
||||
public ResponseEntity<QuoteDetail> create(@RequestBody QuoteDetail body) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(service.create(body));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update quote detail")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<QuoteDetail> update(@PathVariable Long id, @RequestBody QuoteDetail body) {
|
||||
return ResponseEntity.ok(service.update(id, body));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get quote detail by id")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<QuoteDetail> getById(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(service.getById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "List quote details")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<QuoteDetail>> list() {
|
||||
return ResponseEntity.ok(service.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete quote detail")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> delete(@PathVariable Long id) {
|
||||
service.delete(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.AddressService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class AddressRestControllerTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private AddressService service;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
service = Mockito.mock(AddressService.class);
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(new AddressRestController(service))
|
||||
.addPlaceholderValue("apiPrefix", "")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_returnsOk() throws Exception {
|
||||
when(service.list()).thenReturn(List.of());
|
||||
mockMvc.perform(get("/api/v1/addresses").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_returnsCreated() throws Exception {
|
||||
when(service.create(org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(post("/api/v1/addresses")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_returnsOk() throws Exception {
|
||||
when(service.update(Mockito.eq(1L), org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(put("/api/v1/addresses/1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getById_returnsOk() throws Exception {
|
||||
when(service.getById(1L)).thenReturn(null);
|
||||
mockMvc.perform(get("/api/v1/addresses/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_returnsNoContent() throws Exception {
|
||||
mockMvc.perform(delete("/api/v1/addresses/1"))
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.CompanyService;
|
||||
import com.dh7789dev.xpeditis.dto.app.Company;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class CompanyRestControllerTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private CompanyService service;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
service = Mockito.mock(CompanyService.class);
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(new CompanyRestController(service))
|
||||
.addPlaceholderValue("apiPrefix", "")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_returnsOk() throws Exception {
|
||||
when(service.list()).thenReturn(List.of());
|
||||
mockMvc.perform(get("/api/v1/companies").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_returnsCreated() throws Exception {
|
||||
when(service.create(org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(post("/api/v1/companies")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_returnsOk() throws Exception {
|
||||
when(service.update(Mockito.eq(1L), org.mockito.ArgumentMatchers.any(Company.class))).thenReturn(null);
|
||||
mockMvc.perform(put("/api/v1/companies/1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getById_returnsOk() throws Exception {
|
||||
when(service.getById(1L)).thenReturn(null);
|
||||
mockMvc.perform(get("/api/v1/companies/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_returnsNoContent() throws Exception {
|
||||
mockMvc.perform(delete("/api/v1/companies/1"))
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.DocumentService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class DocumentRestControllerTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private DocumentService service;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
service = Mockito.mock(DocumentService.class);
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(new DocumentRestController(service))
|
||||
.addPlaceholderValue("apiPrefix", "")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_returnsOk() throws Exception {
|
||||
when(service.list()).thenReturn(List.of());
|
||||
mockMvc.perform(get("/api/v1/documents").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_returnsCreated() throws Exception {
|
||||
when(service.create(org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(post("/api/v1/documents")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_returnsOk() throws Exception {
|
||||
when(service.update(Mockito.eq(1L), org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(put("/api/v1/documents/1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getById_returnsOk() throws Exception {
|
||||
when(service.getById(1L)).thenReturn(null);
|
||||
mockMvc.perform(get("/api/v1/documents/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_returnsNoContent() throws Exception {
|
||||
mockMvc.perform(delete("/api/v1/documents/1"))
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.ExportFolderService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class ExportFolderRestControllerTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private ExportFolderService service;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
service = Mockito.mock(ExportFolderService.class);
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(new ExportFolderRestController(service))
|
||||
.addPlaceholderValue("apiPrefix", "")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_returnsOk() throws Exception {
|
||||
when(service.list()).thenReturn(List.of());
|
||||
mockMvc.perform(get("/api/v1/export-folders").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_returnsCreated() throws Exception {
|
||||
when(service.create(org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(post("/api/v1/export-folders")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_returnsOk() throws Exception {
|
||||
when(service.update(Mockito.eq(1L), org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(put("/api/v1/export-folders/1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getById_returnsOk() throws Exception {
|
||||
when(service.getById(1L)).thenReturn(null);
|
||||
mockMvc.perform(get("/api/v1/export-folders/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_returnsNoContent() throws Exception {
|
||||
mockMvc.perform(delete("/api/v1/export-folders/1"))
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.LicenseService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class LicenseRestControllerTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private LicenseService service;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
service = Mockito.mock(LicenseService.class);
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(new LicenseRestController(service))
|
||||
.addPlaceholderValue("apiPrefix", "")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_returnsOk() throws Exception {
|
||||
when(service.list()).thenReturn(List.of());
|
||||
mockMvc.perform(get("/api/v1/licenses").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_returnsCreated() throws Exception {
|
||||
when(service.create(org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(post("/api/v1/licenses")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_returnsOk() throws Exception {
|
||||
when(service.update(Mockito.eq(1L), org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(put("/api/v1/licenses/1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getById_returnsOk() throws Exception {
|
||||
when(service.getById(1L)).thenReturn(null);
|
||||
mockMvc.perform(get("/api/v1/licenses/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_returnsNoContent() throws Exception {
|
||||
mockMvc.perform(delete("/api/v1/licenses/1"))
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
package com.dh7789dev.xpeditis.controller.api.v1;
|
||||
|
||||
import com.dh7789dev.xpeditis.QuoteDetailsService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class QuoteDetailRestControllerTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private QuoteDetailsService service;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
service = Mockito.mock(QuoteDetailsService.class);
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(new QuoteDetailRestController(service))
|
||||
.addPlaceholderValue("apiPrefix", "")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_returnsOk() throws Exception {
|
||||
when(service.list()).thenReturn(List.of());
|
||||
mockMvc.perform(get("/api/v1/quote-details").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_returnsCreated() throws Exception {
|
||||
when(service.create(org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(post("/api/v1/quote-details")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_returnsOk() throws Exception {
|
||||
when(service.update(Mockito.eq(1L), org.mockito.ArgumentMatchers.any())).thenReturn(null);
|
||||
mockMvc.perform(put("/api/v1/quote-details/1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getById_returnsOk() throws Exception {
|
||||
when(service.getById(1L)).thenReturn(null);
|
||||
mockMvc.perform(get("/api/v1/quote-details/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_returnsNoContent() throws Exception {
|
||||
mockMvc.perform(delete("/api/v1/quote-details/1"))
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.Address;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AddressService {
|
||||
Address create(Address address);
|
||||
|
||||
Address update(Long id, Address address);
|
||||
|
||||
Address getById(Long id);
|
||||
|
||||
List<Address> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.Company;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CompanyService {
|
||||
Company create(Company company);
|
||||
|
||||
Company update(Long id, Company company);
|
||||
|
||||
Company getById(Long id);
|
||||
|
||||
List<Company> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.Document;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DocumentService {
|
||||
Document create(Document document);
|
||||
|
||||
Document update(Long id, Document document);
|
||||
|
||||
Document getById(Long id);
|
||||
|
||||
List<Document> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.ExportFolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExportFolderService {
|
||||
ExportFolder create(ExportFolder exportFolder);
|
||||
|
||||
ExportFolder update(Long id, ExportFolder exportFolder);
|
||||
|
||||
ExportFolder getById(Long id);
|
||||
|
||||
List<ExportFolder> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.License;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface LicenseService {
|
||||
License create(License license);
|
||||
|
||||
License update(Long id, License license);
|
||||
|
||||
License getById(Long id);
|
||||
|
||||
List<License> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.QuoteDetail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface QuoteDetailsService {
|
||||
QuoteDetail create(QuoteDetail quoteDetail);
|
||||
|
||||
QuoteDetail update(Long id, QuoteDetail quoteDetail);
|
||||
|
||||
QuoteDetail getById(Long id);
|
||||
|
||||
List<QuoteDetail> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,7 +1,41 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.Address;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class AddressServiceImpl implements AddressService {
|
||||
|
||||
private final AddressRepository addressRepository;
|
||||
|
||||
public AddressServiceImpl(AddressRepository addressRepository) {
|
||||
this.addressRepository = addressRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Address create(Address address) {
|
||||
return addressRepository.create(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Address update(Long id, Address address) {
|
||||
return addressRepository.update(id, address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Address getById(Long id) {
|
||||
return addressRepository.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Address> list() {
|
||||
return addressRepository.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
addressRepository.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,41 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.Company;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CompanyServiceImpl implements CompanyService {
|
||||
|
||||
private final CompanyRepository companyRepository;
|
||||
|
||||
public CompanyServiceImpl(CompanyRepository companyRepository) {
|
||||
this.companyRepository = companyRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company create(Company company) {
|
||||
return companyRepository.create(company);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company update(Long id, Company company) {
|
||||
return companyRepository.update(id, company);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company getById(Long id) {
|
||||
return companyRepository.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Company> list() {
|
||||
return companyRepository.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
companyRepository.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,40 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.Document;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DocumentServiceImpl implements DocumentService {
|
||||
private final DocumentRepository repository;
|
||||
|
||||
public DocumentServiceImpl(DocumentRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document create(Document document) {
|
||||
return repository.create(document);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document update(Long id, Document document) {
|
||||
return repository.update(id, document);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document getById(Long id) {
|
||||
return repository.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Document> list() {
|
||||
return repository.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
repository.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,40 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.ExportFolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ExportFolderServiceImpl implements ExportFolderService {
|
||||
private final ExportFolderRepository repository;
|
||||
|
||||
public ExportFolderServiceImpl(ExportFolderRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportFolder create(ExportFolder exportFolder) {
|
||||
return repository.create(exportFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportFolder update(Long id, ExportFolder exportFolder) {
|
||||
return repository.update(id, exportFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportFolder getById(Long id) {
|
||||
return repository.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExportFolder> list() {
|
||||
return repository.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
repository.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,40 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.License;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LicenseServiceImpl implements LicenseService {
|
||||
private final LicenseRepository repository;
|
||||
|
||||
public LicenseServiceImpl(LicenseRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public License create(License license) {
|
||||
return repository.create(license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public License update(Long id, License license) {
|
||||
return repository.update(id, license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getById(Long id) {
|
||||
return repository.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<License> list() {
|
||||
return repository.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
repository.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,40 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.QuoteDetail;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class QuoteDetailsServiceImpl implements QuoteDetailsService {
|
||||
private final QuoteDetailsRepository repository;
|
||||
|
||||
public QuoteDetailsServiceImpl(QuoteDetailsRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuoteDetail create(QuoteDetail quoteDetail) {
|
||||
return repository.create(quoteDetail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuoteDetail update(Long id, QuoteDetail quoteDetail) {
|
||||
return repository.update(id, quoteDetail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuoteDetail getById(Long id) {
|
||||
return repository.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuoteDetail> list() {
|
||||
return repository.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
repository.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.Address;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AddressRepository {
|
||||
Address create(Address address);
|
||||
|
||||
Address update(Long id, Address address);
|
||||
|
||||
Address getById(Long id);
|
||||
|
||||
List<Address> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.Company;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CompanyRepository {
|
||||
Company create(Company company);
|
||||
|
||||
Company update(Long id, Company company);
|
||||
|
||||
Company getById(Long id);
|
||||
|
||||
List<Company> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.Document;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DocumentRepository {
|
||||
Document create(Document document);
|
||||
|
||||
Document update(Long id, Document document);
|
||||
|
||||
Document getById(Long id);
|
||||
|
||||
List<Document> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.ExportFolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExportFolderRepository {
|
||||
ExportFolder create(ExportFolder exportFolder);
|
||||
|
||||
ExportFolder update(Long id, ExportFolder exportFolder);
|
||||
|
||||
ExportFolder getById(Long id);
|
||||
|
||||
List<ExportFolder> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.License;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface LicenseRepository {
|
||||
License create(License license);
|
||||
|
||||
License update(Long id, License license);
|
||||
|
||||
License getById(Long id);
|
||||
|
||||
List<License> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
package com.dh7789dev.xpeditis;
|
||||
|
||||
import com.dh7789dev.xpeditis.dto.app.QuoteDetail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface QuoteDetailsRepository {
|
||||
QuoteDetail create(QuoteDetail quoteDetail);
|
||||
|
||||
QuoteDetail update(Long id, QuoteDetail quoteDetail);
|
||||
|
||||
QuoteDetail getById(Long id);
|
||||
|
||||
List<QuoteDetail> list();
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
|
||||
@ -1,10 +1,54 @@
|
||||
package com.dh7789dev.xpeditis.repository;
|
||||
|
||||
import com.dh7789dev.xpeditis.AddressRepository;
|
||||
import com.dh7789dev.xpeditis.dao.AddressDao;
|
||||
import com.dh7789dev.xpeditis.dto.app.Address;
|
||||
import com.dh7789dev.xpeditis.entity.AddressEntity;
|
||||
import com.dh7789dev.xpeditis.mapper.AddressMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Slf4j
|
||||
@Repository
|
||||
public class AddressJpaRepository implements AddressRepository {
|
||||
private final AddressDao addressDao;
|
||||
private final AddressMapper addressMapper;
|
||||
|
||||
public AddressJpaRepository(AddressDao addressDao, AddressMapper addressMapper) {
|
||||
this.addressDao = addressDao;
|
||||
this.addressMapper = addressMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Address create(Address address) {
|
||||
AddressEntity entity = addressMapper.addressToAddressEntity(address);
|
||||
AddressEntity saved = addressDao.save(entity);
|
||||
return addressMapper.addressEntityToAddress(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Address update(Long id, Address address) {
|
||||
AddressEntity entity = addressDao.findById(id).orElseThrow();
|
||||
if (address.getCompanyName() != null) entity.setCompanyName(address.getCompanyName());
|
||||
if (address.getAddress() != null) entity.setAddress(address.getAddress());
|
||||
if (address.getPostalCode() != null) entity.setPostalCode(address.getPostalCode());
|
||||
if (address.getCountry() != null) entity.setCountry(address.getCountry());
|
||||
AddressEntity saved = addressDao.save(entity);
|
||||
return addressMapper.addressEntityToAddress(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Address getById(Long id) {
|
||||
return addressDao.findById(id).map(addressMapper::addressEntityToAddress).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<Address> list() {
|
||||
return addressDao.findAll().stream().map(addressMapper::addressEntityToAddress).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
addressDao.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,54 @@
|
||||
package com.dh7789dev.xpeditis.repository;
|
||||
|
||||
import com.dh7789dev.xpeditis.CompanyRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.dh7789dev.xpeditis.dao.CompanyDao;
|
||||
import com.dh7789dev.xpeditis.dto.app.Company;
|
||||
import com.dh7789dev.xpeditis.entity.CompanyEntity;
|
||||
import com.dh7789dev.xpeditis.mapper.CompanyMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Slf4j
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class CompanyJpaRepository implements CompanyRepository {
|
||||
|
||||
private final CompanyDao companyDao;
|
||||
private final CompanyMapper companyMapper;
|
||||
|
||||
public CompanyJpaRepository(CompanyDao companyDao, CompanyMapper companyMapper) {
|
||||
this.companyDao = companyDao;
|
||||
this.companyMapper = companyMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company create(Company company) {
|
||||
CompanyEntity entity = companyMapper.companyToCompanyEntity(company);
|
||||
CompanyEntity saved = companyDao.save(entity);
|
||||
return companyMapper.companyEntityToCompany(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company update(Long id, Company company) {
|
||||
CompanyEntity entity = companyDao.findById(id).orElseThrow();
|
||||
if (company.getName() != null) entity.setName(company.getName());
|
||||
if (company.getCountry() != null) entity.setCountry(company.getCountry());
|
||||
CompanyEntity saved = companyDao.save(entity);
|
||||
return companyMapper.companyEntityToCompany(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company getById(Long id) {
|
||||
return companyDao.findById(id).map(companyMapper::companyEntityToCompany).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Company> list() {
|
||||
return companyDao.findAll().stream().map(companyMapper::companyEntityToCompany).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
companyDao.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,55 @@
|
||||
package com.dh7789dev.xpeditis.repository;
|
||||
|
||||
import com.dh7789dev.xpeditis.DocumentRepository;
|
||||
import com.dh7789dev.xpeditis.dao.DocumentDao;
|
||||
import com.dh7789dev.xpeditis.dto.app.Document;
|
||||
import com.dh7789dev.xpeditis.entity.DocumentEntity;
|
||||
import com.dh7789dev.xpeditis.mapper.DocumentMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Repository
|
||||
public class DocumentJpaRepository implements DocumentRepository {
|
||||
private final DocumentDao dao;
|
||||
private final DocumentMapper mapper;
|
||||
|
||||
public DocumentJpaRepository(DocumentDao dao, DocumentMapper mapper) {
|
||||
this.dao = dao;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document create(Document document) {
|
||||
DocumentEntity entity = mapper.documentToDocumentEntity(document);
|
||||
DocumentEntity saved = dao.save(entity);
|
||||
return mapper.documentEntityToDocument(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document update(Long id, Document document) {
|
||||
DocumentEntity entity = dao.findById(id).orElseThrow();
|
||||
if (document.getFileName() != null) entity.setFileName(document.getFileName());
|
||||
if (document.getContentType() != null) entity.setContentType(document.getContentType());
|
||||
if (document.getData() != null) entity.setData(document.getData());
|
||||
DocumentEntity saved = dao.save(entity);
|
||||
return mapper.documentEntityToDocument(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document getById(Long id) {
|
||||
return dao.findById(id).map(mapper::documentEntityToDocument).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Document> list() {
|
||||
return dao.findAll().stream().map(mapper::documentEntityToDocument).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
dao.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,54 @@
|
||||
package com.dh7789dev.xpeditis.repository;
|
||||
|
||||
import com.dh7789dev.xpeditis.ExportFolderRepository;
|
||||
import com.dh7789dev.xpeditis.dao.ExportFolderDao;
|
||||
import com.dh7789dev.xpeditis.dto.app.ExportFolder;
|
||||
import com.dh7789dev.xpeditis.entity.ExportFolderEntity;
|
||||
import com.dh7789dev.xpeditis.mapper.ExportFolderMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Repository
|
||||
public class ExportFolderJpaRepository implements ExportFolderRepository {
|
||||
private final ExportFolderDao dao;
|
||||
private final ExportFolderMapper mapper;
|
||||
|
||||
public ExportFolderJpaRepository(ExportFolderDao dao, ExportFolderMapper mapper) {
|
||||
this.dao = dao;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportFolder create(ExportFolder exportFolder) {
|
||||
ExportFolderEntity entity = mapper.exportFolderToCompanyEntity(exportFolder);
|
||||
ExportFolderEntity saved = dao.save(entity);
|
||||
return mapper.exportFolderEntityToExportFolder(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportFolder update(Long id, ExportFolder exportFolder) {
|
||||
ExportFolderEntity entity = dao.findById(id).orElseThrow();
|
||||
if (exportFolder.getReference() != null) entity.setReference(exportFolder.getReference());
|
||||
if (exportFolder.getValidationDate() != null) entity.setValidationDate(exportFolder.getValidationDate());
|
||||
ExportFolderEntity saved = dao.save(entity);
|
||||
return mapper.exportFolderEntityToExportFolder(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExportFolder getById(Long id) {
|
||||
return dao.findById(id).map(mapper::exportFolderEntityToExportFolder).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExportFolder> list() {
|
||||
return dao.findAll().stream().map(mapper::exportFolderEntityToExportFolder).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
dao.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,55 @@
|
||||
package com.dh7789dev.xpeditis.repository;
|
||||
|
||||
import com.dh7789dev.xpeditis.LicenseRepository;
|
||||
import com.dh7789dev.xpeditis.dao.LicenseDao;
|
||||
import com.dh7789dev.xpeditis.dto.app.License;
|
||||
import com.dh7789dev.xpeditis.entity.LicenseEntity;
|
||||
import com.dh7789dev.xpeditis.mapper.LicenseMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Repository
|
||||
public class LicenseJpaRepository implements LicenseRepository {
|
||||
private final LicenseDao dao;
|
||||
private final LicenseMapper mapper;
|
||||
|
||||
public LicenseJpaRepository(LicenseDao dao, LicenseMapper mapper) {
|
||||
this.dao = dao;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public License create(License license) {
|
||||
LicenseEntity entity = mapper.licenseToLicenseEntity(license);
|
||||
LicenseEntity saved = dao.save(entity);
|
||||
return mapper.licenseEntityToLicense(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public License update(Long id, License license) {
|
||||
LicenseEntity entity = dao.findById(id).orElseThrow();
|
||||
if (license.getLicenseKey() != null) entity.setLicenseKey(license.getLicenseKey());
|
||||
if (license.getExpirationDate() != null) entity.setExpirationDate(license.getExpirationDate());
|
||||
entity.setActive(license.isActive());
|
||||
LicenseEntity saved = dao.save(entity);
|
||||
return mapper.licenseEntityToLicense(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getById(Long id) {
|
||||
return dao.findById(id).map(mapper::licenseEntityToLicense).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<License> list() {
|
||||
return dao.findAll().stream().map(mapper::licenseEntityToLicense).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
dao.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,61 @@
|
||||
package com.dh7789dev.xpeditis.repository;
|
||||
|
||||
|
||||
import com.dh7789dev.xpeditis.QuoteDetailsRepository;
|
||||
import com.dh7789dev.xpeditis.dao.QuoteDetailDao;
|
||||
import com.dh7789dev.xpeditis.dto.app.QuoteDetail;
|
||||
import com.dh7789dev.xpeditis.entity.QuoteDetailEntity;
|
||||
import com.dh7789dev.xpeditis.mapper.DimensionMapper;
|
||||
import com.dh7789dev.xpeditis.mapper.QuoteDetailMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Repository
|
||||
public class QuoteDetailsJpaRepository implements QuoteDetailsRepository {
|
||||
private final QuoteDetailDao dao;
|
||||
private final QuoteDetailMapper mapper;
|
||||
private final DimensionMapper dimensionMapper;
|
||||
|
||||
public QuoteDetailsJpaRepository(QuoteDetailDao dao, QuoteDetailMapper mapper, DimensionMapper dimensionMapper) {
|
||||
this.dao = dao;
|
||||
this.mapper = mapper;
|
||||
this.dimensionMapper = dimensionMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuoteDetail create(QuoteDetail quoteDetail) {
|
||||
QuoteDetailEntity entity = mapper.quoteDetailsToQuoteDetailsEntity(quoteDetail);
|
||||
QuoteDetailEntity saved = dao.save(entity);
|
||||
return mapper.quoteDetailsEntityToQuoteDetails(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuoteDetail update(Long id, QuoteDetail quoteDetail) {
|
||||
QuoteDetailEntity entity = dao.findById(id).orElseThrow();
|
||||
if (quoteDetail.getQuantity() != null) entity.setQuantity(quoteDetail.getQuantity());
|
||||
if (quoteDetail.getDimension() != null) {
|
||||
entity.setDimension(dimensionMapper.dimensionToDimensionEntity(quoteDetail.getDimension()));
|
||||
}
|
||||
if (quoteDetail.getWeight() != null) entity.setWeight(quoteDetail.getWeight());
|
||||
entity.setGerbable(quoteDetail.isStackable());
|
||||
QuoteDetailEntity saved = dao.save(entity);
|
||||
return mapper.quoteDetailsEntityToQuoteDetails(saved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuoteDetail getById(Long id) {
|
||||
return dao.findById(id).map(mapper::quoteDetailsEntityToQuoteDetails).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuoteDetail> list() {
|
||||
return dao.findAll().stream().map(mapper::quoteDetailsEntityToQuoteDetails).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
dao.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,18 +1,108 @@
|
||||
package com.dh7789dev.xpeditis.repository;
|
||||
|
||||
|
||||
import com.dh7789dev.xpeditis.dao.AddressDao;
|
||||
import com.dh7789dev.xpeditis.dto.app.Address;
|
||||
import com.dh7789dev.xpeditis.entity.AddressEntity;
|
||||
import com.dh7789dev.xpeditis.mapper.AddressMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class AddressJpaRepositoryTest {
|
||||
|
||||
private AddressDao addressDao;
|
||||
private AddressMapper addressMapper;
|
||||
private AddressJpaRepository repository;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
addressDao = mock(AddressDao.class);
|
||||
addressMapper = new AddressMapper() {
|
||||
@Override
|
||||
public AddressEntity addressToAddressEntity(Address address) {
|
||||
AddressEntity e = new AddressEntity();
|
||||
e.setCompanyName(address.getCompanyName());
|
||||
e.setAddress(address.getAddress());
|
||||
e.setPostalCode(address.getPostalCode());
|
||||
e.setCountry(address.getCountry());
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Address addressEntityToAddress(AddressEntity addressEntity) {
|
||||
return new Address(
|
||||
addressEntity.getId(),
|
||||
addressEntity.getCompanyName(),
|
||||
addressEntity.getAddress(),
|
||||
addressEntity.getPostalCode(),
|
||||
addressEntity.getCountry(),
|
||||
null,
|
||||
null,
|
||||
addressEntity.getCreatedAt(),
|
||||
addressEntity.getModifiedAt()
|
||||
);
|
||||
}
|
||||
};
|
||||
repository = new AddressJpaRepository(addressDao, addressMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test(){
|
||||
int test = 1 +1;
|
||||
assertEquals(2,test);
|
||||
void create_saves_and_returns_mapped() {
|
||||
Address input = new Address(null, "ACME", "1 rue", "75001", "FR", null, null, null, null);
|
||||
when(addressDao.save(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
|
||||
Address created = repository.create(input);
|
||||
|
||||
var captor = org.mockito.ArgumentCaptor.forClass(AddressEntity.class);
|
||||
verify(addressDao).save(captor.capture());
|
||||
AddressEntity persisted = captor.getValue();
|
||||
assertThat(persisted.getCompanyName()).isEqualTo("ACME");
|
||||
assertThat(created.getCompanyName()).isEqualTo("ACME");
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_edits_mutable_fields() {
|
||||
Long id = 1L;
|
||||
AddressEntity existing = new AddressEntity();
|
||||
existing.setCompanyName("OLD");
|
||||
when(addressDao.findById(id)).thenReturn(Optional.of(existing));
|
||||
when(addressDao.save(existing)).thenReturn(existing);
|
||||
|
||||
Address updated = repository.update(id, new Address(null, "NEW", "2 ave", "75002", "FR", null, null, null, null));
|
||||
|
||||
assertThat(updated.getCompanyName()).isEqualTo("NEW");
|
||||
verify(addressDao).save(existing);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getById_maps() {
|
||||
AddressEntity e = new AddressEntity();
|
||||
e.setCompanyName("X");
|
||||
when(addressDao.findById(7L)).thenReturn(Optional.of(e));
|
||||
|
||||
Address got = repository.getById(7L);
|
||||
assertThat(got.getCompanyName()).isEqualTo("X");
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_maps_all() {
|
||||
AddressEntity e = new AddressEntity();
|
||||
e.setCompanyName("Y");
|
||||
when(addressDao.findAll()).thenReturn(List.of(e));
|
||||
|
||||
List<Address> result = repository.list();
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result.get(0).getCompanyName()).isEqualTo("Y");
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_calls_dao() {
|
||||
repository.delete(10L);
|
||||
verify(addressDao).deleteById(10L);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,19 +1,80 @@
|
||||
package com.dh7789dev.xpeditis.repository;
|
||||
|
||||
|
||||
import com.dh7789dev.xpeditis.dao.CompanyDao;
|
||||
import com.dh7789dev.xpeditis.dto.app.Company;
|
||||
import com.dh7789dev.xpeditis.entity.CompanyEntity;
|
||||
import com.dh7789dev.xpeditis.mapper.CompanyMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CompanyJpaRepositoryTest {
|
||||
|
||||
private CompanyDao companyDao;
|
||||
private CompanyMapper companyMapper;
|
||||
private CompanyJpaRepository repository;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
companyDao = mock(CompanyDao.class);
|
||||
companyMapper = new CompanyMapper() {
|
||||
@Override
|
||||
public CompanyEntity companyToCompanyEntity(Company company) {
|
||||
CompanyEntity e = new CompanyEntity();
|
||||
e.setName(company.getName());
|
||||
e.setCountry(company.getCountry());
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company companyEntityToCompany(CompanyEntity companyEntity) {
|
||||
return new Company(companyEntity.getId(), companyEntity.getName(), companyEntity.getCountry(), null, null, null);
|
||||
}
|
||||
};
|
||||
repository = new CompanyJpaRepository(companyDao, companyMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test(){
|
||||
int test = 1 +1;
|
||||
assertEquals(2,test);
|
||||
void create_saves_and_returns_mapped() {
|
||||
Company input = new Company(null, "ACME", "FR", null, null, null);
|
||||
when(companyDao.save(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
|
||||
Company created = repository.create(input);
|
||||
|
||||
var captor = org.mockito.ArgumentCaptor.forClass(CompanyEntity.class);
|
||||
verify(companyDao).save(captor.capture());
|
||||
CompanyEntity persisted = captor.getValue();
|
||||
assertThat(persisted.getName()).isEqualTo("ACME");
|
||||
assertThat(created.getName()).isEqualTo("ACME");
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_edits_mutable_fields() {
|
||||
Long id = 1L;
|
||||
CompanyEntity existing = new CompanyEntity();
|
||||
existing.setName("OLD");
|
||||
when(companyDao.findById(id)).thenReturn(Optional.of(existing));
|
||||
when(companyDao.save(existing)).thenReturn(existing);
|
||||
|
||||
Company updated = repository.update(id, new Company(null, "NEW", "US", null, null, null));
|
||||
|
||||
assertThat(updated.getName()).isEqualTo("NEW");
|
||||
verify(companyDao).save(existing);
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_maps_all() {
|
||||
CompanyEntity e = new CompanyEntity();
|
||||
e.setName("X");
|
||||
when(companyDao.findAll()).thenReturn(List.of(e));
|
||||
|
||||
List<Company> result = repository.list();
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result.get(0).getName()).isEqualTo("X");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,19 +1,133 @@
|
||||
package com.dh7789dev.xpeditis.repository;
|
||||
|
||||
|
||||
import com.dh7789dev.xpeditis.dao.QuoteDetailDao;
|
||||
import com.dh7789dev.xpeditis.dto.app.Dimension;
|
||||
import com.dh7789dev.xpeditis.dto.app.QuoteDetail;
|
||||
import com.dh7789dev.xpeditis.entity.DimensionEntity;
|
||||
import com.dh7789dev.xpeditis.entity.QuoteDetailEntity;
|
||||
import com.dh7789dev.xpeditis.mapper.DimensionMapper;
|
||||
import com.dh7789dev.xpeditis.mapper.QuoteDetailMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class QuoteDetailsJpaRepositoryTest {
|
||||
|
||||
private QuoteDetailDao dao;
|
||||
private QuoteDetailMapper mapper;
|
||||
private DimensionMapper dimensionMapper;
|
||||
private QuoteDetailsJpaRepository repository;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
dao = mock(QuoteDetailDao.class);
|
||||
mapper = new QuoteDetailMapper() {
|
||||
@Override
|
||||
public QuoteDetailEntity quoteDetailsToQuoteDetailsEntity(QuoteDetail quoteDetail) {
|
||||
QuoteDetailEntity e = new QuoteDetailEntity();
|
||||
e.setQuantity(quoteDetail.getQuantity());
|
||||
if (quoteDetail.getDimension() != null) {
|
||||
DimensionEntity d = new DimensionEntity();
|
||||
d.setLength(quoteDetail.getDimension().getLength());
|
||||
d.setWidth(quoteDetail.getDimension().getWidth());
|
||||
d.setHeight(quoteDetail.getDimension().getHeight());
|
||||
e.setDimension(d);
|
||||
}
|
||||
e.setWeight(quoteDetail.getWeight());
|
||||
e.setGerbable(quoteDetail.isStackable());
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuoteDetail quoteDetailsEntityToQuoteDetails(QuoteDetailEntity quoteDetailEntity) {
|
||||
Dimension dim = null;
|
||||
if (quoteDetailEntity.getDimension() != null) {
|
||||
dim = new Dimension(null,
|
||||
quoteDetailEntity.getDimension().getLength(),
|
||||
quoteDetailEntity.getDimension().getWidth(),
|
||||
quoteDetailEntity.getDimension().getHeight());
|
||||
}
|
||||
return new QuoteDetail(
|
||||
quoteDetailEntity.getId(),
|
||||
quoteDetailEntity.getQuantity(),
|
||||
dim,
|
||||
quoteDetailEntity.getWeight(),
|
||||
quoteDetailEntity.isGerbable(),
|
||||
null
|
||||
);
|
||||
}
|
||||
};
|
||||
dimensionMapper = new DimensionMapper() {
|
||||
@Override
|
||||
public DimensionEntity dimensionToDimensionEntity(Dimension dimension) {
|
||||
DimensionEntity e = new DimensionEntity();
|
||||
e.setLength(dimension.getLength());
|
||||
e.setWidth(dimension.getWidth());
|
||||
e.setHeight(dimension.getHeight());
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension dimensionEntityToDimension(DimensionEntity dimensionEntity) {
|
||||
return new Dimension(null, dimensionEntity.getLength(), dimensionEntity.getWidth(), dimensionEntity.getHeight());
|
||||
}
|
||||
};
|
||||
repository = new QuoteDetailsJpaRepository(dao, mapper, dimensionMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test(){
|
||||
int test = 1 +1;
|
||||
assertEquals(2,test);
|
||||
void create_saves_and_returns_mapped() {
|
||||
when(dao.save(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||
QuoteDetail input = new QuoteDetail(null, 2, new Dimension(null, 1.0, 2.0, 3.0), 10.5, true, null);
|
||||
QuoteDetail created = repository.create(input);
|
||||
|
||||
var captor = org.mockito.ArgumentCaptor.forClass(QuoteDetailEntity.class);
|
||||
verify(dao).save(captor.capture());
|
||||
QuoteDetailEntity persisted = captor.getValue();
|
||||
assertThat(persisted.getQuantity()).isEqualTo(2);
|
||||
assertThat(created.getQuantity()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_edits_mutable_fields() {
|
||||
Long id = 1L;
|
||||
QuoteDetailEntity existing = new QuoteDetailEntity();
|
||||
existing.setQuantity(1);
|
||||
when(dao.findById(id)).thenReturn(Optional.of(existing));
|
||||
when(dao.save(existing)).thenReturn(existing);
|
||||
|
||||
QuoteDetail updated = repository.update(id, new QuoteDetail(null, 3, new Dimension(null, 4.0, 5.0, 6.0), 12.0, false, null));
|
||||
assertThat(updated.getQuantity()).isEqualTo(3);
|
||||
verify(dao).save(existing);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getById_maps() {
|
||||
QuoteDetailEntity e = new QuoteDetailEntity();
|
||||
e.setQuantity(5);
|
||||
when(dao.findById(7L)).thenReturn(Optional.of(e));
|
||||
QuoteDetail got = repository.getById(7L);
|
||||
assertThat(got.getQuantity()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_maps_all() {
|
||||
QuoteDetailEntity e = new QuoteDetailEntity();
|
||||
e.setQuantity(7);
|
||||
when(dao.findAll()).thenReturn(List.of(e));
|
||||
List<QuoteDetail> result = repository.list();
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result.get(0).getQuantity()).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_calls_dao() {
|
||||
repository.delete(10L);
|
||||
verify(dao).deleteById(10L);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user