use of org.folio.service.invoice.InvoiceLineService 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.service.invoice.InvoiceLineService 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