use of org.folio.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPutOrdersByIdToChangeStatusToOpenButWithErrorCreatingItemsForSecondPOL.
@Test
void testPutOrdersByIdToChangeStatusToOpenButWithErrorCreatingItemsForSecondPOL() throws Exception {
logger.info("=== Test Put Order By Id to change Order's status to Open - Inventory errors expected on items creation for second POL ===");
/*============== Preparation ==============*/
// Get Open Order
CompositePurchaseOrder reqData = getMockDraftOrder().mapTo(CompositePurchaseOrder.class);
reqData.setId(ID_FOR_PRINT_MONOGRAPH_ORDER);
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
int polCount = reqData.getCompositePoLines().size();
// Make sure that mock PO has 2 lines
assertThat(reqData.getCompositePoLines(), hasSize(2));
// Make sure that inventory interaction is expected for each PO line
for (CompositePoLine pol : reqData.getCompositePoLines()) {
assertTrue(calculateInventoryItemsQuantity(pol) > 0);
}
// Set location ids to one which emulates item creation failure
CompositePoLine line1 = reqData.getCompositePoLines().get(0);
CompositePoLine line2 = reqData.getCompositePoLines().get(1);
reqData.getCompositePoLines().get(1).getLocations().forEach(location -> location.withLocationId(ID_FOR_INTERNAL_SERVER_ERROR));
reqData.getCompositePoLines().get(1).getLocations().get(0).setLocationId(UUID.randomUUID().toString());
preparePiecesForCompositePo(reqData);
String path = String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId());
/*============== Assert result ==============*/
// Server Error expected as a result because not all items created
verifyPut(path, JsonObject.mapFrom(reqData), APPLICATION_JSON, 500);
List<JsonObject> respOrder = MockServer.serverRqRs.get(PURCHASE_ORDER_STORAGE, HttpMethod.GET);
CompositePurchaseOrder compPo = respOrder.get(0).mapTo(CompositePurchaseOrder.class);
List<JsonObject> respLines = MockServer.serverRqRs.get(PO_LINES_STORAGE, HttpMethod.PUT);
CompositePoLine respLine1 = respLines.stream().filter(line -> line.getString(ID).equals(line1.getId())).peek(line -> line.remove("reportingCodes")).map(line -> line.mapTo(CompositePoLine.class)).distinct().findAny().get();
CompositePoLine respLine2 = respLines.stream().filter(line -> line.getString(ID).equals(line2.getId())).peek(line -> line.remove("reportingCodes")).map(line -> line.mapTo(CompositePoLine.class)).findAny().get();
compPo.setCompositePoLines(List.of(respLine1, respLine2));
// Check that search of the existing instances and items was done for each PO line
List<JsonObject> instancesSearches = getInstancesSearches();
assertNotNull(instancesSearches);
assertNotNull(getItemsSearches());
assertNotNull(getPieceSearches());
assertEquals(polCount, instancesSearches.size());
// Check that 2 new instances created and items created successfully only for first POL
List<JsonObject> createdInstances = getCreatedInstances();
List<JsonObject> createdPieces = getCreatedPieces();
assertNotNull(createdInstances);
assertNotNull(getCreatedItems());
assertNotNull(createdPieces);
assertEquals(polCount, createdInstances.size());
List<JsonObject> items = joinExistingAndNewItems();
// Check instance Ids not exist for polines
verifyInstanceLinksNotCreatedForPoLine();
// Verify pieces were created
assertEquals(calculateTotalQuantity(compPo.getCompositePoLines().get(0)) + calculateTotalQuantity(compPo.getCompositePoLines().get(1)) - 1, createdPieces.size());
// Effectively remove non-processed locations with ID_FOR_INTERNAL_SERVER_ERROR to exclude them from
// created pieces verification
compPo.getCompositePoLines().forEach(poLine -> poLine.getLocations().removeIf(l -> {
if (l.getLocationId().equals(ID_FOR_INTERNAL_SERVER_ERROR)) {
if (poLine.getCost().getQuantityElectronic() != null) {
poLine.getCost().setQuantityElectronic(poLine.getCost().getQuantityElectronic() - l.getQuantityElectronic());
}
if (poLine.getCost().getQuantityPhysical() != null) {
poLine.getCost().setQuantityPhysical(poLine.getCost().getQuantityPhysical() - l.getQuantityPhysical());
}
return true;
} else {
return false;
}
}));
verifyPiecesCreated(items, compPo.getCompositePoLines(), createdPieces);
}
use of org.folio.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPostListedPrintSerialInOpenStatus.
@Test
@Disabled
// TODO Must be fixed in scope of https://issues.folio.org/browse/MODORDERS-587
void testPostListedPrintSerialInOpenStatus() throws Exception {
logger.info("=== Test Listed Print Monograph in Open status ===");
CompositePurchaseOrder reqData = new JsonObject(getMockData(LISTED_PRINT_SERIAL_PATH)).mapTo(CompositePurchaseOrder.class);
String orderId = UUID.randomUUID().toString();
reqData.setWorkflowStatus(WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
prepareOrderForPostRequest(reqData);
reqData.setId(orderId);
reqData.getCompositePoLines().forEach(poLine -> {
poLine.setPaymentStatus(CompositePoLine.PaymentStatus.PENDING);
poLine.setReceiptStatus(ReceiptStatus.PENDING);
});
LocalDate now = LocalDate.now();
final CompositePurchaseOrder resp = verifyPostResponse(COMPOSITE_ORDERS_PATH, JsonObject.mapFrom(reqData).toString(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, 201).as(CompositePurchaseOrder.class);
LocalDate dateOrdered = resp.getDateOrdered().toInstant().atZone(ZoneId.of(ZoneOffset.UTC.getId())).toLocalDate();
assertThat(dateOrdered.getMonth(), equalTo(now.getMonth()));
assertThat(dateOrdered.getYear(), equalTo(now.getYear()));
logger.info(JsonObject.mapFrom(resp));
String poId = resp.getId();
String poNumber = resp.getPoNumber();
assertNotNull(poId);
assertNotNull(poNumber);
assertEquals(reqData.getCompositePoLines().size(), resp.getCompositePoLines().size());
for (int i = 0; i < resp.getCompositePoLines().size(); i++) {
CompositePoLine line = resp.getCompositePoLines().get(i);
String polNumber = line.getPoLineNumber();
String polId = line.getId();
assertEquals(poId, line.getPurchaseOrderId());
assertNotNull(polId);
assertNotNull(polNumber);
assertTrue(polNumber.startsWith(poNumber));
assertNotNull(line.getInstanceId());
line.getLocations().forEach(location -> verifyLocationQuantity(location, line.getOrderFormat()));
line.getLocations().forEach(location -> {
assertNull(location.getLocationId());
assertNotNull(location.getHoldingId());
});
}
int polCount = resp.getCompositePoLines().size();
List<JsonObject> instancesSearches = getInstancesSearches();
assertNotNull(instancesSearches);
assertEquals(polCount, instancesSearches.size());
CompositePoLine respLine1 = resp.getCompositePoLines().get(0);
List<JsonObject> createdInstances = getCreatedInstances();
assertEquals(1, createdInstances.size(), "Quantity of created instance must be equal of line, if create inventory include instance");
assertNotNull("Line must be connected to instance, if create inventory include instance", respLine1.getInstanceId());
List<JsonObject> createdHoldings = getCreatedHoldings();
assertEquals(1, createdHoldings.size(), "Quantity of created holding must be depended of quantity in the locations and create inventory include holding");
verifyHoldingsCreated(1, createdHoldings, respLine1);
// All existing and created items
List<JsonObject> items = joinExistingAndNewItems();
verifyItemsCreated(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, 1, items, respLine1);
List<JsonObject> createdPieces = getCreatedPieces();
verifyOpenOrderPiecesCreated(items, resp.getCompositePoLines(), createdPieces, 0);
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> PHYSICAL.equals(piece.getFormat())).forEach(piece -> {
assertNull(piece.getLocationId());
assertNotNull(piece.getHoldingId());
});
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> ELECTRONIC.equals(piece.getFormat())).forEach(piece -> {
assertNotNull(piece.getLocationId());
assertNull(piece.getHoldingId());
});
verifyEncumbrancesOnPoCreation(reqData, resp);
assertThat(getExistingOrderSummaries(), hasSize(0));
verifyCalculatedData(resp);
// MODORDERS-459 - check status changed to ONGOING
verifyReceiptStatusChangedTo(ReceiptStatus.ONGOING.value(), reqData.getCompositePoLines().size());
verifyPaymentStatusChangedTo(CompositePoLine.PaymentStatus.ONGOING.value(), reqData.getCompositePoLines().size());
}
use of org.folio.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method verifyInstanceLinksNotCreatedForPoLine.
private void verifyInstanceLinksNotCreatedForPoLine() {
List<JsonObject> polUpdates = MockServer.getPoLineUpdates();
assertNotNull(polUpdates);
boolean instanceIdExists = false;
for (JsonObject jsonObj : polUpdates) {
PoLine line = jsonObj.mapTo(PoLine.class);
if (StringUtils.isNotEmpty(getInstanceId(line))) {
instanceIdExists = true;
break;
}
}
assertFalse(instanceIdExists, "The PO Line must NOT contain instance id");
}
use of org.folio.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class OrderRolloverServiceTest method shouldUpdateOrderLinesCostAndEncumbranceLinksAndPolCurrencyVsSystemCurrencyTheSame.
@Test
@DisplayName("Should update order lines cost And Encumbrance Links where Pol Currency equals systemCurrency")
void shouldUpdateOrderLinesCostAndEncumbranceLinksAndPolCurrencyVsSystemCurrencyTheSame() {
String fromFiscalYearId = UUID.randomUUID().toString();
String ledgerId = UUID.randomUUID().toString();
String toFiscalYearId = UUID.randomUUID().toString();
String fundId1 = UUID.randomUUID().toString();
String fundId2 = UUID.randomUUID().toString();
String fundId3 = UUID.randomUUID().toString();
String orderId1 = UUID.randomUUID().toString();
String orderId2 = UUID.randomUUID().toString();
String orderId3 = UUID.randomUUID().toString();
String poLineId1 = UUID.randomUUID().toString();
String poLineId2 = UUID.randomUUID().toString();
String poLineId3 = UUID.randomUUID().toString();
String prevEncumbrId1 = UUID.randomUUID().toString();
String prevEncumbrId2 = UUID.randomUUID().toString();
String prevEncumbrId3 = UUID.randomUUID().toString();
String currEncumbrId1 = UUID.randomUUID().toString();
String currEncumbrId2 = UUID.randomUUID().toString();
String currEncumbrId3 = UUID.randomUUID().toString();
String expClassId2 = UUID.randomUUID().toString();
String expClassId3 = UUID.randomUUID().toString();
EncumbranceRollover ongoingEncumbranceBasedOnExpended = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.EXPENDED);
EncumbranceRollover oneTimeEncumbrance = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withBasedOn(EncumbranceRollover.BasedOn.REMAINING);
EncumbranceRollover ongoingEncumbranceBasedOnInitialAmount = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.INITIAL_AMOUNT);
LedgerFiscalYearRollover ledgerFiscalYearRollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withFromFiscalYearId(fromFiscalYearId).withLedgerId(ledgerId).withToFiscalYearId(toFiscalYearId).withEncumbrancesRollover(List.of(ongoingEncumbranceBasedOnExpended, oneTimeEncumbrance, ongoingEncumbranceBasedOnInitialAmount));
List<Fund> funds = List.of(new Fund().withId(fundId1).withLedgerId(ledgerId), new Fund().withId(fundId2).withLedgerId(ledgerId), new Fund().withId(fundId3).withLedgerId(ledgerId));
PurchaseOrder purchaseOrder1 = new PurchaseOrder().withId(orderId1).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
PurchaseOrder purchaseOrder2 = new PurchaseOrder().withId(orderId2).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
PurchaseOrder purchaseOrder3 = new PurchaseOrder().withId(orderId3).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
List<PurchaseOrder> orders = List.of(purchaseOrder1, purchaseOrder2, purchaseOrder3);
PurchaseOrderCollection purchaseOrderCollection = new PurchaseOrderCollection().withPurchaseOrders(orders).withTotalRecords(3);
FundDistribution fundDistributionOneTime = new FundDistribution().withFundId(fundId1).withValue(100d).withEncumbrance(prevEncumbrId1);
FundDistribution fundDistributionOngoing2 = new FundDistribution().withFundId(fundId2).withValue(100d).withEncumbrance(prevEncumbrId2).withExpenseClassId(expClassId2);
FundDistribution fundDistributionOngoing3 = new FundDistribution().withFundId(fundId3).withValue(100d).withEncumbrance(prevEncumbrId3).withExpenseClassId(expClassId3);
Cost costOneTime = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
PoLine poLineOneTime = new PoLine().withId(poLineId1).withPurchaseOrderId(orderId1).withCost(costOneTime).withFundDistribution(List.of(fundDistributionOneTime));
Cost costOngoing2 = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
PoLine poLineOngoing2 = new PoLine().withId(poLineId2).withPurchaseOrderId(orderId2).withCost(costOngoing2).withFundDistribution(List.of(fundDistributionOngoing2));
Cost costOngoing3 = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
PoLine poLineOngoing3 = new PoLine().withId(poLineId3).withPurchaseOrderId(orderId3).withCost(costOngoing3).withFundDistribution(List.of(fundDistributionOngoing3));
List<PoLine> poLines = List.of(poLineOneTime, poLineOngoing2, poLineOngoing3);
doReturn(completedFuture(funds)).when(fundService).getFundsByLedgerId(ledgerId, requestContext);
doReturn(completedFuture(purchaseOrderCollection)).when(purchaseOrderStorageService).getPurchaseOrders(anyString(), anyInt(), anyInt(), any());
doReturn(completedFuture(poLines)).when(purchaseOrderLineService).getOrderLines(anyString(), anyInt(), anyInt(), any());
doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLines(eq(poLines), any());
Encumbrance encumbranceOneTime = new Encumbrance().withSourcePurchaseOrderId(orderId1).withSourcePoLineId(poLineId1).withOrderType(Encumbrance.OrderType.ONE_TIME).withInitialAmountEncumbered(60d);
Transaction transactionOneTime = new Transaction().withId(currEncumbrId1).withFromFundId(fundId1).withEncumbrance(encumbranceOneTime);
Encumbrance encumbranceOngoing2 = new Encumbrance().withSourcePurchaseOrderId(orderId2).withSourcePoLineId(poLineId2).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(90d);
Transaction transactionOngoing2 = new Transaction().withId(currEncumbrId2).withFromFundId(fundId2).withEncumbrance(encumbranceOngoing2).withExpenseClassId(expClassId2);
Encumbrance encumbranceOngoing3 = new Encumbrance().withSourcePurchaseOrderId(orderId3).withSourcePoLineId(poLineId3).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(95d);
Transaction transactionOngoing3 = new Transaction().withId(currEncumbrId3).withFromFundId(fundId3).withEncumbrance(encumbranceOngoing3).withExpenseClassId(expClassId3);
List<Transaction> encumbrances = List.of(transactionOneTime, transactionOngoing2, transactionOngoing3);
TransactionCollection encumbranceCollection = new TransactionCollection().withTransactions(encumbrances).withTotalRecords(3);
doReturn(completedFuture(encumbranceCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), any());
double exchangeEurToUsdRate = 1.0d;
doReturn(completedFuture(systemCurrency)).when(configurationEntriesService).getSystemCurrency(requestContext);
String polCurrency = systemCurrency;
ConversionQuery actQuery = ConversionQueryBuilder.of().setBaseCurrency(polCurrency).setTermCurrency(systemCurrency).set(RATE_KEY, exchangeEurToUsdRate).build();
ExchangeRateProvider exchangeRateProvider = Mockito.mock(ManualExchangeRateProvider.class);
ManualCurrencyConversion manualCurrencyConversion = new ManualCurrencyConversion(actQuery, exchangeRateProvider, ConversionContext.of());
ExchangeRate exchangeRate = mock(ExchangeRate.class);
doReturn(exchangeRateProvider).when(exchangeRateProviderResolver).resolve(any(ConversionQuery.class), eq(requestContext));
doReturn(manualCurrencyConversion).when(exchangeRateProvider).getCurrencyConversion(any(ConversionQuery.class));
doReturn(exchangeRate).when(exchangeRateProvider).getExchangeRate(any(ConversionQuery.class));
when(exchangeRate.getContext()).thenReturn(ConversionContext.of());
when(exchangeRate.getCurrency()).thenReturn(Monetary.getCurrency(systemCurrency));
when(exchangeRate.getBaseCurrency()).thenReturn(Monetary.getCurrency(polCurrency));
when(exchangeRate.getFactor()).thenReturn(new DefaultNumberValue(exchangeEurToUsdRate));
CompletableFuture<Void> future = orderRolloverService.rollover(ledgerFiscalYearRollover, requestContext);
future.join();
assertFalse(future.isCompletedExceptionally());
assertThat(fundDistributionOneTime.getEncumbrance(), equalTo(currEncumbrId1));
assertThat(fundDistributionOngoing2.getEncumbrance(), equalTo(currEncumbrId2));
assertThat(fundDistributionOngoing3.getEncumbrance(), equalTo(currEncumbrId3));
assertThat(costOneTime.getPoLineEstimatedPrice(), equalTo(60d));
assertThat(costOngoing2.getPoLineEstimatedPrice(), equalTo(90d));
assertThat(costOngoing3.getPoLineEstimatedPrice(), equalTo(95d));
assertThat(costOneTime.getFyroAdjustmentAmount(), equalTo(-40d));
assertThat(costOngoing2.getFyroAdjustmentAmount(), equalTo(-10d));
assertThat(costOngoing3.getFyroAdjustmentAmount(), equalTo(-5d));
}
use of org.folio.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class OrderRolloverServiceTest method shouldUpdateOrderLinesCostAndEncumbranceLinksWithExchangeRateAndPolCurrencyVsSystemCurrencyAreDifferent.
@Test
@DisplayName("Should update order lines cost And Encumbrance Links where Pol Currency and systemCurrency are different")
void shouldUpdateOrderLinesCostAndEncumbranceLinksWithExchangeRateAndPolCurrencyVsSystemCurrencyAreDifferent() {
String fromFiscalYearId = UUID.randomUUID().toString();
String ledgerId = UUID.randomUUID().toString();
String toFiscalYearId = UUID.randomUUID().toString();
String fundId1 = UUID.randomUUID().toString();
String fundId2 = UUID.randomUUID().toString();
String fundId3 = UUID.randomUUID().toString();
String orderId1 = UUID.randomUUID().toString();
String orderId2 = UUID.randomUUID().toString();
String orderId3 = UUID.randomUUID().toString();
String poLineId1 = UUID.randomUUID().toString();
String poLineId2 = UUID.randomUUID().toString();
String poLineId3 = UUID.randomUUID().toString();
String prevEncumbrId1 = UUID.randomUUID().toString();
String prevEncumbrId2 = UUID.randomUUID().toString();
String prevEncumbrId3 = UUID.randomUUID().toString();
String currEncumbrId1 = UUID.randomUUID().toString();
String currEncumbrId2 = UUID.randomUUID().toString();
String currEncumbrId3 = UUID.randomUUID().toString();
String expClassId2 = UUID.randomUUID().toString();
String expClassId3 = UUID.randomUUID().toString();
EncumbranceRollover ongoingEncumbranceBasedOnExpended = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.EXPENDED);
EncumbranceRollover oneTimeEncumbrance = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withBasedOn(EncumbranceRollover.BasedOn.REMAINING);
EncumbranceRollover ongoingEncumbranceBasedOnInitialAmount = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.INITIAL_AMOUNT);
LedgerFiscalYearRollover ledgerFiscalYearRollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withFromFiscalYearId(fromFiscalYearId).withLedgerId(ledgerId).withToFiscalYearId(toFiscalYearId).withEncumbrancesRollover(List.of(ongoingEncumbranceBasedOnExpended, oneTimeEncumbrance, ongoingEncumbranceBasedOnInitialAmount));
List<Fund> funds = List.of(new Fund().withId(fundId1).withLedgerId(ledgerId), new Fund().withId(fundId2).withLedgerId(ledgerId), new Fund().withId(fundId3).withLedgerId(ledgerId));
PurchaseOrder purchaseOrder1 = new PurchaseOrder().withId(orderId1).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
PurchaseOrder purchaseOrder2 = new PurchaseOrder().withId(orderId2).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
PurchaseOrder purchaseOrder3 = new PurchaseOrder().withId(orderId3).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
List<PurchaseOrder> orders = List.of(purchaseOrder1, purchaseOrder2, purchaseOrder3);
PurchaseOrderCollection purchaseOrderCollection = new PurchaseOrderCollection().withPurchaseOrders(orders).withTotalRecords(3);
FundDistribution fundDistributionOneTime = new FundDistribution().withFundId(fundId1).withValue(100d).withEncumbrance(prevEncumbrId1);
FundDistribution fundDistributionOngoing2 = new FundDistribution().withFundId(fundId2).withValue(100d).withEncumbrance(prevEncumbrId2).withExpenseClassId(expClassId2);
FundDistribution fundDistributionOngoing3 = new FundDistribution().withFundId(fundId3).withValue(100d).withEncumbrance(prevEncumbrId3).withExpenseClassId(expClassId3);
String polCurrency = "EUR";
Cost costOneTime = new Cost().withListUnitPrice(24.99d).withQuantityPhysical(1).withCurrency(polCurrency).withPoLineEstimatedPrice(24.99d);
PoLine poLineOneTime = new PoLine().withId(poLineId1).withPurchaseOrderId(orderId1).withCost(costOneTime).withFundDistribution(List.of(fundDistributionOneTime));
Cost costOngoing2 = new Cost().withListUnitPrice(24.99d).withQuantityPhysical(1).withCurrency(polCurrency).withPoLineEstimatedPrice(24.99d);
PoLine poLineOngoing2 = new PoLine().withId(poLineId2).withPurchaseOrderId(orderId2).withCost(costOngoing2).withFundDistribution(List.of(fundDistributionOngoing2));
Cost costOngoing3 = new Cost().withListUnitPrice(24.99d).withQuantityPhysical(1).withCurrency(polCurrency).withPoLineEstimatedPrice(24.99d);
PoLine poLineOngoing3 = new PoLine().withId(poLineId3).withPurchaseOrderId(orderId3).withCost(costOngoing3).withFundDistribution(List.of(fundDistributionOngoing3));
List<PoLine> poLines = List.of(poLineOneTime, poLineOngoing2, poLineOngoing3);
doReturn(completedFuture(funds)).when(fundService).getFundsByLedgerId(ledgerId, requestContext);
doReturn(completedFuture(purchaseOrderCollection)).when(purchaseOrderStorageService).getPurchaseOrders(anyString(), anyInt(), anyInt(), any());
doReturn(completedFuture(poLines)).when(purchaseOrderLineService).getOrderLines(anyString(), anyInt(), anyInt(), any());
doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLines(eq(poLines), any());
Encumbrance encumbranceOneTime = new Encumbrance().withSourcePurchaseOrderId(orderId1).withSourcePoLineId(poLineId1).withOrderType(Encumbrance.OrderType.ONE_TIME).withInitialAmountEncumbered(30.16d);
Transaction transactionOneTime = new Transaction().withId(currEncumbrId1).withFromFundId(fundId1).withEncumbrance(encumbranceOneTime);
Encumbrance encumbranceOngoing2 = new Encumbrance().withSourcePurchaseOrderId(orderId2).withSourcePoLineId(poLineId2).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(30.16d);
Transaction transactionOngoing2 = new Transaction().withId(currEncumbrId2).withFromFundId(fundId2).withEncumbrance(encumbranceOngoing2).withExpenseClassId(expClassId2);
Encumbrance encumbranceOngoing3 = new Encumbrance().withSourcePurchaseOrderId(orderId3).withSourcePoLineId(poLineId3).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(30.16d);
Transaction transactionOngoing3 = new Transaction().withId(currEncumbrId3).withFromFundId(fundId3).withEncumbrance(encumbranceOngoing3).withExpenseClassId(expClassId3);
List<Transaction> encumbrances = List.of(transactionOneTime, transactionOngoing2, transactionOngoing3);
TransactionCollection encumbranceCollection = new TransactionCollection().withTransactions(encumbrances).withTotalRecords(3);
doReturn(completedFuture(encumbranceCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), any());
double exchangeEurToUsdRate = 0.82858d;
doReturn(completedFuture(systemCurrency)).when(configurationEntriesService).getSystemCurrency(requestContext);
ConversionQuery actQuery = ConversionQueryBuilder.of().setBaseCurrency(polCurrency).setTermCurrency(systemCurrency).set(RATE_KEY, exchangeEurToUsdRate).build();
ExchangeRateProvider exchangeRateProvider = Mockito.mock(ManualExchangeRateProvider.class);
ManualCurrencyConversion manualCurrencyConversion = new ManualCurrencyConversion(actQuery, exchangeRateProvider, ConversionContext.of());
ExchangeRate exchangeRate = mock(ExchangeRate.class);
doReturn(exchangeRateProvider).when(exchangeRateProviderResolver).resolve(any(ConversionQuery.class), eq(requestContext));
doReturn(manualCurrencyConversion).when(exchangeRateProvider).getCurrencyConversion(any(ConversionQuery.class));
doReturn(exchangeRate).when(exchangeRateProvider).getExchangeRate(any(ConversionQuery.class));
when(exchangeRate.getContext()).thenReturn(ConversionContext.of());
when(exchangeRate.getCurrency()).thenReturn(Monetary.getCurrency(systemCurrency));
when(exchangeRate.getBaseCurrency()).thenReturn(Monetary.getCurrency(polCurrency));
when(exchangeRate.getFactor()).thenReturn(new DefaultNumberValue(exchangeEurToUsdRate));
CompletableFuture<Void> future = orderRolloverService.rollover(ledgerFiscalYearRollover, requestContext);
future.join();
assertFalse(future.isCompletedExceptionally());
assertThat(fundDistributionOneTime.getEncumbrance(), equalTo(currEncumbrId1));
assertThat(fundDistributionOngoing2.getEncumbrance(), equalTo(currEncumbrId2));
assertThat(fundDistributionOngoing3.getEncumbrance(), equalTo(currEncumbrId3));
assertThat(new BigDecimal(costOneTime.getPoLineEstimatedPrice()).setScale(2, RoundingMode.HALF_EVEN), equalTo(new BigDecimal(24.99d).setScale(2, RoundingMode.HALF_EVEN)));
assertThat(new BigDecimal(costOngoing2.getPoLineEstimatedPrice()).setScale(2, RoundingMode.HALF_EVEN), equalTo(new BigDecimal(24.99d).setScale(2, RoundingMode.HALF_EVEN)));
assertThat(new BigDecimal(costOngoing3.getPoLineEstimatedPrice()).setScale(2, RoundingMode.HALF_EVEN), equalTo(new BigDecimal(24.99d).setScale(2, RoundingMode.HALF_EVEN)));
assertThat(costOneTime.getFyroAdjustmentAmount(), equalTo(0.0d));
assertThat(costOngoing2.getFyroAdjustmentAmount(), equalTo(0.0d));
assertThat(costOngoing3.getFyroAdjustmentAmount(), equalTo(0.0d));
}
Aggregations