Search in sources :

Example 1 with CloseReason

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

the class PurchaseOrdersApiTest method testPutOrderWithoutPoLinesToChangeStatusFromOpenToClosedItemsHaveToBeUpdate.

@Test
void testPutOrderWithoutPoLinesToChangeStatusFromOpenToClosedItemsHaveToBeUpdate() {
    logger.info("===  Test case when order status updated from Open to Closed no PO Lines in payload - related items have to be updated ===");
    CompositePurchaseOrder reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_OPEN_TO_BE_CLOSED).mapTo(CompositePurchaseOrder.class);
    List<CompositePoLine> poLines = reqData.getCompositePoLines();
    poLines.forEach(line -> {
        line.setPurchaseOrderId(PO_ID_OPEN_TO_BE_CLOSED);
        line.setReceiptStatus(ReceiptStatus.AWAITING_RECEIPT);
        addMockEntry(PO_LINES_STORAGE, line);
    });
    MockServer.addMockTitles(poLines);
    reqData.setCompositePoLines(Collections.emptyList());
    reqData.setVendor(ACTIVE_VENDOR_ID);
    reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.CLOSED);
    reqData.setCloseReason(new CloseReason().withReason("Test"));
    reqData.setReEncumber(false);
    verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData), EMPTY, 204);
    PurchaseOrder purchaseOrder = getPurchaseOrderUpdates().get(0).mapTo(PurchaseOrder.class);
    assertThat(purchaseOrder.getWorkflowStatus(), is(PurchaseOrder.WorkflowStatus.CLOSED));
    assertThat(purchaseOrder.getCloseReason(), notNullValue());
    assertThat(purchaseOrder.getCloseReason().getReason(), equalTo("Test"));
    assertThat(getItemsSearches(), notNullValue());
    assertThat(getItemsSearches(), hasSize(1));
    assertThat(getItemUpdates(), notNullValue());
    assertThat(getItemUpdates(), hasSize(getItemsSearches().get(0).getJsonArray(ITEMS).size()));
    assertThat(getQueryParams(ITEM_RECORDS), hasSize(1));
    assertThat(getQueryParams(ITEM_RECORDS).get(0), containsAny("status.name==On order", poLines.get(0).getId()));
}
Also used : CloseReason(org.folio.rest.jaxrs.model.CloseReason) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) TestUtils.getMinimalContentCompositePurchaseOrder(org.folio.TestUtils.getMinimalContentCompositePurchaseOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) TestUtils.getMinimalContentCompositePurchaseOrder(org.folio.TestUtils.getMinimalContentCompositePurchaseOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Example 2 with CloseReason

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

the class PurchaseOrdersApiTest method testUpdateOrderWithProtectedFieldsChangingForClosedOrder.

@Test
void testUpdateOrderWithProtectedFieldsChangingForClosedOrder() {
    logger.info("=== Test case when closed order errors if protected fields are changed ===");
    JsonObject reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_CLOSED_STATUS);
    assertThat(reqData.getString("workflowStatus"), is(CompositePurchaseOrder.WorkflowStatus.CLOSED.value()));
    Map<String, Object> allProtectedFieldsModification = new HashMap<>();
    allProtectedFieldsModification.put(POProtectedFields.APPROVED.getFieldName(), false);
    allProtectedFieldsModification.put(POProtectedFields.PO_NUMBER.getFieldName(), "testPO");
    allProtectedFieldsModification.put(POProtectedFields.MANUAL_PO.getFieldName(), true);
    allProtectedFieldsModification.put(POProtectedFields.RE_ENCUMBER.getFieldName(), true);
    allProtectedFieldsModification.put(POProtectedFields.ORDER_TYPE.getFieldName(), CompositePurchaseOrder.OrderType.ONE_TIME.value());
    allProtectedFieldsModification.put(POProtectedFields.ONGOING.getFieldName(), null);
    CloseReason closeReason = new CloseReason();
    closeReason.setNote("testing reason on Closed Order");
    closeReason.setReason("Complete");
    allProtectedFieldsModification.put(POProtectedFields.CLOSE_REASON.getFieldName(), JsonObject.mapFrom(closeReason));
    checkPreventProtectedFieldsModificationRule(COMPOSITE_ORDERS_BY_ID_PATH, reqData, allProtectedFieldsModification);
}
Also used : HashMap(java.util.HashMap) CloseReason(org.folio.rest.jaxrs.model.CloseReason) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 3 with CloseReason

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

the class PurchaseOrdersApiTest method testCancelOrder.

