Skip to content

Commit

Permalink
Merge pull request #1422 from folio-org/tmprelease-24.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Vignesh-kalyanasundaram authored Feb 5, 2024
2 parents 2abd284 + d136960 commit 71917b5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>mod-circulation</artifactId>
<groupId>org.folio</groupId>
<version>24.0.12-SNAPSHOT</version>
<version>24.0.13-SNAPSHOT</version>
<licenses>
<license>
<name>Apache License 2.0</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -38,10 +39,14 @@ public CompletableFuture<Result<CheckoutLockConfiguration>> 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())));
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 71917b5

Please sign in to comment.