Search in sources :

Example 56 with PurchaseOrder

use of org.folio.rest.jaxrs.model.PurchaseOrder in project mod-orders by folio-org.

the class PurchaseOrdersApiTest method testReopenOrderUnreleasesEncumbrancesUnlessInvoiceLineHasReleaseEncumbrance.

@Test
void testReopenOrderUnreleasesEncumbrancesUnlessInvoiceLineHasReleaseEncumbrance() {
    logger.info("=== Check encumbrances are unreleased when an order is reopened, except for po lines having a linked invoice line with releaseEncumbrance = true ===");
    String purchaseOrderId = "0fb18568-cf8d-442b-b74a-cad7cfa557a0";
    String poLineId1 = "0285a6b6-6693-4ea9-83e1-41d227063d88";
    String transactionId = "41fe8202-f038-4000-a969-4eee74ba8735";
    String fiscalYearId = "ac2164c7-ba3d-1bc2-a12c-e35ceccbfaf2";
    String fundId = "a89eccf0-57a6-495e-898d-32b9b2210f2f";
    List<String> transactionIds = Arrays.asList(transactionId);
    Cost cost = new Cost().withCurrency("USD").withListUnitPrice(10.00).withQuantityElectronic(1);
    FundDistribution fundDistribution = new FundDistribution().withFundId("fb7b70f1-b898-4924-a991-0e4b6312bb5f").withDistributionType(DistributionType.PERCENTAGE).withValue(100.00).withEncumbrance("eb506834-6c70-4239-8d1a-6414a5b08008");
    CompositePoLine poLines = new CompositePoLine().withId(poLineId1).withOrderFormat(OrderFormat.PHYSICAL_RESOURCE).withPoLineNumber("10233-1").withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.NONE)).withPurchaseOrderId(purchaseOrderId).withAcquisitionMethod(TestUtils.PURCHASE_METHOD).withCollection(true).withCost(cost).withFundDistribution(Arrays.asList(fundDistribution));
    CompositePurchaseOrder reqData = new CompositePurchaseOrder().withId(purchaseOrderId).withApproved(true).withPoNumber("S60402").withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME).withVendor("d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1").withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.CLOSED);
    Encumbrance encumbrance = new Encumbrance().withOrderType(Encumbrance.OrderType.ONE_TIME).withStatus(Encumbrance.Status.UNRELEASED).withSourcePoLineId(poLineId1).withReEncumber(false).withSubscription(false).withSourcePurchaseOrderId(purchaseOrderId).withInitialAmountEncumbered(10.00).withAmountAwaitingPayment(0.0).withAmountExpended(0.0);
    Metadata metadata = new Metadata().withCreatedByUserId("00000001-1111-5555-9999-999999999999").withUpdatedByUsername("00000001-1111-5555-9999-999999999999").withCreatedDate(new Date(2020, 05, 29, 11, 30)).withUpdatedDate(new Date(2020, 05, 30, 11, 30));
    Transaction transaction = new Transaction().withId(transactionId).withAmount(10.0).withSource(Transaction.Source.PO_LINE).withCurrency("USD").withToFundId(fundId).withEncumbrance(encumbrance).withFiscalYearId(fiscalYearId).withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withMetadata(metadata);
    MockServer.addMockEntry(PO_LINES_STORAGE, JsonObject.mapFrom(poLines));
    MockServer.addMockEntry(PURCHASE_ORDER_STORAGE, JsonObject.mapFrom(reqData));
    assertThat(reqData.getWorkflowStatus(), is(CompositePurchaseOrder.WorkflowStatus.CLOSED));
    reqData.setWorkflowStatus(WorkflowStatus.OPEN);
    // NOTE: permissions are checked in another test
    verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData).encodePrettily(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID, REOPEN_PERMISSIONS_HEADER), "", 204);
    // check the order has been reopened, the first encumbrance has been unreleased but not the second one
    PurchaseOrder po = getPurchaseOrderUpdates().get(0).mapTo(PurchaseOrder.class);
    assertThat(po.getWorkflowStatus(), is(PurchaseOrder.WorkflowStatus.OPEN));
    List<Transaction> transactions = Arrays.asList(transaction);
    TransactionCollection transactionCollection = new TransactionCollection().withTransactions(Arrays.asList(transaction)).withTotalRecords(1);
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            return null;
        }
    }).when(transactionService).updateTransactions(transactions, requestContext);
    doReturn(completedFuture(transactionCollection)).when(restClient).get(requestEntry, requestContext, TransactionCollection.class);
    doReturn(completedFuture(transactions)).when(transactionService).getTransactionsByIds(transactionIds, requestContext);
    List<Transaction> updatedTransactions = encumbranceService.getEncumbrancesByIds(transactionIds, requestContext).join();
    assertThat(updatedTransactions.size(), equalTo(1));
    Transaction updatedEncumbrance1 = updatedTransactions.get(0);
    assertThat(updatedEncumbrance1.getEncumbrance().getSourcePoLineId(), equalTo(poLineId1));
    assertThat(updatedEncumbrance1.getEncumbrance().getStatus(), equalTo(Encumbrance.Status.UNRELEASED));
}
Also used : TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) Metadata(org.folio.rest.acq.model.finance.Metadata) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) Matchers.containsString(org.hamcrest.Matchers.containsString) TestUtils.getMinimalContentCompositePurchaseOrder(org.folio.TestUtils.getMinimalContentCompositePurchaseOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Date(java.util.Date) LocalDate(java.time.LocalDate) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Physical(org.folio.rest.jaxrs.model.Physical) Transaction(org.folio.rest.acq.model.finance.Transaction) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) TestUtils.getMinimalContentCompositePurchaseOrder(org.folio.TestUtils.getMinimalContentCompositePurchaseOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Example 57 with PurchaseOrder

use of org.folio.rest.jaxrs.model.PurchaseOrder in project mod-orders by folio-org.

the class HelperUtilsTest method testOrderStatusToBeCancelled.

@Test
void testOrderStatusToBeCancelled() {
    PurchaseOrder purchaseOrder = new PurchaseOrder();
    purchaseOrder.setId(UUID.randomUUID().toString());
    purchaseOrder.setWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PoLine firstPoLine = new PoLine();
    firstPoLine.setId(UUID.randomUUID().toString());
    firstPoLine.setPaymentStatus(PoLine.PaymentStatus.CANCELLED);
    firstPoLine.setReceiptStatus(PoLine.ReceiptStatus.CANCELLED);
    PoLine secondPoLine = new PoLine();
    secondPoLine.setId(UUID.randomUUID().toString());
    secondPoLine.setPaymentStatus(PoLine.PaymentStatus.CANCELLED);
    secondPoLine.setReceiptStatus(PoLine.ReceiptStatus.CANCELLED);
    List<PoLine> poLines = List.of(firstPoLine, secondPoLine);
    assertTrue(HelperUtils.changeOrderStatus(purchaseOrder, poLines));
    assertEquals(purchaseOrder.getWorkflowStatus(), PurchaseOrder.WorkflowStatus.CLOSED);
    assertEquals(purchaseOrder.getCloseReason(), new CloseReason().withReason(REASON_CANCELLED));
}
Also used : CloseReason(org.folio.rest.jaxrs.model.CloseReason) PoLine(org.folio.rest.jaxrs.model.PoLine) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Test(org.junit.jupiter.api.Test)

Example 58 with PurchaseOrder

use of org.folio.rest.jaxrs.model.PurchaseOrder in project mod-orders by folio-org.

the class PurchaseOrderStorageServiceTest method successRetrievePurchaseOrdersByIds.

@Test
void successRetrievePurchaseOrdersByIds() {
    String orderId = UUID.randomUUID().toString();
    List<PurchaseOrder> purchaseOrders = Collections.singletonList(new PurchaseOrder().withId(orderId));
    PurchaseOrderCollection purchaseOrderCollection = new PurchaseOrderCollection().withPurchaseOrders(purchaseOrders).withTotalRecords(1);
    when(restClientMock.get(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(purchaseOrderCollection));
    List<PurchaseOrder> actOrders = purchaseOrderStorageService.getPurchaseOrdersByIds(List.of(orderId), requestContext).join();
    verify(restClientMock).get(any(), eq(requestContext), eq(PurchaseOrderCollection.class));
    assertEquals(purchaseOrderCollection.getPurchaseOrders(), actOrders);
}
Also used : PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Test(org.junit.jupiter.api.Test)

Example 59 with PurchaseOrder

use of org.folio.rest.jaxrs.model.PurchaseOrder in project mod-orders by folio-org.

the class RestClientTest method testSearchShouldThrowExceptionIfItemNotFind.

@Test
void testSearchShouldThrowExceptionIfItemNotFind() throws Exception {
    RestClient restClient = Mockito.spy(new RestClient());
    String uuid = UUID.randomUUID().toString();
    Response response = new Response();
    response.setCode(404);
    response.setError(new JsonObject("{\"endpoint\":\"/composite-orders\",\"statusCode\": 404 , \"errorMessage\":\"Not found\"}"));
    doReturn(httpClient).when(restClient).getHttpClient(okapiHeaders);
    String endpoint = resourcesPath(PURCHASE_ORDER_STORAGE) + "/{id}";
    doReturn(completedFuture(response)).when(httpClient).request(eq(HttpMethod.DELETE), anyString(), eq(okapiHeaders));
    RequestEntry requestEntry = new RequestEntry(endpoint).withId(uuid);
    CompletableFuture<PurchaseOrder> resultFuture = restClient.get(requestEntry, false, requestContext, PurchaseOrder.class);
    ExecutionException executionException = assertThrows(ExecutionException.class, resultFuture::get);
    verify(httpClient).request(eq(HttpMethod.GET), eq(requestEntry.buildEndpoint()), eq(okapiHeaders));
}
Also used : Response(org.folio.rest.tools.client.Response) JsonObject(io.vertx.core.json.JsonObject) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RequestEntry(org.folio.rest.core.models.RequestEntry) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Aggregations

PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)59 Test (org.junit.jupiter.api.Test)52 PoLine (org.folio.rest.jaxrs.model.PoLine)49 Cost (org.folio.rest.jaxrs.model.Cost)46 Piece (org.folio.rest.jaxrs.model.Piece)42 Location (org.folio.rest.jaxrs.model.Location)39 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)32 Eresource (org.folio.rest.jaxrs.model.Eresource)28 Physical (org.folio.rest.jaxrs.model.Physical)24 JsonObject (io.vertx.core.json.JsonObject)23 ArrayList (java.util.ArrayList)23 DisplayName (org.junit.jupiter.api.DisplayName)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 PieceCreationHolder (org.folio.models.pieces.PieceCreationHolder)12 PieceDeletionHolder (org.folio.models.pieces.PieceDeletionHolder)12 PieceUpdateHolder (org.folio.models.pieces.PieceUpdateHolder)12 List (java.util.List)10 Map (java.util.Map)10 CompletableFuture (java.util.concurrent.CompletableFuture)10 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)10