use of org.folio.rest.core.RestClient in project mod-orders by folio-org.
the class InvoiceLineServiceTest method shouldRemoveEncumbranceLinks.
@Test
void shouldRemoveEncumbranceLinks() {
// Given
String poLineId1 = UUID.randomUUID().toString();
String poLineId2 = UUID.randomUUID().toString();
String encumbrance1Id = UUID.randomUUID().toString();
String encumbrance2Id = UUID.randomUUID().toString();
String encumbrance3Id = UUID.randomUUID().toString();
List<String> transactionIds = List.of(encumbrance1Id, encumbrance2Id, encumbrance3Id);
String invoiceLineId1 = UUID.randomUUID().toString();
InvoiceLine invoiceLine1 = new InvoiceLine().withId(invoiceLineId1).withPoLineId(poLineId1).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance1Id))).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)))));
String invoiceLineId2 = UUID.randomUUID().toString();
InvoiceLine invoiceLine2 = new InvoiceLine().withId(invoiceLineId2).withPoLineId(poLineId2).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance3Id)))));
List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2);
InvoiceLine expectedInvoiceLine1 = JsonObject.mapFrom(invoiceLine1).mapTo(InvoiceLine.class);
expectedInvoiceLine1.getFundDistributions().get(0).setEncumbrance(null);
expectedInvoiceLine1.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
InvoiceLine expectedInvoiceLine2 = JsonObject.mapFrom(invoiceLine2).mapTo(InvoiceLine.class);
expectedInvoiceLine2.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
when(restClient.put(any(RequestEntry.class), any(InvoiceLine.class), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(null));
when(requestContextMock.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
// When
CompletableFuture<Void> result = invoiceLineService.removeEncumbranceLinks(invoiceLines, transactionIds, requestContextMock);
assertFalse(result.isCompletedExceptionally());
result.join();
// Then
verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId1.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine1), eq(requestContextMock));
verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId2.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine2), eq(requestContextMock));
}
use of org.folio.rest.core.RestClient in project mod-orders by folio-org.
the class PurchaseOrderHelperTest method testDeleteOrderLinkedToInvoiceWithError.
@Test
void testDeleteOrderLinkedToInvoiceWithError() {
// given
InvoiceLineService invoiceLineService = new InvoiceLineService(restClient);
RestClient restClient = mock(RestClient.class, CALLS_REAL_METHODS);
OrderInvoiceRelationService orderInvoiceRelationService = spy(new OrderInvoiceRelationService(restClient, invoiceLineService));
// for returning non empty collection
OrderInvoiceRelationshipCollection oirCollection = new OrderInvoiceRelationshipCollection().withOrderInvoiceRelationships(Collections.singletonList(new OrderInvoiceRelationship())).withTotalRecords(1);
doReturn(completedFuture(oirCollection)).when(restClient).get(any(), any(), any());
CompletableFuture<Void> future = orderInvoiceRelationService.checkOrderInvoiceRelationship(ORDER_ID, new RequestContext(ctxMock, okapiHeadersMock));
CompletionException exception = assertThrows(CompletionException.class, future::join);
HttpException httpException = (HttpException) exception.getCause();
assertEquals(ErrorCodes.ORDER_RELATES_TO_INVOICE.getDescription(), httpException.getMessage());
}
use of org.folio.rest.core.RestClient in project mod-orders by folio-org.
the class InventoryManagerTest method shouldCheckIfTheHoldingExistsWhenLocationIdAlwaysNewHoldingShouldBeCreated.
@Test
void shouldCheckIfTheHoldingExistsWhenLocationIdAlwaysNewHoldingShouldBeCreated() throws IOException {
String instanceId = UUID.randomUUID().toString();
JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
String holdingIdExp = extractId(getFirstObjectFromResponse(holdingsCollection, HOLDINGS_RECORDS));
List<JsonObject> holdings = holdingsCollection.getJsonArray(HOLDINGS_RECORDS).stream().map(o -> ((JsonObject) o)).collect(toList());
List<String> locationIds = holdings.stream().map(holding -> holding.getString(HOLDING_PERMANENT_LOCATION_ID)).collect(toList());
Location location = new Location().withLocationId(locationIds.get(0)).withQuantity(1).withQuantityPhysical(1);
doReturn(completedFuture(holdingIdExp)).when(restClient).post(any(RequestEntry.class), any(JsonObject.class), eq(PostResponseType.UUID), eq(String.class), eq(requestContext));
String holdingIdAct = inventoryManager.getOrCreateHoldingsRecord(instanceId, location, requestContext).join();
assertThat(holdingIdAct, equalTo(holdingIdExp));
verify(restClient, times(1)).post(any(RequestEntry.class), any(JsonObject.class), eq(PostResponseType.UUID), eq(String.class), eq(requestContext));
}
use of org.folio.rest.core.RestClient in project mod-orders by folio-org.
the class InventoryManagerTest method shouldReturnHoldingsByIdsIfTheyExist.
@Test
void shouldReturnHoldingsByIdsIfTheyExist() throws IOException, ExecutionException, InterruptedException {
JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
List<JsonObject> holdings = holdingsCollection.getJsonArray("holdingsRecords").stream().map(o -> ((JsonObject) o)).collect(toList());
List<String> holdingIds = holdings.stream().map(holding -> holding.getString(ID)).collect(toList());
doReturn(completedFuture(holdingsCollection)).when(restClient).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
List<JsonObject> actHoldings = inventoryManager.getHoldingsByIds(holdingIds, requestContext).get();
assertThat(actHoldings.size(), equalTo(holdings.size()));
verify(restClient, times(1)).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
}
use of org.folio.rest.core.RestClient in project mod-orders by folio-org.
the class InventoryManagerTest method shouldReturnHoldingsByInstanceIdAndLocationIdsIfTheyExist.
@Test
void shouldReturnHoldingsByInstanceIdAndLocationIdsIfTheyExist() throws IOException, ExecutionException, InterruptedException {
String instanceId = UUID.randomUUID().toString();
JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
List<JsonObject> holdings = holdingsCollection.getJsonArray("holdingsRecords").stream().map(o -> ((JsonObject) o)).collect(toList());
List<String> locationIds = holdings.stream().map(holding -> holding.getString(HOLDING_PERMANENT_LOCATION_ID)).collect(toList());
doReturn(completedFuture(holdingsCollection)).when(restClient).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
List<JsonObject> actHoldings = inventoryManager.getHoldingRecords(instanceId, locationIds, requestContext).get();
assertThat(actHoldings.size(), equalTo(holdings.size()));
verify(restClient, times(2)).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
}
Aggregations