Commits (2)
...@@ -35,7 +35,7 @@ public interface GeographicAddressManagementApi { ...@@ -35,7 +35,7 @@ public interface GeographicAddressManagementApi {
return getRequest().map(r -> r.getHeader("Accept")); return getRequest().map(r -> r.getHeader("Accept"));
} }
@Operation(summary = "Creates a 'GeographicAddress'", operationId = "createGeographicAddress", description = "", tags={ "geographicAddress", }) @Operation(summary = "Creates a 'GeographicAddress'", operationId = "createGeographicAddress", description = "", tags={ "GeographicAddress", })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "400", description = "Created" ), @ApiResponse(responseCode = "400", description = "Created" ),
@ApiResponse(responseCode = "400", description = "Bad Request" ), @ApiResponse(responseCode = "400", description = "Bad Request" ),
...@@ -61,8 +61,7 @@ public interface GeographicAddressManagementApi { ...@@ -61,8 +61,7 @@ public interface GeographicAddressManagementApi {
@ApiResponse(responseCode = "409", description = "Conflict" ), @ApiResponse(responseCode = "409", description = "Conflict" ),
@ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) @ApiResponse(responseCode = "500", description = "Internal Server Error" ) })
@DeleteMapping(value = "/geographicAddress/{id}", @DeleteMapping(value = "/geographicAddress/{id}",
produces = { "application/json" }, produces = { "application/json" })
consumes = { "application/json" })
ResponseEntity<Void> deleteGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id); ResponseEntity<Void> deleteGeographicAddress(@Parameter(description = "Identifier of the Geographic address", required = true) @PathVariable("id") String id);
...@@ -123,7 +122,7 @@ public interface GeographicAddressManagementApi { ...@@ -123,7 +122,7 @@ public interface GeographicAddressManagementApi {
@ApiResponse(responseCode = "500", description = "Internal Server Error" ) }) @ApiResponse(responseCode = "500", description = "Internal Server Error" ) })
@GetMapping(value = "/geographicAddress/{id}/geographicSubAddress", @GetMapping(value = "/geographicAddress/{id}/geographicSubAddress",
produces = { "application/json" }) produces = { "application/json" })
ResponseEntity<Set<GeographicSubAddress>> retrieveGeographicSubAddress( ResponseEntity<Set<GeographicSubAddress>> retrieveGeographicSubAddresses(
@Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id); @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id);
@Operation(summary = "Retrieves a 'GeographicSubAddress' by Id", operationId = "retrieveGeographicSubAddress", description = "" , tags={ "GeographicSubAddress", }) @Operation(summary = "Retrieves a 'GeographicSubAddress' by Id", operationId = "retrieveGeographicSubAddress", description = "" , tags={ "GeographicSubAddress", })
......
...@@ -37,7 +37,7 @@ public class GeographicAddressManagementApiController implements GeographicAddre ...@@ -37,7 +37,7 @@ public class GeographicAddressManagementApiController implements GeographicAddre
@Override @Override
public ResponseEntity<List<GeographicAddress>> listGeographicAddress() { public ResponseEntity<List<GeographicAddress>> listGeographicAddress() {
try { try {
return new ResponseEntity<>(geographicAddressManagementService.findAllGeographicAddresss(), HttpStatus.OK); return new ResponseEntity<>(geographicAddressManagementService.findAllGeographicAddress(), HttpStatus.OK);
} catch (Exception e) { } catch (Exception e) {
log.error(COULD_NOT_SERIALIZE, e); log.error(COULD_NOT_SERIALIZE, e);
...@@ -89,7 +89,7 @@ public class GeographicAddressManagementApiController implements GeographicAddre ...@@ -89,7 +89,7 @@ public class GeographicAddressManagementApiController implements GeographicAddre
@PreAuthorize("hasAnyAuthority('ROLE_USER')" ) @PreAuthorize("hasAnyAuthority('ROLE_USER')" )
@Override @Override
public ResponseEntity<Set<GeographicSubAddress>> retrieveGeographicSubAddress( public ResponseEntity<Set<GeographicSubAddress>> retrieveGeographicSubAddresses(
@Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id) { @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id) {
try{ try{
Set<GeographicSubAddress> c = geographicAddressManagementService.findAllGeographicSubAddresses(id); Set<GeographicSubAddress> c = geographicAddressManagementService.findAllGeographicSubAddresses(id);
...@@ -120,8 +120,8 @@ public class GeographicAddressManagementApiController implements GeographicAddre ...@@ -120,8 +120,8 @@ public class GeographicAddressManagementApiController implements GeographicAddre
@PreAuthorize("hasAnyAuthority('ROLE_USER')" ) @PreAuthorize("hasAnyAuthority('ROLE_USER')" )
@Override @Override
public ResponseEntity<GeographicSubAddress> retrieveGeographicSubAddress( public ResponseEntity<GeographicSubAddress> retrieveGeographicSubAddress(
@Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String geoAddressId, @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("geoAddressId") String geoAddressId,
@Parameter(description = "Identifier of the geographic sub address", required = true) @PathVariable("id") String geoSubAddressId){ @Parameter(description = "Identifier of the geographic sub address", required = true) @PathVariable("geoSubAddressId") String geoSubAddressId){
try{ try{
GeographicSubAddress c = geographicAddressManagementService.findGeographicSubAddressByUUID(geoAddressId,geoSubAddressId); GeographicSubAddress c = geographicAddressManagementService.findGeographicSubAddressByUUID(geoAddressId,geoSubAddressId);
......
...@@ -33,7 +33,7 @@ public interface GeographicAddressValidationManagementApi { ...@@ -33,7 +33,7 @@ public interface GeographicAddressValidationManagementApi {
return getRequest().map(r -> r.getHeader("Accept")); return getRequest().map(r -> r.getHeader("Accept"));
} }
@Operation(summary = "Creates a 'GeographicAddressValidation'", operationId = "createGeographicAddressValidation", description = "", tags={ "geographicAddress", }) @Operation(summary = "Creates a 'GeographicAddressValidation'", operationId = "createGeographicAddressValidation", description = "", tags={ "GeographicAddressValidation", })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(responseCode = "400", description = "Created" ), @ApiResponse(responseCode = "400", description = "Created" ),
@ApiResponse(responseCode = "400", description = "Bad Request" ), @ApiResponse(responseCode = "400", description = "Bad Request" ),
......
...@@ -4,7 +4,6 @@ import org.etsi.osl.tmf.gam673.mapper.MapperUtils; ...@@ -4,7 +4,6 @@ import org.etsi.osl.tmf.gam673.mapper.MapperUtils;
import org.etsi.osl.tmf.gam673.model.GeographicAddress; import org.etsi.osl.tmf.gam673.model.GeographicAddress;
import org.etsi.osl.tmf.gam673.model.GeographicSubAddress; import org.etsi.osl.tmf.gam673.model.GeographicSubAddress;
import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository; import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository;
import org.etsi.osl.tmf.prm669.model.RelatedParty;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -30,7 +29,7 @@ public class GeographicAddressManagementService { ...@@ -30,7 +29,7 @@ public class GeographicAddressManagementService {
this.geographicAddressManagementRepository = geographicAddressManagementRepository; this.geographicAddressManagementRepository = geographicAddressManagementRepository;
} }
public List<GeographicAddress> findAllGeographicAddresss(){ public List<GeographicAddress> findAllGeographicAddress(){
return (List<GeographicAddress>) geographicAddressManagementRepository.findAll(); return (List<GeographicAddress>) geographicAddressManagementRepository.findAll();
} }
...@@ -59,7 +58,7 @@ public class GeographicAddressManagementService { ...@@ -59,7 +58,7 @@ public class GeographicAddressManagementService {
public GeographicAddress updateGeographicAddress(String id,GeographicAddress geographicAddress){ public GeographicAddress updateGeographicAddress(String id,GeographicAddress geographicAddress){
log.info("Update geographic address with id: {}",id); log.info("Update geographic address with id: {}",id);
Optional<GeographicAddress> gs=geographicAddressManagementRepository.findByUuid(id); Optional<GeographicAddress> gs = geographicAddressManagementRepository.findByUuid(id);
return gs.map(address -> updateFields(geographicAddress, address)).orElse(null); return gs.map(address -> updateFields(geographicAddress, address)).orElse(null);
} }
......
...@@ -42,10 +42,10 @@ public class GeographicAddressValidationManagementService { ...@@ -42,10 +42,10 @@ public class GeographicAddressValidationManagementService {
} }
public GeographicAddressValidation updateGeographicAddressValidation(String id,GeographicAddressValidation geographicAddressValidation){ public GeographicAddressValidation updateGeographicAddressValidation(String id,GeographicAddressValidation newGeographicAddressValidation){
log.info("Update geographic address validation with id: {}",id); log.info("Update geographic address validation with id: {}",id);
Optional<GeographicAddressValidation> gs=geographicAddressValidationManagementRepository.findByUuid(id); Optional<GeographicAddressValidation> gs=geographicAddressValidationManagementRepository.findByUuid(id);
return gs.map(address -> updateFields(geographicAddressValidation, address)).orElse(null); return gs.map(oldAddress -> updateFields(newGeographicAddressValidation, oldAddress)).orElse(null);
} }
public Void deleteGeographicAddressValidationById(String id){ public Void deleteGeographicAddressValidationById(String id){
...@@ -66,6 +66,12 @@ public class GeographicAddressValidationManagementService { ...@@ -66,6 +66,12 @@ public class GeographicAddressValidationManagementService {
for(GeographicAddress n : newGeographicAddressValidation.getAlternateGeographicAddresses()){ for(GeographicAddress n : newGeographicAddressValidation.getAlternateGeographicAddresses()){
if(n.getUuid()==null){ if(n.getUuid()==null){
existingGeographicAddressValidation.addGeographicAddress(n); existingGeographicAddressValidation.addGeographicAddress(n);
}else {
for (GeographicAddress oldGeographicAddress : existingGeographicAddressValidation.getAlternateGeographicAddresses()){
if (n.getUuid().equals(oldGeographicAddress.getUuid())){
GeographicAddress geographicAddress = mapperUtils.geographicAddressMap(n, oldGeographicAddress);
}
}
} }
} }
} }
......
...@@ -2,6 +2,7 @@ package org.etsi.osl.services.api.gam673; ...@@ -2,6 +2,7 @@ package org.etsi.osl.services.api.gam673;
import org.etsi.osl.tmf.gam673.api.GeographicAddressManagementApiController; import org.etsi.osl.tmf.gam673.api.GeographicAddressManagementApiController;
import org.etsi.osl.tmf.gam673.model.GeographicAddress; import org.etsi.osl.tmf.gam673.model.GeographicAddress;
import org.etsi.osl.tmf.gam673.model.GeographicSubAddress;
import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -12,7 +13,9 @@ import org.springframework.http.HttpStatus; ...@@ -12,7 +13,9 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
...@@ -35,11 +38,71 @@ class GeographicAddressManagementControllerTest { ...@@ -35,11 +38,71 @@ class GeographicAddressManagementControllerTest {
MockitoAnnotations.openMocks(this); MockitoAnnotations.openMocks(this);
} }
@Test
void testRetrieveGeographicAddressByUUID() {
GeographicAddress address = new GeographicAddress();
// Add test data to address list
when(service.findGeographicAddressByUUID("test")).thenReturn(address);
ResponseEntity<GeographicAddress> response = controller.retrieveGeographicAddress("test");
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(address, response.getBody());
}
@Test
void throwExceptionTestWhenRetrieveGeographicAddressByUUID(){
when(service.findGeographicAddressByUUID("test")).thenThrow(RuntimeException.class);
ResponseEntity<GeographicAddress> response = controller.retrieveGeographicAddress("test");
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
@Test
void testRetrieveGeographicSubAddressByUUID() {
GeographicSubAddress address = new GeographicSubAddress();
// Add test data to address list
when(service.findGeographicSubAddressByUUID("test","test")).thenReturn(address);
ResponseEntity<GeographicSubAddress> response = controller.retrieveGeographicSubAddress("test","test");
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(address, response.getBody());
}
@Test
void throwExceptionTestWhenRetrieveGeographicSubAddressByUUID(){
when(service.findGeographicSubAddressByUUID("test","test")).thenThrow(RuntimeException.class);
ResponseEntity<GeographicSubAddress> response = controller.retrieveGeographicSubAddress("test","test");
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
@Test
void testRetrieveGeographicSubAddresses() {
Set<GeographicSubAddress> subAddress = new HashSet<>();
// Add test data to address list
when(service.findAllGeographicSubAddresses("test")).thenReturn(subAddress);
ResponseEntity<Set<GeographicSubAddress>> response = controller.retrieveGeographicSubAddresses("test");
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(subAddress, response.getBody());
}
@Test
void throwExceptionTestWhenRetrieveGeographicSubAddresses(){
when(service.findAllGeographicSubAddresses("test")).thenThrow(RuntimeException.class);
ResponseEntity<Set<GeographicSubAddress>> response = controller.retrieveGeographicSubAddresses("test");
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
@Test @Test
void testRetrieveGeographicAddresses() { void testRetrieveGeographicAddresses() {
List<GeographicAddress> addresses = new ArrayList<>(); List<GeographicAddress> addresses = new ArrayList<>();
// Add test data to address list // Add test data to address list
when(service.findAllGeographicAddresss()).thenReturn(addresses); when(service.findAllGeographicAddress()).thenReturn(addresses);
ResponseEntity<List<GeographicAddress>> response = controller.listGeographicAddress(); ResponseEntity<List<GeographicAddress>> response = controller.listGeographicAddress();
...@@ -49,7 +112,7 @@ class GeographicAddressManagementControllerTest { ...@@ -49,7 +112,7 @@ class GeographicAddressManagementControllerTest {
@Test @Test
void throwExceptionTestWhenRetrieveGeographicAddresses(){ void throwExceptionTestWhenRetrieveGeographicAddresses(){
when(service.findAllGeographicAddresss()).thenThrow(RuntimeException.class); when(service.findAllGeographicAddress()).thenThrow(RuntimeException.class);
ResponseEntity<List<GeographicAddress>> response = controller.listGeographicAddress(); ResponseEntity<List<GeographicAddress>> response = controller.listGeographicAddress();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
......
package org.etsi.osl.services.api.gam673; package org.etsi.osl.services.api.gam673;
import org.etsi.osl.tmf.gam673.model.GeographicAddress; import org.etsi.osl.tmf.gam673.model.GeographicAddress;
import org.etsi.osl.tmf.gam673.model.GeographicSubAddress;
import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository; import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository;
import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService; import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -13,6 +14,7 @@ import org.springframework.test.context.ActiveProfiles; ...@@ -13,6 +14,7 @@ import org.springframework.test.context.ActiveProfiles;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
...@@ -44,7 +46,7 @@ class GeographicAddressManagementServiceTest { ...@@ -44,7 +46,7 @@ class GeographicAddressManagementServiceTest {
List<GeographicAddress> addresses = List.of(new GeographicAddress(), new GeographicAddress()); List<GeographicAddress> addresses = List.of(new GeographicAddress(), new GeographicAddress());
when(repository.findAll()).thenReturn(addresses); when(repository.findAll()).thenReturn(addresses);
List<GeographicAddress> result = service.findAllGeographicAddresss(); List<GeographicAddress> result = service.findAllGeographicAddress();
assertEquals(addresses, result); assertEquals(addresses, result);
} }
...@@ -63,6 +65,50 @@ class GeographicAddressManagementServiceTest { ...@@ -63,6 +65,50 @@ class GeographicAddressManagementServiceTest {
assertEquals(address, result); assertEquals(address, result);
} }
@Test
void testFindAllGeographicSubAddress() {
Optional<GeographicAddress> address = Optional.of(new GeographicAddress());
GeographicSubAddress subAddress = new GeographicSubAddress();
subAddress.setSubAddressType("test");
subAddress.setBuildingName("test");
subAddress.setSubUnitType("test");
address.get().setGeographicSubAddresses(Set.of(subAddress));
// Mock data
when(repository.findByUuid("test")).thenReturn(address);
Set<GeographicSubAddress> result = service.findAllGeographicSubAddresses("test");
assertEquals(address.get().getGeographicSubAddresses(), result);
}
@Test
void testFindGeographicSubAddressByUUID() {
// Mock data
String addressId = "123";
String subAddressId = "321";
GeographicSubAddress subAddress = new GeographicSubAddress();
subAddress.setSubAddressType("test");
subAddress.setBuildingName("test");
subAddress.setSubUnitType("test");
subAddress.setUuid(subAddressId);
GeographicAddress address = new GeographicAddress();
address.setUuid(addressId);
address.setGeographicSubAddresses(Set.of(subAddress));
when(repository.findByUuid(addressId)).thenReturn(Optional.of(address));
GeographicSubAddress result = service.findGeographicSubAddressByUUID(addressId, subAddressId);
assertNotNull(result);
assertEquals(subAddress, result);
}
@Test @Test
void testCreateGeographicAddress() { void testCreateGeographicAddress() {
// Mock data // Mock data
......
package org.etsi.osl.services.api.gam673;
import org.etsi.osl.tmf.gam673.api.GeographicAddressValidationManagementApiController;
import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation;
import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressValidationManagementService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
class GeographicAddressValidationManagementControllerTest {
@InjectMocks
private GeographicAddressValidationManagementApiController controller;
@Mock
private GeographicAddressValidationManagementService service;
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}
@Test
void testRetrieveGeographicAddressValidation() {
List<GeographicAddressValidation> addresses = new ArrayList<>();
// Add test data to address list
when(service.findAllGeographicAddressValidations()).thenReturn(addresses);
ResponseEntity<List<GeographicAddressValidation>> response = controller.listGeographicAddressValidation();
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(addresses, response.getBody());
}
@Test
void throwExceptionTestWhenRetrieveGeographicAddressValidation(){
when(service.findAllGeographicAddressValidations()).thenThrow(RuntimeException.class);
ResponseEntity<List<GeographicAddressValidation>> response = controller.listGeographicAddressValidation();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
@Test
void testRetrieveGeographicAddressValidationByUUID() {
GeographicAddressValidation addressValidation = new GeographicAddressValidation();
// Add test data to address list
when(service.findGeographicAddressValidationByUUID("Test")).thenReturn(addressValidation);
ResponseEntity<GeographicAddressValidation> response = controller.retrieveGeographicAddressValidation("Test");
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(addressValidation, response.getBody());
}
@Test
void throwExceptionTestWhenRetrieveGeographicAddressValidationByUUID(){
when(service.findGeographicAddressValidationByUUID("test")).thenThrow(RuntimeException.class);
ResponseEntity<GeographicAddressValidation> response = controller.retrieveGeographicAddressValidation("test");
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
@Test
void testCreateGeographicAddressValidation() {
GeographicAddressValidation address = new GeographicAddressValidation();
when(service.createGeographicAddressValidation(any())).thenReturn(address);
ResponseEntity<GeographicAddressValidation> response = controller.createGeographicAddressValidation(address);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(address, response.getBody());
}
@Test
void testExceptionWhenCreateGeographicAddressValidation(){
GeographicAddressValidation address = new GeographicAddressValidation();
when(service.createGeographicAddressValidation(any())).thenThrow(RuntimeException.class);
ResponseEntity<GeographicAddressValidation> response = controller.createGeographicAddressValidation(address);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
@Test
void testDeleteGeographicAddressValidation() {
doNothing().when(service).deleteGeographicAddressValidationById(anyString());
ResponseEntity<Void> response = controller.deleteGeographicAddressValidation("addressId");
assertEquals(HttpStatus.OK, response.getStatusCode());
}
@Test
void testDeleteGeographicAddressValidationException() {
doThrow(RuntimeException.class).when(service).deleteGeographicAddressValidationById(anyString());
ResponseEntity<Void> response = controller.deleteGeographicAddressValidation("addressId");
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
@Test
void testPatchGeographicAddressValidation() {
String addressId = "addressId";
GeographicAddressValidation updatedAddress = new GeographicAddressValidation();
// Set up mock service behavior
when(service.updateGeographicAddressValidation(anyString(), any())).thenReturn(updatedAddress);
ResponseEntity<GeographicAddressValidation> response = controller.patchGeographicAddressValidation(addressId, updatedAddress);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(updatedAddress, response.getBody());
}
@Test
void testPatchGeographicAddressValidationException() {
String addressId = "addressId";
GeographicAddressValidation updatedAddress = new GeographicAddressValidation();
// Set up mock service behavior
when(service.updateGeographicAddressValidation(anyString(), any())).thenThrow(RuntimeException.class);
ResponseEntity<GeographicAddressValidation> response = controller.patchGeographicAddressValidation(addressId, updatedAddress);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
}
package org.etsi.osl.services.api.gam673;
import org.etsi.osl.tmf.gam673.model.GeographicAddress;
import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation;
import org.etsi.osl.tmf.gam673.repo.GeographicAddressValidationManagementRepository;
import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressValidationManagementService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.test.context.ActiveProfiles;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@AutoConfigureMockMvc
@ActiveProfiles("testing")
class GeographicAddressValidationManagementServiceTest {
@InjectMocks
private GeographicAddressValidationManagementService service;
@Mock
private GeographicAddressValidationManagementRepository repository;
@BeforeEach
void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
void testFindAllGeographicAddressValidation() {
// Mock data
List<GeographicAddressValidation> addresses = List.of(new GeographicAddressValidation(), new GeographicAddressValidation());
when(repository.findAll()).thenReturn(addresses);
List<GeographicAddressValidation> result = service.findAllGeographicAddressValidations();
assertEquals(addresses, result);
}
@Test
void testFindGeographicAddressValidationByUUID() {
// Mock data
String uuid = "123";
GeographicAddressValidation address = new GeographicAddressValidation();
address.setUuid(uuid);
when(repository.findByUuid(uuid)).thenReturn(Optional.of(address));
GeographicAddressValidation result = service.findGeographicAddressValidationByUUID(uuid);
assertNotNull(result);
assertEquals(address, result);
}
@Test
void testCreateGeographicAddressValidation() {
// Mock data
GeographicAddressValidation address = new GeographicAddressValidation();
when(repository.save(any())).thenReturn(address);
GeographicAddressValidation result = service.createGeographicAddressValidation(address);
assertEquals(address, result);
}
@Test
void testUpdateGeographicAddressValidation() {
// Mock data
String id = "123";
GeographicAddress newAlternativeAddress= new GeographicAddress();
newAlternativeAddress.setUuid("1234");
newAlternativeAddress.setLocality("localityNew");
GeographicAddress oldAlternativeAddress= new GeographicAddress();
oldAlternativeAddress.setUuid("1234");
oldAlternativeAddress.setLocality("localityOld");
GeographicAddressValidation existingAddress = new GeographicAddressValidation();
existingAddress.setAlternateGeographicAddresses(Set.of(oldAlternativeAddress));
GeographicAddressValidation newAddress = new GeographicAddressValidation();
newAddress.setAlternateGeographicAddresses(Set.of(newAlternativeAddress));
when(repository.findByUuid(id)).thenReturn(Optional.of(existingAddress));
when(repository.save(any())).thenReturn(existingAddress);
GeographicAddressValidation result = service.updateGeographicAddressValidation(id, newAddress);
assertNotNull(result);
assertEquals(existingAddress, result);
// Add additional assertions for updated fields if needed
}
@Test
void testDeleteGeographicAddressValidationById() {
// Mock data
String id = "123";
GeographicAddressValidation existingAddress = new GeographicAddressValidation();
when(repository.findByUuid(id)).thenReturn(Optional.of(existingAddress));
Void result = service.deleteGeographicAddressValidationById(id);
assertNull(result);
verify(repository, times(1)).delete(existingAddress);
}
}