From 8ceecac2fa0c07609b262e0ea3b3c6f9c0247b5b Mon Sep 17 00:00:00 2001 From: Oleksandr Vidinieiev Date: Thu, 25 Jan 2024 16:16:31 +0200 Subject: [PATCH] MODTLR-10 Fix code smells --- .../exception/TenantScopedExecutionException.java | 10 ++++++++++ .../service/impl/TenantScopedExecutionServiceImpl.java | 3 ++- src/test/java/org/folio/api/EcsTlrApiTest.java | 6 +++--- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/folio/exception/TenantScopedExecutionException.java diff --git a/src/main/java/org/folio/exception/TenantScopedExecutionException.java b/src/main/java/org/folio/exception/TenantScopedExecutionException.java new file mode 100644 index 00000000..14a3f431 --- /dev/null +++ b/src/main/java/org/folio/exception/TenantScopedExecutionException.java @@ -0,0 +1,10 @@ +package org.folio.exception; + +public class TenantScopedExecutionException extends RuntimeException { + private final String tenantId; + + public TenantScopedExecutionException(Exception cause, String tenantId) { + super(cause); + this.tenantId = tenantId; + } +} diff --git a/src/main/java/org/folio/service/impl/TenantScopedExecutionServiceImpl.java b/src/main/java/org/folio/service/impl/TenantScopedExecutionServiceImpl.java index 4248458b..7742b4d0 100644 --- a/src/main/java/org/folio/service/impl/TenantScopedExecutionServiceImpl.java +++ b/src/main/java/org/folio/service/impl/TenantScopedExecutionServiceImpl.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.concurrent.Callable; +import org.folio.exception.TenantScopedExecutionException; import org.folio.service.TenantScopedExecutionService; import org.folio.spring.FolioExecutionContext; import org.folio.spring.FolioModuleMetadata; @@ -33,7 +34,7 @@ public T execute(String tenantId, Callable action) { return action.call(); } catch (Exception e) { log.error("execute:: tenantId={}", tenantId, e); - throw new RuntimeException(e); + throw new TenantScopedExecutionException(e, tenantId); } } } diff --git a/src/test/java/org/folio/api/EcsTlrApiTest.java b/src/test/java/org/folio/api/EcsTlrApiTest.java index ca11c335..094744e7 100644 --- a/src/test/java/org/folio/api/EcsTlrApiTest.java +++ b/src/test/java/org/folio/api/EcsTlrApiTest.java @@ -62,18 +62,18 @@ void getByIdNotFound() throws Exception { } @Test - public void titleLevelRequestIsCreatedForDifferentTenant() { + void titleLevelRequestIsCreatedForDifferentTenant() { EcsTlr ecsTlr = buildEcsTlr(); wireMockServer.stubFor(WireMock.post(urlMatching(".*/circulation/requests")) .withHeader(TENANT_HEADER, equalTo(ANOTHER_TENANT)) .willReturn(jsonResponse(asJsonString(ecsTlr), HttpStatus.SC_CREATED))); - assertEquals(getCurrentTenantId(), TENANT); + assertEquals(TENANT, getCurrentTenantId()); doPost(TLR_URL, ecsTlr) .expectStatus().isCreated() .expectBody().json(asJsonString(ecsTlr)); - assertEquals(getCurrentTenantId(), TENANT); + assertEquals(TENANT, getCurrentTenantId()); wireMockServer.verify(postRequestedFor(urlMatching(".*/circulation/requests")) .withHeader(TENANT_HEADER, equalTo(ANOTHER_TENANT))); }