Search in sources :

Example 1 with InvoiceLineService

use of org.folio.service.invoice.InvoiceLineService 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 2 with InvoiceLineService

use of org.folio.service.invoice.InvoiceLineService in project mod-orders by folio-org.

the class EncumbranceServiceTest method shouldCallRemoveEncumbranceLinks.

@Test
void shouldCallRemoveEncumbranceLinks() {
    // Given
    String poLineId1 = UUID.randomUUID().toString();
    String poLineId2 = UUID.randomUUID().toString();
    String orderId = UUID.randomUUID().toString();
    String encumbrance1Id = UUID.randomUUID().toString();
    String encumbrance2Id = UUID.randomUUID().toString();
    String encumbrance3Id = UUID.randomUUID().toString();
    Transaction encumbrance1 = new Transaction().withId(encumbrance1Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId1));
    Transaction encumbrance2 = new Transaction().withId(encumbrance2Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId1));
    Transaction encumbrance3 = new Transaction().withId(encumbrance3Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId2));
    List<Transaction> transactions = List.of(encumbrance1, encumbrance2, encumbrance3);
    List<String> transactionIds = List.of(encumbrance1Id, encumbrance2Id, encumbrance3Id);
    InvoiceLine invoiceLine1 = new InvoiceLine().withId(UUID.randomUUID().toString()).withPoLineId(poLineId1).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance1Id))).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)))));
    InvoiceLine invoiceLine2 = new InvoiceLine().withId(UUID.randomUUID().toString()).withPoLineId(poLineId2).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance3Id)))));
    List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2);
    when(orderInvoiceRelationService.isOrderLinkedToAnInvoice(eq(orderId), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(true));
    when(invoiceLineService.getInvoiceLinesByOrderLineIds(anyList(), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(invoiceLines));
    when(invoiceLineService.removeEncumbranceLinks(anyList(), anyList(), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(null));
    // When
    CompletableFuture<Void> result = encumbranceService.deleteEncumbranceLinksInInvoiceLines(transactions, requestContextMock);
    assertFalse(result.isCompletedExceptionally());
    result.join();
    // Then
    verify(invoiceLineService, times(1)).removeEncumbranceLinks(argThat(lines -> lines.size() == 2), argThat(ids -> ids.containsAll(transactionIds)), eq(requestContextMock));
}
Also used : OrderInvoiceRelationService(org.folio.service.orders.OrderInvoiceRelationService) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Header(io.restassured.http.Header) X_OKAPI_USER_ID(org.folio.TestConstants.X_OKAPI_USER_ID) PoLine(org.folio.rest.jaxrs.model.PoLine) Context(io.vertx.core.Context) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) MockitoAnnotations(org.mockito.MockitoAnnotations) BigDecimal(java.math.BigDecimal) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) OKAPI_URL(org.folio.rest.RestConstants.OKAPI_URL) Mockito.doReturn(org.mockito.Mockito.doReturn) BASE_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.BASE_MOCK_DATA_PATH) UUID(java.util.UUID) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) TestConfig.mockPort(org.folio.TestConfig.mockPort) Test(org.junit.jupiter.api.Test) List(java.util.List) X_OKAPI_TOKEN(org.folio.TestConstants.X_OKAPI_TOKEN) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Mockito.inOrder(org.mockito.Mockito.inOrder) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InvoiceLineService(org.folio.service.invoice.InvoiceLineService) Mock(org.mockito.Mock) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Transaction(org.folio.rest.acq.model.finance.Transaction) ArrayList(java.util.ArrayList) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) RequestContext(org.folio.rest.core.models.RequestContext) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) InjectMocks(org.mockito.InjectMocks) InOrder(org.mockito.InOrder) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) FiscalYearService(org.folio.service.finance.FiscalYearService) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) ENCUMBRANCE_PATH(org.folio.rest.impl.MockServer.ENCUMBRANCE_PATH) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) TestUtils.getMockAsJson(org.folio.TestUtils.getMockAsJson) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) Test(org.junit.jupiter.api.Test)

Aggregations

RequestContext (org.folio.rest.core.models.RequestContext)2 InvoiceLineService (org.folio.service.invoice.InvoiceLineService)2 OrderInvoiceRelationService (org.folio.service.orders.OrderInvoiceRelationService)2 Test (org.junit.jupiter.api.Test)2 Header (io.restassured.http.Header)1 Context (io.vertx.core.Context)1 Vertx (io.vertx.core.Vertx)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletionException (java.util.concurrent.CompletionException)1 TestConfig.mockPort (org.folio.TestConfig.mockPort)1 X_OKAPI_TOKEN (org.folio.TestConstants.X_OKAPI_TOKEN)1 X_OKAPI_USER_ID (org.folio.TestConstants.X_OKAPI_USER_ID)1