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));
}
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));
}
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);
}
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));
}
Aggregations