From 7f3af335b5ac0bafab491844bcc7e3643f636d46 Mon Sep 17 00:00:00 2001 From: siarhei_hrabko Date: Fri, 8 Sep 2023 11:20:52 +0300 Subject: [PATCH] MODFIN-283 minor fixes --- .../java/org/folio/rest/core/RestClient.java | 1 + .../folio/services/fund/FundServiceTest.java | 80 +++++-------------- 2 files changed, 20 insertions(+), 61 deletions(-) diff --git a/src/main/java/org/folio/rest/core/RestClient.java b/src/main/java/org/folio/rest/core/RestClient.java index 2fca7fc5..e0074d86 100644 --- a/src/main/java/org/folio/rest/core/RestClient.java +++ b/src/main/java/org/folio/rest/core/RestClient.java @@ -165,6 +165,7 @@ protected WebClient getVertxWebClient(Context context) { options.setKeepAlive(true); options.setConnectTimeout(2000); options.setIdleTimeout(5000); + options.setTryUseCompression(true); return WebClientFactory.getWebClient(context.owner(), options); } diff --git a/src/test/java/org/folio/services/fund/FundServiceTest.java b/src/test/java/org/folio/services/fund/FundServiceTest.java index 84db5e30..c240fa8e 100644 --- a/src/test/java/org/folio/services/fund/FundServiceTest.java +++ b/src/test/java/org/folio/services/fund/FundServiceTest.java @@ -63,8 +63,7 @@ public class FundServiceTest { @BeforeEach public void initMocks() { MockitoAnnotations.openMocks(this); - Context context = Vertx.vertx() - .getOrCreateContext(); + Context context = Vertx.vertx().getOrCreateContext(); Map okapiHeaders = new HashMap<>(); okapiHeaders.put(OKAPI_URL, "http://localhost:" + mockPort); okapiHeaders.put(X_OKAPI_TOKEN.getName(), X_OKAPI_TOKEN.getValue()); @@ -76,10 +75,8 @@ public void initMocks() { @Test void testShouldRetrieveFundById(VertxTestContext vertxTestContext) { // Given - String ledgerId = UUID.randomUUID() - .toString(); - String fundId = UUID.randomUUID() - .toString(); + String ledgerId = UUID.randomUUID().toString(); + String fundId = UUID.randomUUID().toString(); Fund fund = new Fund().withId(fundId) .withLedgerId(ledgerId); @@ -112,9 +109,7 @@ void testShouldThrowHttpExceptionAsCauseIfFundNotFound(VertxTestContext vertxTes vertxTestContext.assertFailure(future) .onComplete(result -> { HttpException actHttpException = (HttpException) result.cause(); - Error actError = actHttpException.getErrors() - .getErrors() - .get(0); + Error actError = actHttpException.getErrors().getErrors().get(0); assertEquals(actError.getCode(), expError.getCode()); assertEquals(actError.getMessage(), String.format(FUND_NOT_FOUND_ERROR.getDescription(), fundId)); assertEquals(NOT_FOUND, actHttpException.getCode()); @@ -127,8 +122,7 @@ void testShouldThrowHttpExceptionAsCauseIfFundNotFound(VertxTestContext vertxTes @Test void testShouldThrowNotHttpExceptionIfFundNotFound(VertxTestContext vertxTestContext) { // Given - String fundId = UUID.randomUUID() - .toString(); + String fundId = UUID.randomUUID().toString(); doReturn(Future.failedFuture(new RuntimeException())).when(restClient) .get(anyString(), eq(Fund.class), eq(requestContext)); var future = fundService.getFundById(fundId, requestContext); @@ -145,10 +139,8 @@ void testShouldThrowNotHttpExceptionIfFundNotFound(VertxTestContext vertxTestCon @Test void testShouldRetrieveFundsWithAcqUnits(VertxTestContext vertxTestContext) { // Given - String ledgerId = UUID.randomUUID() - .toString(); - String fundId = UUID.randomUUID() - .toString(); + String ledgerId = UUID.randomUUID().toString(); + String fundId = UUID.randomUUID().toString(); Fund fund = new Fund().withId(fundId) .withLedgerId(ledgerId); FundsCollection fundsCollection = new FundsCollection().withFunds(List.of(fund)) @@ -173,10 +165,8 @@ void testShouldRetrieveFundsWithAcqUnits(VertxTestContext vertxTestContext) { @Test void testShouldRetrieveFundsWithoutAcqUnits(VertxTestContext vertxTestContext) { // Given - String ledgerId = UUID.randomUUID() - .toString(); - String fundId = UUID.randomUUID() - .toString(); + String ledgerId = UUID.randomUUID().toString(); + String fundId = UUID.randomUUID().toString(); Fund fund = new Fund().withId(fundId) .withLedgerId(ledgerId); FundsCollection fundsCollection = new FundsCollection().withFunds(List.of(fund)) @@ -215,22 +205,10 @@ void testGetFundsByIds(VertxTestContext vertxTestContext) { assertTrue(result.succeeded()); var funds = result.result(); - assertEquals(fund1.getId(), fundsCollection.getFunds() - .get(0) - .getId()); - assertEquals(fund2.getId(), fundsCollection.getFunds() - .get(1) - .getId()); - assertEquals(funds.get(0) - .getId(), - fundsCollection.getFunds() - .get(0) - .getId()); - assertEquals(funds.get(1) - .getId(), - fundsCollection.getFunds() - .get(1) - .getId()); + assertEquals(fund1.getId(), fundsCollection.getFunds().get(0).getId()); + assertEquals(fund2.getId(), fundsCollection.getFunds().get(1).getId()); + assertEquals(funds.get(0).getId(),fundsCollection.getFunds().get(0).getId()); + assertEquals(funds.get(1).getId(),fundsCollection.getFunds().get(1).getId()); vertxTestContext.completeNow(); }); } @@ -255,22 +233,10 @@ void testGetFundsByIdsTwo(VertxTestContext vertxTestContext) { assertTrue(result.succeeded()); var funds = result.result(); - assertEquals(fund1.getId(), fundsCollection.getFunds() - .get(0) - .getId()); - assertEquals(fund2.getId(), fundsCollection.getFunds() - .get(1) - .getId()); - assertEquals(funds.get(0) - .getId(), - fundsCollection.getFunds() - .get(0) - .getId()); - assertEquals(funds.get(1) - .getId(), - fundsCollection.getFunds() - .get(1) - .getId()); + assertEquals(fund1.getId(), fundsCollection.getFunds().get(0).getId()); + assertEquals(fund2.getId(), fundsCollection.getFunds().get(1).getId()); + assertEquals(funds.get(0).getId(), fundsCollection.getFunds().get(0).getId()); + assertEquals(funds.get(1).getId(), fundsCollection.getFunds().get(1).getId()); vertxTestContext.completeNow(); }); @@ -296,16 +262,8 @@ void testGetFunds(VertxTestContext vertxTestContext) { assertTrue(result.succeeded()); var funds = result.result(); - assertEquals(fundsCollection.getFunds() - .get(0) - .getId(), - funds.get(0) - .getId()); - assertEquals(fundsCollection.getFunds() - .get(1) - .getId(), - funds.get(1) - .getId()); + assertEquals(fundsCollection.getFunds().get(0).getId(), funds.get(0).getId()); + assertEquals(fundsCollection.getFunds().get(1).getId(),funds.get(1).getId()); vertxTestContext.completeNow(); }); }