use of org.folio.rest.acq.model.OrderInvoiceRelationshipCollection in project mod-orders by folio-org.
the class OrderInvoiceRelationServiceTest method testShouldThrowExceptionWhenOrderLineLinkedToInvoice.
@Test
void testShouldThrowExceptionWhenOrderLineLinkedToInvoice() {
// GIVEN
OrderInvoiceRelationshipCollection oirCollection = new OrderInvoiceRelationshipCollection().withOrderInvoiceRelationships(Collections.singletonList(new OrderInvoiceRelationship())).withTotalRecords(1);
doReturn(completedFuture(oirCollection)).when(restClient).get(any(), any(), any());
PoLine poLineLinkedToInvoice = new PoLine().withId(poLineIdConnectedToInvoice);
InvoiceLine invoiceLine1 = new InvoiceLine().withInvoiceId(invoiceId).withPoLineId(poLineIdConnectedToInvoice);
InvoiceLine invoiceLine2 = new InvoiceLine().withInvoiceId(invoiceId).withPoLineId(UUID.randomUUID().toString());
List<InvoiceLine> invoiceLines = Arrays.asList(invoiceLine1, invoiceLine2);
InvoiceLineCollection invoiceLineCollection = new InvoiceLineCollection();
invoiceLineCollection.setInvoiceLines(invoiceLines);
// WHEN
when(invoiceLineService.getInvoiceLinesByOrderLineId(eq(poLineIdConnectedToInvoice), any())).thenReturn(completedFuture(invoiceLines));
CompletableFuture<Void> future = orderInvoiceRelationService.checkOrderPOLineLinkedToInvoiceLine(poLineLinkedToInvoice, requestContext);
// THEN
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.acq.model.OrderInvoiceRelationshipCollection 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.acq.model.OrderInvoiceRelationshipCollection in project mod-orders by folio-org.
the class MockServer method handleGetOrderInvoiceRelationship.
private void handleGetOrderInvoiceRelationship(RoutingContext ctx) {
logger.info("handleGetOrderInvoiceRelationship got: " + ctx.request().path());
JsonObject emptyCollection = JsonObject.mapFrom(new OrderInvoiceRelationshipCollection().withTotalRecords(0));
serverResponse(ctx, 200, APPLICATION_JSON, emptyCollection.encodePrettily());
addServerRqRsData(HttpMethod.GET, "orderInvoiceRelationship", emptyCollection);
}
use of org.folio.rest.acq.model.OrderInvoiceRelationshipCollection in project mod-orders by folio-org.
the class OrderInvoiceRelationServiceTest method testShouldDeletePoLIneWhenOrderLineIsNotLinkedToInvoice.
@Test
void testShouldDeletePoLIneWhenOrderLineIsNotLinkedToInvoice() {
OrderInvoiceRelationshipCollection oirCollection = new OrderInvoiceRelationshipCollection().withOrderInvoiceRelationships(Collections.singletonList(new OrderInvoiceRelationship())).withTotalRecords(0);
doReturn(completedFuture(oirCollection)).when(restClient).get(any(), any(), any());
PoLine poLineNotLinkedToInvoice = new PoLine().withId(poLineIdNotConnectedToInvoice);
// WHEN
when(invoiceLineService.getInvoiceLinesByOrderLineId(eq(poLineIdNotConnectedToInvoice), any())).thenReturn(completedFuture(Collections.emptyList()));
orderInvoiceRelationService.checkOrderPOLineLinkedToInvoiceLine(poLineNotLinkedToInvoice, requestContext).join();
}
Aggregations