Commit 3b750270 authored by Labros Papadopoulos's avatar Labros Papadopoulos
Browse files

tmf 674 api enhancements + new test

parent 9cc88ab1
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ public interface GeographicSiteManagementApi {
            produces = { "application/json" },
            consumes = { "application/json" },
            method = RequestMethod.GET)
    default ResponseEntity<GeographicSite> retrieveGeographicSite() {
    default ResponseEntity<GeographicSite> retrieveGeographicSite(@Parameter(description = "Identifier of the Geographic site",required=true) @PathVariable("id") String id) {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("application/json")) {
                try {
+15 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ public class GeographicSiteManagementApiController implements GeographicSiteMana
        this.geographicSiteManagementService = geographicSiteManagementService;
    }

//    @PreAuthorize("hasAnyAuthority('ROLE_USER')" )
    @PreAuthorize("hasAnyAuthority('ROLE_USER')" )
    @Override
    public ResponseEntity<List<GeographicSite>> listGeographicSite() {

@@ -41,6 +41,20 @@ public class GeographicSiteManagementApiController implements GeographicSiteMana
        }
    }

    @PreAuthorize("hasAnyAuthority('ROLE_USER')" )
    @Override
    public ResponseEntity<GeographicSite> retrieveGeographicSite(@PathVariable("id") String id) {


        try {
            return new ResponseEntity<>(geographicSiteManagementService.findGeographicSiteByUUID(id), HttpStatus.OK);

        } catch (Exception e) {
            log.error(COULD_NOT_SERIALIZE, e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @PreAuthorize("hasAnyAuthority('ROLE_USER')" )
    @Override
    public ResponseEntity<GeographicSite> createGeographicSite(
+4 −2
Original line number Diff line number Diff line
@@ -31,8 +31,10 @@ public class GeographicSiteManagementService {
        return (List<GeographicSite>) geographicSiteManagementRepository.findAll();
    }

    public Optional<GeographicSite> findGeographicSiteByUUID(String uuid){
        return geographicSiteManagementRepository.findByUuid(uuid);
    public GeographicSite findGeographicSiteByUUID(String uuid){
        Optional<GeographicSite> gs=geographicSiteManagementRepository.findByUuid(uuid);
        return gs.orElse(null);

    }

   public GeographicSite createGeographicSite(GeographicSite geographicSite){
+11 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ import org.springframework.http.ResponseEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
@@ -52,12 +54,17 @@ class GeographicSiteManagementApiControllerTest {
    }

    @Test
    void throwExceptionTestWhenRetrieveGeographicSites(){
        when(service.findAllGeographicSites()).thenThrow(RuntimeException.class);
        ResponseEntity<GeographicSite> response = controller.retrieveGeographicSite();
        assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
    void testFetchGeographicSite() {
        GeographicSite site = new GeographicSite();
        // Add test data to sites list
        when(service.findGeographicSiteByUUID("123")).thenReturn(site);

        ResponseEntity<GeographicSite> response = controller.retrieveGeographicSite("123");

        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(site, response.getBody());
    }

    @Test
    void testCreateGeographicSite() {
        GeographicSite site = new GeographicSite();
+2 −3
Original line number Diff line number Diff line
@@ -49,10 +49,9 @@ class GeographicSiteManagementServiceTest {
        GeographicSite site = new GeographicSite();
        when(repository.findByUuid(uuid)).thenReturn(Optional.of(site));

        Optional<GeographicSite> result = service.findGeographicSiteByUUID(uuid);
        GeographicSite result = service.findGeographicSiteByUUID(uuid);

        assertTrue(result.isPresent());
        assertEquals(site, result.get());
        assertEquals(site, result);
    }

    @Test