Search in sources :

Example 1 with InvoiceLineCollection

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());
}
Also used : OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.OrderInvoiceRelationshipCollection) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) PoLine(org.folio.rest.jaxrs.model.PoLine) CompletionException(java.util.concurrent.CompletionException) OrderInvoiceRelationship(org.folio.rest.acq.model.OrderInvoiceRelationship) HttpException(org.folio.rest.core.exceptions.HttpException) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection) Test(org.junit.jupiter.api.Test)

Example 2 with InvoiceLineCollection

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);
}
Also used : InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) JsonObject(io.vertx.core.json.JsonObject) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection)

Aggregations

InvoiceLine (org.folio.rest.acq.model.invoice.InvoiceLine)2 InvoiceLineCollection (org.folio.rest.acq.model.invoice.InvoiceLineCollection)2 JsonObject (io.vertx.core.json.JsonObject)1 CompletionException (java.util.concurrent.CompletionException)1 OrderInvoiceRelationship (org.folio.rest.acq.model.OrderInvoiceRelationship)1 OrderInvoiceRelationshipCollection (org.folio.rest.acq.model.OrderInvoiceRelationshipCollection)1 HttpException (org.folio.rest.core.exceptions.HttpException)1 PoLine (org.folio.rest.jaxrs.model.PoLine)1 Test (org.junit.jupiter.api.Test)1