Skip to content

Commit

Permalink
MODFIN-283 minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Sep 8, 2023
1 parent 7eaa4e5 commit 7f3af33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 61 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/folio/rest/core/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
80 changes: 19 additions & 61 deletions src/test/java/org/folio/services/fund/FundServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> okapiHeaders = new HashMap<>();
okapiHeaders.put(OKAPI_URL, "http://localhost:" + mockPort);
okapiHeaders.put(X_OKAPI_TOKEN.getName(), X_OKAPI_TOKEN.getValue());
Expand All @@ -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);

Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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();
});
}
Expand All @@ -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();
});

Expand All @@ -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();
});
}
Expand Down

0 comments on commit 7f3af33

Please sign in to comment.