From 74f7183165569e0221134a031a4ee01d2359a5ca Mon Sep 17 00:00:00 2001 From: Dmytro Krutii Date: Thu, 30 May 2024 15:04:03 +0300 Subject: [PATCH] MODINV-943 Fix Unit tests --- .../java/support/fakes/FakeStorageModule.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/test/java/support/fakes/FakeStorageModule.java b/src/test/java/support/fakes/FakeStorageModule.java index 33d543037..802c7ffcd 100644 --- a/src/test/java/support/fakes/FakeStorageModule.java +++ b/src/test/java/support/fakes/FakeStorageModule.java @@ -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); @@ -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 resourcesForTenant = getResourcesForTenant(context); + + List filteredItems = new FakeCQLToJSONInterpreter(false) + .execute(resourcesForTenant.values(), query); + + List 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);