use of org.folio.rest.acq.model.invoice.Adjustment 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.acq.model.invoice.Adjustment in project mod-orders by folio-org.
the class EncumbranceServiceTest method shouldCallRemoveEncumbranceLinks.
@Test
void shouldCallRemoveEncumbranceLinks() {
// Given
String poLineId1 = UUID.randomUUID().toString();
String poLineId2 = UUID.randomUUID().toString();
String orderId = UUID.randomUUID().toString();
String encumbrance1Id = UUID.randomUUID().toString();
String encumbrance2Id = UUID.randomUUID().toString();
String encumbrance3Id = UUID.randomUUID().toString();
Transaction encumbrance1 = new Transaction().withId(encumbrance1Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId1));
Transaction encumbrance2 = new Transaction().withId(encumbrance2Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId1));
Transaction encumbrance3 = new Transaction().withId(encumbrance3Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId2));
List<Transaction> transactions = List.of(encumbrance1, encumbrance2, encumbrance3);
List<String> transactionIds = List.of(encumbrance1Id, encumbrance2Id, encumbrance3Id);
InvoiceLine invoiceLine1 = new InvoiceLine().withId(UUID.randomUUID().toString()).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)))));
InvoiceLine invoiceLine2 = new InvoiceLine().withId(UUID.randomUUID().toString()).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);
when(orderInvoiceRelationService.isOrderLinkedToAnInvoice(eq(orderId), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(true));
when(invoiceLineService.getInvoiceLinesByOrderLineIds(anyList(), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(invoiceLines));
when(invoiceLineService.removeEncumbranceLinks(anyList(), anyList(), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(null));
// When
CompletableFuture<Void> result = encumbranceService.deleteEncumbranceLinksInInvoiceLines(transactions, requestContextMock);
assertFalse(result.isCompletedExceptionally());
result.join();
// Then
verify(invoiceLineService, times(1)).removeEncumbranceLinks(argThat(lines -> lines.size() == 2), argThat(ids -> ids.containsAll(transactionIds)), eq(requestContextMock));
}
Aggregations