Search in sources :

Example 1 with CompositeFund

use of org.folio.rest.acq.model.finance.CompositeFund in project mod-invoice by folio-org.

the class MockServer method handleFundById.

private void handleFundById(RoutingContext ctx) {
    logger.info("handleFund got: GET " + ctx.request().path());
    String id = ctx.request().getParam(AbstractHelper.ID);
    logger.info("id: " + id);
    if (ID_DOES_NOT_EXIST.equals(id)) {
        serverResponse(ctx, 404, APPLICATION_JSON, Response.Status.NOT_FOUND.getReasonPhrase());
    } else if (ID_FOR_INTERNAL_SERVER_ERROR.equals(id)) {
        serverResponse(ctx, 500, APPLICATION_JSON, INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else {
        Fund fund = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString()).withCode("TEST").withName("TEST");
        List<CompositeFund> funds = getMockEntries(FUNDS, Fund.class).map(funds1 -> funds1.stream().map(fund1 -> new CompositeFund().withFund(fund1)).collect(toList())).orElse(Collections.singletonList(new CompositeFund().withFund(fund)));
        addServerRqRsData(HttpMethod.GET, FUNDS, JsonObject.mapFrom(funds.get(0)));
        serverResponse(ctx, 200, APPLICATION_JSON, JsonObject.mapFrom(funds.get(0)).encodePrettily());
    }
}
Also used : Fund(org.folio.rest.acq.model.finance.Fund) CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CompositeFund(org.folio.rest.acq.model.finance.CompositeFund)

Example 2 with CompositeFund

use of org.folio.rest.acq.model.finance.CompositeFund in project mod-orders by folio-org.

the class FundServiceTest method testShouldRetrieveFundById.

@Test
void testShouldRetrieveFundById() {
    // Given
    String ledgerId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    CompositeFund compositeFund = new CompositeFund().withFund(new Fund().withId(fundId).withLedgerId(ledgerId));
    doReturn(completedFuture(compositeFund)).when(restClient).get(any(), eq(requestContext), eq(CompositeFund.class));
    // When
    Fund actFund = fundService.retrieveFundById(fundId, requestContext).join();
    // Then
    assertThat(actFund, equalTo(compositeFund.getFund()));
    ArgumentCaptor<RequestEntry> argumentCaptor = ArgumentCaptor.forClass(RequestEntry.class);
    verify(restClient).get(argumentCaptor.capture(), eq(requestContext), eq(CompositeFund.class));
    RequestEntry requestEntry = argumentCaptor.getValue();
    assertEquals("/finance/funds/" + fundId, requestEntry.buildEndpoint());
}
Also used : CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) Fund(org.folio.rest.acq.model.finance.Fund) CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Aggregations

CompositeFund (org.folio.rest.acq.model.finance.CompositeFund)2 Fund (org.folio.rest.acq.model.finance.Fund)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 RequestEntry (org.folio.rest.core.models.RequestEntry)1 Test (org.junit.jupiter.api.Test)1