Commit 177291ee authored by Konstantinos Poulakakis's avatar Konstantinos Poulakakis
Browse files

Add TMF 673 additional tests. Change the updateFields method.

parent 60664f0c
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ public interface GeographicAddressManagementApi {
            @ApiResponse(responseCode = "500", description = "Internal Server Error" ) })
    @GetMapping(value = "/geographicAddress/{id}/geographicSubAddress",
            produces = { "application/json" })
    ResponseEntity<Set<GeographicSubAddress>> retrieveGeographicSubAddress(
    ResponseEntity<Set<GeographicSubAddress>> retrieveGeographicSubAddresses(
            @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", })
+2 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ public class GeographicAddressManagementApiController implements GeographicAddre
    @Override
    public ResponseEntity<List<GeographicAddress>> listGeographicAddress() {
        try {
            return new ResponseEntity<>(geographicAddressManagementService.findAllGeographicAddresss(), HttpStatus.OK);
            return new ResponseEntity<>(geographicAddressManagementService.findAllGeographicAddress(), HttpStatus.OK);

        } catch (Exception e) {
            log.error(COULD_NOT_SERIALIZE, e);
@@ -89,7 +89,7 @@ public class GeographicAddressManagementApiController implements GeographicAddre

    @PreAuthorize("hasAnyAuthority('ROLE_USER')" )
    @Override
    public ResponseEntity<Set<GeographicSubAddress>> retrieveGeographicSubAddress(
    public ResponseEntity<Set<GeographicSubAddress>> retrieveGeographicSubAddresses(
            @Parameter(description = "Identifier of the geographic address", required = true) @PathVariable("id") String id) {
        try{
            Set<GeographicSubAddress> c = geographicAddressManagementService.findAllGeographicSubAddresses(id);
+1 −2
Original line number Diff line number Diff line
@@ -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.GeographicSubAddress;
import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository;
import org.etsi.osl.tmf.prm669.model.RelatedParty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,7 +29,7 @@ public class GeographicAddressManagementService {
        this.geographicAddressManagementRepository = geographicAddressManagementRepository;
    }

    public List<GeographicAddress> findAllGeographicAddresss(){
    public List<GeographicAddress> findAllGeographicAddress(){
        return (List<GeographicAddress>) geographicAddressManagementRepository.findAll();
    }

+6 −0
Original line number Diff line number Diff line
@@ -66,6 +66,12 @@ public class GeographicAddressValidationManagementService {
            for(GeographicAddress n : newGeographicAddressValidation.getAlternateGeographicAddresses()){
                if(n.getUuid()==null){
                    existingGeographicAddressValidation.addGeographicAddress(n);
                }else {
                    for (GeographicAddress oldGeographicAddress : existingGeographicAddressValidation.getAlternateGeographicAddresses()){
                        if (n.getUuid().equals(oldGeographicAddress.getUuid())){
                            GeographicAddress geographicAddress = mapperUtils.geographicAddressMap(n, oldGeographicAddress);
                        }
                    }
                }
            }
        }
+65 −2
Original line number Diff line number Diff line
@@ -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.model.GeographicAddress;
import org.etsi.osl.tmf.gam673.model.GeographicSubAddress;
import org.etsi.osl.tmf.gam673.reposervices.GeographicAddressManagementService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -12,7 +13,9 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
@@ -35,11 +38,71 @@ class GeographicAddressManagementControllerTest {
        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
    void testRetrieveGeographicAddresses() {
        List<GeographicAddress> addresses = new ArrayList<>();
        // Add test data to address list
        when(service.findAllGeographicAddresss()).thenReturn(addresses);
        when(service.findAllGeographicAddress()).thenReturn(addresses);

        ResponseEntity<List<GeographicAddress>> response = controller.listGeographicAddress();

@@ -49,7 +112,7 @@ class GeographicAddressManagementControllerTest {

    @Test
    void throwExceptionTestWhenRetrieveGeographicAddresses(){
        when(service.findAllGeographicAddresss()).thenThrow(RuntimeException.class);
        when(service.findAllGeographicAddress()).thenThrow(RuntimeException.class);
        ResponseEntity<List<GeographicAddress>> response = controller.listGeographicAddress();
        assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());

Loading