From 83e92b089855bd8d5bf730f1f6d5650339ef3fee Mon Sep 17 00:00:00 2001 From: Vignesh <125984866+Vignesh-kalyanasundaram@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:46:12 +0530 Subject: [PATCH 1/4] CIRC-2023 Handle exception while calling mod-settings (#1421) * Handle exception when calling mod-settings * CIRC-2023 Adding test cases * CIRC-2023 Adding logger --- .../storage/SettingsRepository.java | 9 ++- .../storage/SettingsRepositoryTest.java | 77 +++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/folio/circulation/infrastructure/storage/SettingsRepositoryTest.java diff --git a/src/main/java/org/folio/circulation/infrastructure/storage/SettingsRepository.java b/src/main/java/org/folio/circulation/infrastructure/storage/SettingsRepository.java index 0a983cb602..89f2e845ba 100644 --- a/src/main/java/org/folio/circulation/infrastructure/storage/SettingsRepository.java +++ b/src/main/java/org/folio/circulation/infrastructure/storage/SettingsRepository.java @@ -16,6 +16,7 @@ import java.util.concurrent.CompletableFuture; import static org.folio.circulation.support.http.client.CqlQuery.exactMatch; +import static org.folio.circulation.support.results.Result.succeeded; public class SettingsRepository { private static final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass()); @@ -38,10 +39,14 @@ public CompletableFuture> lookUpCheckOutLockSe .map(Configuration::getValue) .map(JsonObject::new) .orElse(new JsonObject()))) - .thenApply(r -> r.map(CheckoutLockConfiguration::from)); + .thenApply(r -> r.map(CheckoutLockConfiguration::from)) + .thenApply(r -> r.mapFailure(failure -> { + log.warn("lookUpCheckOutLockSettings:: Error while fetching checkout lock settings {}", failure); + return succeeded(CheckoutLockConfiguration.from(new JsonObject())); + })); } catch (Exception ex) { log.warn("lookUpCheckOutLockSettings:: Unable to retrieve checkoutLockFeature settings ", ex); - return CompletableFuture.completedFuture(Result.succeeded(CheckoutLockConfiguration.from(new JsonObject()))); + return CompletableFuture.completedFuture(succeeded(CheckoutLockConfiguration.from(new JsonObject()))); } } } diff --git a/src/test/java/org/folio/circulation/infrastructure/storage/SettingsRepositoryTest.java b/src/test/java/org/folio/circulation/infrastructure/storage/SettingsRepositoryTest.java new file mode 100644 index 0000000000..f3c7c60c92 --- /dev/null +++ b/src/test/java/org/folio/circulation/infrastructure/storage/SettingsRepositoryTest.java @@ -0,0 +1,77 @@ +package org.folio.circulation.infrastructure.storage; + +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import org.folio.circulation.support.Clients; +import org.folio.circulation.support.CollectionResourceClient; +import org.folio.circulation.support.ServerErrorFailure; +import org.folio.circulation.support.http.client.Response; +import org.folio.circulation.support.results.Result; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class SettingsRepositoryTest { + + @Test + void testFetchSettingsWhenFeatureEnabled() throws ExecutionException, InterruptedException { + Clients clients = mock(Clients.class); + CollectionResourceClient collectionResourceClient = mock(CollectionResourceClient.class); + when(clients.settingsStorageClient()).thenReturn(collectionResourceClient); + SettingsRepository settingsRepository = new SettingsRepository(clients); + when(collectionResourceClient.getMany(any(), any())) + .thenReturn(CompletableFuture.completedFuture(Result.succeeded(new Response(200, createCheckoutLockJsonResponse(true).toString(), "application/json")))); + var res = settingsRepository.lookUpCheckOutLockSettings().get().value(); + assertTrue(res.isCheckOutLockFeatureEnabled()); + } + + @Test + void testFetchSettingsWhenFeatureDisabled() throws ExecutionException, InterruptedException { + Clients clients = mock(Clients.class); + CollectionResourceClient collectionResourceClient = mock(CollectionResourceClient.class); + when(clients.settingsStorageClient()).thenReturn(collectionResourceClient); + SettingsRepository settingsRepository = new SettingsRepository(clients); + when(collectionResourceClient.getMany(any(), any())) + .thenReturn(CompletableFuture.completedFuture(Result.succeeded(new Response(200, createCheckoutLockJsonResponse(false).toString(), "application/json")))); + var res = settingsRepository.lookUpCheckOutLockSettings().get().value(); + assertFalse(res.isCheckOutLockFeatureEnabled()); + } + + @Test + void testFetchSettingsWhenSettingsApiThrowError() throws ExecutionException, InterruptedException { + Clients clients = mock(Clients.class); + CollectionResourceClient collectionResourceClient = mock(CollectionResourceClient.class); + when(clients.settingsStorageClient()).thenReturn(collectionResourceClient); + SettingsRepository settingsRepository = new SettingsRepository(clients); + when(collectionResourceClient.getMany(any(), any())) + .thenReturn(CompletableFuture.completedFuture(Result.failed(new ServerErrorFailure("Unable to call mod settings")))); + var res = settingsRepository.lookUpCheckOutLockSettings().get().value(); + assertFalse(res.isCheckOutLockFeatureEnabled()); + } + + private JsonObject createCheckoutLockJsonResponse(boolean checkoutFeatureFlag) { + JsonObject checkoutLockResponseJson = new JsonObject(); + checkoutLockResponseJson.put("id", UUID.randomUUID()) + .put("scope", "mod-circulation") + .put("key", "checkoutLockFeature") + .put("value", + new JsonObject().put("checkOutLockFeatureEnabled", checkoutFeatureFlag) + .put("lockTtl", 500) + .put("retryInterval", 5) + .put("noOfRetryAttempts", 10) + .encodePrettily() + ).encodePrettily(); + JsonObject result = new JsonObject(); + result.put("items", new JsonArray(List.of(checkoutLockResponseJson))); + return result; + } +} From 6ef2fc316ad66689189d3b0dd5a36da381cfc4bb Mon Sep 17 00:00:00 2001 From: Vignesh-Kalyanasundaram Date: Mon, 5 Feb 2024 17:48:35 +0530 Subject: [PATCH 2/4] Update NEWS --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 4d57cfdbd2..a77076eb1d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +## 24.0.12 2024-02-05 + +* Handle exception while calling mod-settings (CIRC-2023) + ## 24.0.11 2023-12-06 * The option to print picks slips doesn't activate (CIRC-1994) From dd2b74a3df2370bc54005e16e3f260ae77067666 Mon Sep 17 00:00:00 2001 From: Vignesh-Kalyanasundaram Date: Mon, 5 Feb 2024 18:44:48 +0530 Subject: [PATCH 3/4] [maven-release-plugin] prepare release v24.0.12 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8d16ca6386..abd38fbfcc 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 mod-circulation org.folio - 24.0.12-SNAPSHOT + 24.0.12 Apache License 2.0 @@ -295,7 +295,7 @@ https://github.com/folio-org/mod-inventory scm:git:git://github.com:folio-org/mod-inventory.git scm:git:git@github.com:folio-org/mod-inventory.git - v24.0.0 + v24.0.12 From d13696021bc9127c2be5556f3847acd57bbd59d3 Mon Sep 17 00:00:00 2001 From: Vignesh-Kalyanasundaram Date: Mon, 5 Feb 2024 18:44:50 +0530 Subject: [PATCH 4/4] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index abd38fbfcc..41f3220d08 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 mod-circulation org.folio - 24.0.12 + 24.0.13-SNAPSHOT Apache License 2.0 @@ -295,7 +295,7 @@ https://github.com/folio-org/mod-inventory scm:git:git://github.com:folio-org/mod-inventory.git scm:git:git@github.com:folio-org/mod-inventory.git - v24.0.12 + v24.0.0