Skip to content

Commit

Permalink
MODINV-943 Fix Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrokrutii committed May 30, 2024
1 parent 3a312a9 commit 74f7183
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/test/java/support/fakes/FakeStorageModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void register(Router router) {
router.route(pathTree).handler(this::emulateFailureIfNeeded);
router.route(pathTree).handler(this::checkTokenHeader);

router.post(rootPath + "/retrieve").handler(this::retrieveMany);
router.post(rootPath).handler(this::checkRequiredProperties);
router.post(rootPath).handler(this::checkUniqueProperties);
router.post(rootPath + "/emulate-failure").handler(this::emulateFailure);
Expand Down Expand Up @@ -266,6 +267,37 @@ private void getMany(RoutingContext routingContext) {
JsonResponse.success(routingContext.response(), result);
}

private void retrieveMany(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
var requestBody = routingContext.getBodyAsJson();

var limit = requestBody.getInteger("limit");
var offset = requestBody.getInteger("offset");
var query = requestBody.getString("query");;

System.out.printf("Handling %s%n", routingContext.request().uri());

Map<String, JsonObject> resourcesForTenant = getResourcesForTenant(context);

List<JsonObject> filteredItems = new FakeCQLToJSONInterpreter(false)
.execute(resourcesForTenant.values(), query);

List<JsonObject> pagedItems = filteredItems.stream()
.skip(offset)
.limit(limit)
.collect(Collectors.toList());

JsonObject result = new JsonObject();

result.put(collectionPropertyName, new JsonArray(pagedItems));
result.put("totalRecords", filteredItems.size());

System.out.printf("Found %s resources: %s%n", recordTypeName,
result.encodePrettily());

JsonResponse.success(routingContext.response(), result);
}

private void empty(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);

Expand Down

0 comments on commit 74f7183

Please sign in to comment.