From 9f13436feb1d1a82b8c6b28739db11be4219b03b Mon Sep 17 00:00:00 2001 From: Vignesh-Kalyanasundaram Date: Fri, 9 Feb 2024 17:24:45 +0530 Subject: [PATCH] Revert "CIRC-2023 Handle exception while calling mod-settings (#1421)" This reverts commit 83e92b089855bd8d5bf730f1f6d5650339ef3fee. --- .../storage/SettingsRepository.java | 9 +-- .../storage/SettingsRepositoryTest.java | 77 ------------------- 2 files changed, 2 insertions(+), 84 deletions(-) delete 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 89f2e845ba..0a983cb602 100644 --- a/src/main/java/org/folio/circulation/infrastructure/storage/SettingsRepository.java +++ b/src/main/java/org/folio/circulation/infrastructure/storage/SettingsRepository.java @@ -16,7 +16,6 @@ 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()); @@ -39,14 +38,10 @@ public CompletableFuture> lookUpCheckOutLockSe .map(Configuration::getValue) .map(JsonObject::new) .orElse(new JsonObject()))) - .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())); - })); + .thenApply(r -> r.map(CheckoutLockConfiguration::from)); } catch (Exception ex) { log.warn("lookUpCheckOutLockSettings:: Unable to retrieve checkoutLockFeature settings ", ex); - return CompletableFuture.completedFuture(succeeded(CheckoutLockConfiguration.from(new JsonObject()))); + return CompletableFuture.completedFuture(Result.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 deleted file mode 100644 index f3c7c60c92..0000000000 --- a/src/test/java/org/folio/circulation/infrastructure/storage/SettingsRepositoryTest.java +++ /dev/null @@ -1,77 +0,0 @@ -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; - } -}