Skip to content

Commit

Permalink
complete TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
gunplar committed Nov 15, 2023
1 parent e3a09ce commit fd6b34f
Showing 1 changed file with 24 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@

import static com.here.naksha.app.common.TestUtil.*;
import static com.here.naksha.app.common.TestUtil.loadFileOrFail;
import static com.here.naksha.lib.core.util.storage.RequestHelper.createFeatureRequest;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.*;

import com.here.naksha.app.service.models.FeatureCollectionRequest;
import com.here.naksha.lib.core.NakshaAdminCollection;
import com.here.naksha.lib.core.models.geojson.implementation.XyzFeature;
import com.here.naksha.lib.core.models.geojson.implementation.XyzFeatureCollection;
import com.here.naksha.lib.core.models.naksha.EventHandler;
import com.here.naksha.lib.core.models.naksha.Space;
import com.here.naksha.lib.core.models.storage.*;
import com.here.naksha.lib.core.storage.IWriteSession;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
Expand Down Expand Up @@ -117,7 +113,6 @@ public void tc0300_testCreateFeaturesWithNewIds() throws Exception {
HttpRequest request;
HttpResponse<String> response;

// TODO : Need to replace setup steps when EventHandler and Space REST API tests are available
// Given: Storage (mock implementation) configured in Admin storage
final String storageJson = loadFileOrFail("TC0300_createFeaturesWithNewIds/create_storage.json");
streamId = UUID.randomUUID().toString();
Expand All @@ -130,27 +125,24 @@ public void tc0300_testCreateFeaturesWithNewIds() throws Exception {
assertEquals(200, response.statusCode(), "ResCode mismatch. Failed creating Storage");

// Given: EventHandler (uses above Storage) configured in Admin storage
final EventHandler eventHandler =
parseJsonFileOrFail("TC0300_createFeaturesWithNewIds/create_event_handler.json", EventHandler.class);
final WriteFeatures<?> ehRequest = createFeatureRequest(
NakshaAdminCollection.EVENT_HANDLERS, eventHandler, IfExists.REPLACE, IfConflict.REPLACE);
try (final IWriteSession writer =
app.getHub().getSpaceStorage().newWriteSession(newTestNakshaContext(), true)) {
final Result result = writer.execute(ehRequest);
assertTrue(result instanceof SuccessResult, "Failed creating EventHandler");
writer.commit();
}
final String eventHandlerJson = loadFileOrFail("TC0300_createFeaturesWithNewIds/create_event_handler.json");
request = HttpRequest.newBuilder(stdHttpRequest, (k, v) -> true)
.uri(new URI(nakshaHttpUri + "hub/handlers"))
.POST(HttpRequest.BodyPublishers.ofString(eventHandlerJson))
.header(HDR_STREAM_ID, streamId)
.build();
response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, response.statusCode(), "ResCode mismatch. Failed creating Event Handler");

// Given: Space (uses above EventHandler) configured in Admin storage
final Space space = parseJsonFileOrFail("TC0300_createFeaturesWithNewIds/create_space.json", Space.class);
final WriteFeatures<?> spRequest =
createFeatureRequest(NakshaAdminCollection.SPACES, space, IfExists.REPLACE, IfConflict.REPLACE);
try (final IWriteSession writer =
app.getHub().getSpaceStorage().newWriteSession(newTestNakshaContext(), true)) {
final Result result = writer.execute(spRequest);
assertTrue(result instanceof SuccessResult, "Failed creating Space");
writer.commit();
}
request = HttpRequest.newBuilder(stdHttpRequest, (k, v) -> true)
.uri(new URI(nakshaHttpUri + "hub/spaces"))
.POST(HttpRequest.BodyPublishers.ofString(space.toString()))
.header(HDR_STREAM_ID, streamId)
.build();
response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, response.statusCode(), "ResCode mismatch. Failed creating Event Handler");

// Given: Create Features request (against above Space)
final String bodyJson = loadFileOrFail("TC0300_createFeaturesWithNewIds/create_features.json");
Expand Down Expand Up @@ -344,26 +336,24 @@ public void tc0307_testCreateFeaturesWithNoHandler() throws Exception {

// Test API : POST /hub/spaces/{spaceId}/features
// Validate request gets failed if we attempt creating features with no associated Event Handler
String streamId;
String streamId = UUID.randomUUID().toString();
;
HttpRequest request;
HttpResponse<String> response;

// TODO : Need to replace setup steps when Space REST API tests are available
// Given: Space (without EventHandler) configured in Admin storage
final Space space = parseJsonFileOrFail("TC0307_createFeaturesWithNoHandler/create_space.json", Space.class);
final WriteFeatures<?> spRequest =
createFeatureRequest(NakshaAdminCollection.SPACES, space, IfExists.REPLACE, IfConflict.REPLACE);
try (final IWriteSession writer =
app.getHub().getSpaceStorage().newWriteSession(newTestNakshaContext(), true)) {
final Result result = writer.execute(spRequest);
assertTrue(result instanceof SuccessResult, "Failed creating Space");
writer.commit();
}
request = HttpRequest.newBuilder(stdHttpRequest, (k, v) -> true)
.uri(new URI(nakshaHttpUri + "hub/spaces"))
.POST(HttpRequest.BodyPublishers.ofString(space.toString()))
.header(HDR_STREAM_ID, streamId)
.build();
response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, response.statusCode(), "ResCode mismatch. Failed creating Event Handler");

// Given: Create Features request (against above Space)
final String bodyJson = loadFileOrFail("TC0307_createFeaturesWithNoHandler/create_features.json");
final String expectedBodyPart = loadFileOrFail("TC0307_createFeaturesWithNoHandler/feature_response_part.json");
streamId = UUID.randomUUID().toString();

// When: Create Features request is submitted to NakshaHub Space Storage instance
request = HttpRequest.newBuilder(stdHttpRequest, (k, v) -> true)
Expand Down

0 comments on commit fd6b34f

Please sign in to comment.