@Test
void testCancelOrder() {
    logger.info("=== Test case: Cancel order ===");
    JsonObject reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_OPEN_TO_CANCEL);
    assertThat(reqData.getString("workflowStatus"), is(CompositePurchaseOrder.WorkflowStatus.OPEN.value()));
    reqData.put("workflowStatus", "Closed");
    CloseReason closeReason = new CloseReason();
    closeReason.setReason("Cancelled");
    reqData.put("closeReason", JsonObject.mapFrom(closeReason));
    reqData.remove("compositePoLines");
    verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getString("id")), JsonObject.mapFrom(reqData), "", 204);
    assertThat(getPurchaseOrderUpdates().get(0).mapTo(PurchaseOrder.class).getWorkflowStatus(), is(PurchaseOrder.WorkflowStatus.CLOSED));
    List<JsonObject> polUpdates = MockServer.getPoLineUpdates();
    assertNotNull(polUpdates);
    // check the payment and receipt status of the last 3 updated polines
    JsonObject line1 = polUpdates.get(polUpdates.size() - 3);
    assertEquals(ReceiptStatus.CANCELLED.value(), line1.getString(RECEIPT_STATUS));
    assertEquals(PaymentStatus.CANCELLED.value(), line1.getString(PAYMENT_STATUS));
    JsonObject line2 = polUpdates.get(polUpdates.size() - 2);
    assertEquals(ReceiptStatus.CANCELLED.value(), line2.getString(RECEIPT_STATUS));
    assertEquals(PaymentStatus.PAYMENT_NOT_REQUIRED.value(), line2.getString(PAYMENT_STATUS));
    JsonObject line3 = polUpdates.get(polUpdates.size() - 1);
    assertEquals(ReceiptStatus.FULLY_RECEIVED.value(), line3.getString(RECEIPT_STATUS));
    assertEquals(PaymentStatus.CANCELLED.value(), line3.getString(PAYMENT_STATUS));
}
Also used : CloseReason(org.folio.rest.jaxrs.model.CloseReason) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 4 with CloseReason

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

the class PurchaseOrdersApiTest method testUpdateOrderCloseOrderWithCloseReasonAndFundDistribution.

@Test
void testUpdateOrderCloseOrderWithCloseReasonAndFundDistribution() {
    logger.info("=== Test case: Able to Close Order with close Reason and fund distribution ===");
    JsonObject reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_WFD_ID_OPEN_STATUS);
    assertThat(reqData.getString("workflowStatus"), is(CompositePurchaseOrder.WorkflowStatus.OPEN.value()));
    reqData.put("workflowStatus", "Closed");
    // close reason must not be checked if the Order is in OPEN status in storage
    CloseReason closeReason = new CloseReason();
    closeReason.setNote("can set close reason");
    closeReason.setReason("Complete");
    reqData.put("closeReason", JsonObject.mapFrom(closeReason));
    verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getString("id")), JsonObject.mapFrom(reqData), "", 204);
}
Also used : CloseReason(org.folio.rest.jaxrs.model.CloseReason) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 5 with CloseReason

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

the class PurchaseOrdersApiTest method testUpdateOrderCloseOrderWithCloseReason.

@Test
void testUpdateOrderCloseOrderWithCloseReason() {
    logger.info("=== Test case: Able to Close Order with close Reason ===");
    JsonObject reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_OPEN_STATUS);
    assertThat(reqData.getString("workflowStatus"), is(CompositePurchaseOrder.WorkflowStatus.OPEN.value()));
    reqData.put("workflowStatus", "Closed");
    // close reason must not be checked if the Order is in OPEN status in storage
    CloseReason closeReason = new CloseReason();
    closeReason.setNote("can set close reason");
    closeReason.setReason("Complete");
    reqData.put("closeReason", JsonObject.mapFrom(closeReason));
    verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getString("id")), JsonObject.mapFrom(reqData), "", 204);
}
Also used : CloseReason(org.folio.rest.jaxrs.model.CloseReason) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Aggregations

CloseReason (org.folio.rest.jaxrs.model.CloseReason)6 Test (org.junit.jupiter.api.Test)6 JsonObject (io.vertx.core.json.JsonObject)4 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)2 HashMap (java.util.HashMap)1 TestUtils.getMinimalContentCompositePoLine (org.folio.TestUtils.getMinimalContentCompositePoLine)1 TestUtils.getMinimalContentCompositePurchaseOrder (org.folio.TestUtils.getMinimalContentCompositePurchaseOrder)1 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)1 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)1 PoLine (org.folio.rest.jaxrs.model.PoLine)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1