Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
gunplar committed Nov 21, 2023
1 parent b352f80 commit 5435e53
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,10 @@ void tc0501_testUpdateFeatureById() throws Exception {
HttpResponse<String> response;

// Read request body
final String bodyJson = loadFileOrFail("TC0501_updateOneFeatureById/update_request.json");
final String bodyJson = loadFileOrFail("TC0501_updateOneFeatureById/update_request_and_response.json");
// TODO: include geometry after Cursor-related changes ->
final Space space = parseJsonFileOrFail("TC0300_createFeaturesWithNewIds/create_space.json", Space.class);
final String expectedBodyPart = loadFileOrFail("TC0501_updateOneFeatureById/response.json");
final String expectedBodyPart = bodyJson;
streamId = UUID.randomUUID().toString();

// When: Create Features request is submitted to NakshaHub Space Storage instance
Expand All @@ -873,6 +873,39 @@ void tc0501_testUpdateFeatureById() throws Exception {
assertEquals(streamId, getHeader(response, HDR_STREAM_ID), "StreamId mismatch");
}

@Test
@Order(11)
void tc0502_testUpdateFeatureByWrongUriId() throws Exception {
// Test API : PUT /hub/spaces/{spaceId}/features/{featureId}
String streamId;
HttpRequest request;
HttpResponse<String> response;

// Read request body
final String bodyJson = loadFileOrFail("TC0502_updateFeatureWithWrongUriId/request.json");
// TODO: include geometry after Cursor-related changes ->
final Space space = parseJsonFileOrFail("TC0300_createFeaturesWithNewIds/create_space.json", Space.class);
final String expectedBodyPart = loadFileOrFail("TC0502_updateFeatureWithWrongUriId/response.json");
streamId = UUID.randomUUID().toString();

// When: Create Features request is submitted to NakshaHub Space Storage instance
request = HttpRequest.newBuilder(stdHttpRequest, (k, v) -> true)
.uri(new URI(NAKSHA_HTTP_URI + "hub/spaces/" + space.getId() + "/features/wrong-id"))
.PUT(HttpRequest.BodyPublishers.ofString(bodyJson))
.header(HDR_STREAM_ID, streamId)
.build();
response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

// Then: Perform assertions
assertEquals(409, response.statusCode(), "ResCode mismatch");
JSONAssert.assertEquals(
"Update Feature error response doesn't match",
expectedBodyPart,
response.body(),
JSONCompareMode.LENIENT);
assertEquals(streamId, getHeader(response, HDR_STREAM_ID), "StreamId mismatch");
}

@AfterAll
static void close() throws InterruptedException {
if (app != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "my-custom-id-301-1",
"id": "wrong-id",
"type": "Feature",
"properties": {
"speedLimit": "30"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "ErrorResponse",
"error": "Conflict",
"errorMessage": "No feature found for id wrong-id"
}

0 comments on commit 5435e53

Please sign in to comment.