diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java index 95be7548..d9a73921 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java @@ -39,7 +39,8 @@ public ResponseEntity getCollection(String id, String sortBy) throws return ResponseEntity.ok() .body(StacToCollection.convert(model.getCollections().get(0))); } else { - throw new NoSuchElementException(String.format("uuid %s not found!", id)); + log.error("UUID {} not found", id); + return ResponseEntity.notFound().build(); } } } diff --git a/server/src/test/java/au/org/aodn/ogcapi/server/common/RestApiTest.java b/server/src/test/java/au/org/aodn/ogcapi/server/common/RestApiTest.java index 37394423..3396a2d8 100644 --- a/server/src/test/java/au/org/aodn/ogcapi/server/common/RestApiTest.java +++ b/server/src/test/java/au/org/aodn/ogcapi/server/common/RestApiTest.java @@ -2,14 +2,10 @@ import au.org.aodn.ogcapi.features.model.Collections; import au.org.aodn.ogcapi.server.BaseTestClass; - import au.org.aodn.ogcapi.server.core.model.ErrorResponse; import au.org.aodn.ogcapi.server.core.model.ExtendedCollections; import au.org.aodn.ogcapi.server.core.model.enumeration.OGCMediaTypeMapper; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.*; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; @@ -28,9 +24,6 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) // We need to use @BeforeAll @AfterAll with not static method public class RestApiTest extends BaseTestClass { - @Autowired - protected ObjectMapper objectMapper; - @BeforeAll public void beforeClass() { super.createElasticIndex(); @@ -514,14 +507,10 @@ public void verifyCQLFuzzyKey() throws IOException { * on any error */ @Test - public void verifyErrorMessageCreated() throws JsonProcessingException { + public void verifyErrorMessageCreated() { ResponseEntity collection = testRestTemplate.getForEntity(getBasePath() + "/collections/12324", String.class); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, collection.getStatusCode(), "Request Status match"); - - ErrorResponse response = objectMapper.readValue(Objects.requireNonNull(collection.getBody()), ErrorResponse.class); - assertEquals("uuid 12324 not found!", response.getMessage(), "message match"); - assertEquals("uri=/api/v1/ogc/collections/12324", response.getDetails(), "message url"); + assertEquals(HttpStatus.NOT_FOUND, collection.getStatusCode(), "Request Status match"); } /** * Test sort by, you can use this as an example for how ot use sortBy