use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class ReOpenCompositeOrderManagerTest method shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveSameStatuses.
@ParameterizedTest
@CsvSource(value = { "Open:Expected:Awaiting Receipt:Awaiting Payment", "Approved:Received:Partially Received:Partially Paid", "Paid:Received:Partially Received:Partially Paid" }, delimiter = ':')
void shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveSameStatuses(String invoiceStatus, String pieceStatus, String expReceiptStatus, String expPaymentStatus) throws ExecutionException, InterruptedException {
CompositePurchaseOrder oldOrder = getMockAsJson(ORDER_PATH).mapTo(CompositePurchaseOrder.class);
CompositePoLine poLine1 = oldOrder.getCompositePoLines().get(0);
String poLineId1 = poLine1.getId();
String encumbrance1Id = poLine1.getFundDistribution().get(0).getEncumbrance();
CompositePoLine poLine2 = JsonObject.mapFrom(poLine1).mapTo(CompositePoLine.class);
String poLineId2 = UUID.randomUUID().toString();
String encumbrance2Id = UUID.randomUUID().toString();
String oldInstance2 = UUID.randomUUID().toString();
poLine2.setId(poLineId2);
poLine2.getFundDistribution().get(0).setEncumbrance(encumbrance2Id);
poLine2.setInstanceId(oldInstance2);
oldOrder.setCompositePoLines(List.of(poLine1, poLine2));
CompositePurchaseOrder newOrder = JsonObject.mapFrom(oldOrder).mapTo(CompositePurchaseOrder.class);
newOrder.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.CLOSED);
String invoiceId1 = UUID.randomUUID().toString();
Invoice invoice1 = new Invoice().withId(invoiceId1).withStatus(Invoice.Status.fromValue(invoiceStatus));
String invoiceId2 = UUID.randomUUID().toString();
Invoice invoice2 = new Invoice().withId(invoiceId2).withStatus(Invoice.Status.fromValue(invoiceStatus));
InvoiceLine invoiceLine1 = new InvoiceLine().withId(UUID.randomUUID().toString()).withInvoiceId(invoice1.getId()).withPoLineId(poLineId1).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance1Id)));
InvoiceLine invoiceLine2 = new InvoiceLine().withId(UUID.randomUUID().toString()).withInvoiceId(invoice2.getId()).withPoLineId(poLineId2).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)));
List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2);
List<Invoice> invoices = List.of(invoice1, invoice2);
Piece piece1 = new Piece().withFormat(Piece.Format.PHYSICAL).withReceivingStatus(Piece.ReceivingStatus.fromValue(pieceStatus)).withPoLineId(poLineId1).withLocationId(UUID.randomUUID().toString()).withHoldingId(UUID.randomUUID().toString());
Piece piece2 = new Piece().withFormat(Piece.Format.PHYSICAL).withReceivingStatus(Piece.ReceivingStatus.fromValue(pieceStatus)).withPoLineId(poLineId2).withLocationId(UUID.randomUUID().toString()).withHoldingId(UUID.randomUUID().toString());
doReturn(closedToOpenEncumbranceStrategy).when(encumbranceWorkflowStrategyFactory).getStrategy(eq(OrderWorkflowType.CLOSED_TO_OPEN));
doReturn(completedFuture(null)).when(closedToOpenEncumbranceStrategy).processEncumbrances(eq(newOrder), eq(oldOrder), eq(requestContext));
doReturn(completedFuture(invoiceLines)).when(invoiceLineService).getInvoiceLinesByOrderLineIds(List.of(poLineId1, poLineId2), requestContext);
doReturn(completedFuture(invoices)).when(invoiceService).getInvoicesByOrderId(oldOrder.getId(), requestContext);
doReturn(completedFuture(List.of(piece1, piece2))).when(pieceStorageService).getPiecesByLineIdsByChunks(List.of(poLineId1, poLineId2), requestContext);
reOpenCompositeOrderManager.process(newOrder, oldOrder, requestContext).get();
assertEquals(CompositePoLine.ReceiptStatus.fromValue(expReceiptStatus), newOrder.getCompositePoLines().get(0).getReceiptStatus());
assertEquals(CompositePoLine.PaymentStatus.fromValue(expPaymentStatus), newOrder.getCompositePoLines().get(0).getPaymentStatus());
assertEquals(CompositePoLine.ReceiptStatus.fromValue(expReceiptStatus), newOrder.getCompositePoLines().get(1).getReceiptStatus());
assertEquals(CompositePoLine.PaymentStatus.fromValue(expPaymentStatus), newOrder.getCompositePoLines().get(1).getPaymentStatus());
}
use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class PieceStorageServiceTest method testPiecesShouldBeReturnedByQuery.
@Test
void testPiecesShouldBeReturnedByQuery() {
String pieceId = UUID.randomUUID().toString();
List<Piece> pieces = Collections.singletonList(new Piece().withId(pieceId));
PieceCollection pieceCollection = new PieceCollection().withPieces(pieces).withTotalRecords(1);
when(restClientMock.get(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(pieceCollection));
String expectedQuery = String.format("id==%s", pieceId);
PieceCollection retrievedPieces = pieceStorageService.getPieces(Integer.MAX_VALUE, 0, expectedQuery, requestContext).join();
verify(restClientMock).get(any(), eq(requestContext), eq(PieceCollection.class));
assertEquals(pieceCollection, retrievedPieces);
}
use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class PieceUpdateInventoryServiceTest method shouldDeleteHoldingIfHoldingIdIsProvidedAndFoundInDBAndNoPiecesAndItems.
@Test
void shouldDeleteHoldingIfHoldingIdIsProvidedAndFoundInDBAndNoPiecesAndItems() {
String holdingId = UUID.randomUUID().toString();
JsonObject holding = new JsonObject();
holding.put(ID, holding);
Piece piece = new Piece().withId(UUID.randomUUID().toString()).withHoldingId(holdingId);
doReturn(completedFuture(Collections.emptyList())).when(pieceStorageService).getPiecesByHoldingId(holdingId, requestContext);
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holdingId, true, requestContext);
doReturn(completedFuture(new ArrayList<>())).when(inventoryManager).getItemsByHoldingId(holdingId, requestContext);
pieceUpdateInventoryService.deleteHoldingConnectedToPiece(piece, requestContext);
verify(inventoryManager, times(1)).deleteHoldingById(holdingId, true, requestContext);
}
use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class DefaultPieceFlowsValidatorTest method createPieceAllowableIfCreateInventoryInTheLineAllowThatButCreateItemFlagIsFalse.
@Test
void createPieceAllowableIfCreateInventoryInTheLineAllowThatButCreateItemFlagIsFalse() {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece piece = new Piece().withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING_ITEM);
CompositePoLine originPoLine = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
defaultPieceFlowsValidator.isPieceRequestValid(piece, originPoLine, true);
}
use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class DefaultPieceFlowsValidatorTest method createPieceIsForbiddenIfCreateInventoryInTheLineDonNotAllowThat.
@Test
void createPieceIsForbiddenIfCreateInventoryInTheLineDonNotAllowThat() {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece piece = new Piece().withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING);
CompositePoLine originPoLine = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
HttpException exception = Assertions.assertThrows(HttpException.class, () -> {
defaultPieceFlowsValidator.isPieceRequestValid(piece, originPoLine, true);
});
boolean isErrorPresent = exception.getErrors().getErrors().stream().anyMatch(error -> error.getCode().equals(ErrorCodes.CREATE_ITEM_FOR_PIECE_IS_NOT_ALLOWED_ERROR.getCode()));
assertEquals(true, isErrorPresent);
}
Aggregations