use of org.folio.rest.acq.model.invoice.InvoiceLineCollection 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.invoice.InvoiceLineCollection in project mod-orders by folio-org.
the class MockServer method handleGetInvoiceLines.
private void handleGetInvoiceLines(RoutingContext ctx) {
// for testReopenOrderUnreleasesEncumbrancesUnlessInvoiceLineHasReleaseEncumbrance
String query = ctx.request().params().get("query");
String poLineId1 = "50fb5514-cdf1-11e8-a8d5-f2801f1b9fd1";
String poLineId2 = "4d3d5eb0-b32a-11eb-8529-0242ac130003";
InvoiceLineCollection invoiceLineCollection;
if (query.equals("poLineId == " + poLineId1 + " and releaseEncumbrance == true")) {
invoiceLineCollection = new InvoiceLineCollection().withInvoiceLines(Collections.emptyList()).withTotalRecords(0);
} else if (query.equals("poLineId == " + poLineId2 + " and releaseEncumbrance == true")) {
InvoiceLine invoiceLine = new InvoiceLine().withId(UUID.randomUUID().toString()).withPoLineId(poLineId2).withReleaseEncumbrance(true);
invoiceLineCollection = new InvoiceLineCollection().withInvoiceLines(List.of(invoiceLine)).withTotalRecords(1);
} else if (query.matches("poLineId(.*)")) {
InvoiceLine invoiceLine = new InvoiceLine().withId(UUID.randomUUID().toString()).withPoLineId(poLineId2).withInvoiceId(UUID.randomUUID().toString()).withReleaseEncumbrance(true);
invoiceLineCollection = new InvoiceLineCollection().withInvoiceLines(List.of(invoiceLine)).withTotalRecords(1);
} else {
serverResponse(ctx, HttpStatus.HTTP_NOT_FOUND.toInt(), APPLICATION_JSON, "invoice line not found");
return;
}
JsonObject jo = JsonObject.mapFrom(invoiceLineCollection);
serverResponse(ctx, 200, APPLICATION_JSON, jo.encodePrettily());
addServerRqRsData(HttpMethod.GET, "invoiceLines", jo);
}
Aggregations