Skip to content

Commit

Permalink
Merge pull request #89 from aodn/feature/5918-return-404-for-not-foun…
Browse files Browse the repository at this point in the history
…d-uuid

return 404 if didn't find an uuid
  • Loading branch information
vietnguyengit authored Sep 25, 2024
2 parents 702e51c + 295b927 commit eee1d0c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public ResponseEntity<Collection> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -514,14 +507,10 @@ public void verifyCQLFuzzyKey() throws IOException {
* on any error
*/
@Test
public void verifyErrorMessageCreated() throws JsonProcessingException {
public void verifyErrorMessageCreated() {
ResponseEntity<String> 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
Expand Down

0 comments on commit eee1d0c

Please sign in to comment.