Search in sources :

Example 1 with OrderInvoiceRelationship

use of org.folio.rest.acq.model.OrderInvoiceRelationship 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 OrderInvoiceRelationship

use of org.folio.rest.acq.model.OrderInvoiceRelationship 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());
}
Also used : OrderInvoiceRelationService(org.folio.service.orders.OrderInvoiceRelationService) OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.OrderInvoiceRelationshipCollection) CompletionException(java.util.concurrent.CompletionException) RestClient(org.folio.rest.core.RestClient) OrderInvoiceRelationship(org.folio.rest.acq.model.OrderInvoiceRelationship) InvoiceLineService(org.folio.service.invoice.InvoiceLineService) HttpException(org.folio.rest.core.exceptions.HttpException) RequestContext(org.folio.rest.core.models.RequestContext) Test(org.junit.jupiter.api.Test)

Example 3 with OrderInvoiceRelationship

use of org.folio.rest.acq.model.OrderInvoiceRelationship 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();
}
Also used : OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.OrderInvoiceRelationshipCollection) PoLine(org.folio.rest.jaxrs.model.PoLine) OrderInvoiceRelationship(org.folio.rest.acq.model.OrderInvoiceRelationship) Test(org.junit.jupiter.api.Test)

Aggregations

OrderInvoiceRelationship (org.folio.rest.acq.model.OrderInvoiceRelationship)3 OrderInvoiceRelationshipCollection (org.folio.rest.acq.model.OrderInvoiceRelationshipCollection)3 Test (org.junit.jupiter.api.Test)3 CompletionException (java.util.concurrent.CompletionException)2 HttpException (org.folio.rest.core.exceptions.HttpException)2 PoLine (org.folio.rest.jaxrs.model.PoLine)2 InvoiceLine (org.folio.rest.acq.model.invoice.InvoiceLine)1 InvoiceLineCollection (org.folio.rest.acq.model.invoice.InvoiceLineCollection)1 RestClient (org.folio.rest.core.RestClient)1 RequestContext (org.folio.rest.core.models.RequestContext)1 InvoiceLineService (org.folio.service.invoice.InvoiceLineService)1 OrderInvoiceRelationService (org.folio.service.orders.OrderInvoiceRelationService)1