Search in sources :

Example 1 with OrderInvoiceRelationService

use of org.folio.service.orders.OrderInvoiceRelationService 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)

Aggregations

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