use of org.folio.rest.impl.MockServer.ENCUMBRANCE_PATH in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPutOrdersByIdPEMixFormat.
@Test
@Disabled
// TODO must be fixed in scoupe of https://issues.folio.org/browse/MODORDERS-587
void testPutOrdersByIdPEMixFormat() {
logger.info("=== Test Put Order By Id create Pieces with P/E Mix format ===");
CompositePurchaseOrder reqData = getMockAsJson(PE_MIX_PATH).mapTo(CompositePurchaseOrder.class);
reqData.setId(ID_FOR_PRINT_MONOGRAPH_ORDER);
reqData.setReEncumber(null);
// Make sure that mock PO has 1 po line
assertThat(reqData.getCompositePoLines(), hasSize(1));
reqData.setManualPo(false);
CompositePoLine compositePoLine = reqData.getCompositePoLines().get(0);
compositePoLine.setId(PO_LINE_ID_FOR_SUCCESS_CASE);
compositePoLine.getEresource().setCreateInventory(Eresource.CreateInventory.NONE);
compositePoLine.setPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM).withMaterialType("4b93736c-8731-46cd-9d6e-f9dce0f63bcd"));
compositePoLine.getCost().setQuantityPhysical(3);
compositePoLine.getCost().setQuantityElectronic(2);
compositePoLine.setOrderFormat(OrderFormat.P_E_MIX);
Transaction encumbrance = getMockAsJson(ENCUMBRANCE_PATH).getJsonArray("transactions").getJsonObject(0).mapTo(Transaction.class);
compositePoLine.getFundDistribution().get(0).setEncumbrance(encumbrance.getId());
compositePoLine.getFundDistribution().get(0).setFundId(encumbrance.getFromFundId());
encumbrance.getEncumbrance().setSourcePoLineId(compositePoLine.getId());
encumbrance.getEncumbrance().setSourcePurchaseOrderId(compositePoLine.getPurchaseOrderId());
compositePoLine.getLocations().stream().filter(location -> ObjectUtils.defaultIfNull(location.getQuantityPhysical(), 0) > 0).forEach(location -> location.setQuantityElectronic(null));
// MODORDERS-243
removeAllEncumbranceLinks(reqData);
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
preparePiecesForCompositePo(reqData);
verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData), "", 204);
List<JsonObject> respOrder = MockServer.serverRqRs.get(PURCHASE_ORDER_STORAGE, HttpMethod.PUT);
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(compositePoLine.getId())).peek(line -> line.remove("reportingCodes")).map(line -> line.mapTo(CompositePoLine.class)).filter(line -> line.getLocations().stream().filter(loc -> Objects.nonNull(loc.getHoldingId())).findFirst().isPresent()).distinct().findAny().get();
compPo.setCompositePoLines(List.of(respLine1));
List<JsonObject> createdPieces = getCreatedPieces();
List<JsonObject> createdItems = getCreatedItems();
assertThat(createdItems, notNullValue());
assertThat(createdPieces, notNullValue());
int piecesSize = createdPieces.size();
logger.debug("------------------- piecesSize, itemSize --------------------\n" + piecesSize + " " + createdItems.size());
// Verify total number of pieces created should be equal to total quantity
assertEquals(calculateTotalQuantity(respLine1), piecesSize);
verifyOpenOrderPiecesCreated(createdItems, compPo.getCompositePoLines(), createdPieces, 0);
verifyEncumbrancesOnPoUpdate(compPo);
assertTrue(getExistingOrderSummaries().size() > 0);
}
Aggregations