use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class CheckinReceivingApiTest method testPostCheckinMultipleTitlesError.
@Test
void testPostCheckinMultipleTitlesError() {
logger.info("=== Test POST check-in multiple titles error for non-packages ===");
CompositePurchaseOrder order = getMinimalContentCompositePurchaseOrder();
CompositePoLine poLine = getMinimalContentCompositePoLine(order.getId());
poLine.setOrderFormat(CompositePoLine.OrderFormat.P_E_MIX);
poLine.setEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING_ITEM));
poLine.setPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM));
String locationForPhysical = UUID.randomUUID().toString();
String locationForElectronic = UUID.randomUUID().toString();
String titleIdForPhysical = UUID.randomUUID().toString();
MockServer.addMockTitleWithId(poLine, titleIdForPhysical);
String titleIdForElectronic = UUID.randomUUID().toString();
MockServer.addMockTitleWithId(poLine, titleIdForElectronic);
Piece physicalPiece = getMinimalContentPiece(poLine.getId()).withReceivingStatus(Piece.ReceivingStatus.EXPECTED).withFormat(org.folio.rest.jaxrs.model.Piece.Format.PHYSICAL).withLocationId(locationForPhysical).withId(UUID.randomUUID().toString()).withTitleId(titleIdForPhysical).withItemId(UUID.randomUUID().toString());
Piece electronicPiece = getMinimalContentPiece(poLine.getId()).withReceivingStatus(Piece.ReceivingStatus.EXPECTED).withFormat(org.folio.rest.jaxrs.model.Piece.Format.ELECTRONIC).withId(UUID.randomUUID().toString()).withTitleId(titleIdForElectronic).withItemId(UUID.randomUUID().toString());
addMockEntry(PURCHASE_ORDER_STORAGE, order.withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN));
addMockEntry(PO_LINES_STORAGE, poLine);
addMockEntry(PIECES_STORAGE, physicalPiece);
addMockEntry(PIECES_STORAGE, electronicPiece);
List<ToBeCheckedIn> toBeCheckedInList = new ArrayList<>();
toBeCheckedInList.add(new ToBeCheckedIn().withCheckedIn(2).withPoLineId(poLine.getId()).withCheckInPieces(Arrays.asList(new CheckInPiece().withItemStatus(CheckInPiece.ItemStatus.ON_ORDER), new CheckInPiece().withItemStatus(CheckInPiece.ItemStatus.ON_ORDER))));
CheckinCollection request = new CheckinCollection().withToBeCheckedIn(toBeCheckedInList).withTotalRecords(2);
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setId(physicalPiece.getId());
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setLocationId(locationForPhysical);
request.getToBeCheckedIn().get(0).getCheckInPieces().get(1).setId(electronicPiece.getId());
request.getToBeCheckedIn().get(0).getCheckInPieces().get(1).setLocationId(locationForElectronic);
Response response = verifyPostResponse(ORDERS_CHECKIN_ENDPOINT, JsonObject.mapFrom(request).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, HttpStatus.HTTP_BAD_REQUEST.toInt());
assertThat(response.as(Errors.class).getErrors().get(0).getMessage(), is(MULTIPLE_NONPACKAGE_TITLES.getDescription()));
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class CompositePoLineValidationUtilTest method shouldReturnErrorIfLocationAndHoldingReferenceAreNotPresentInTheLocation.
@Test
@DisplayName("Should return error if location and holding reference are not present in the location")
void shouldReturnErrorIfLocationAndHoldingReferenceAreNotPresentInTheLocation() {
Location location1 = new Location().withQuantity(1).withQuantityPhysical(1);
Location location2 = new Location().withQuantity(1).withQuantityPhysical(1);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM);
Cost cost = new Cost().withQuantityPhysical(2);
CompositePoLine compositePoLine = new CompositePoLine().withPhysical(physical).withCost(cost).withLocations(List.of(location1, location2));
List<Error> errors = CompositePoLineValidationUtil.validateLocations(compositePoLine);
assertEquals(2, errors.size());
errors.forEach(error -> {
assertEquals(ErrorCodes.HOLDINGS_ID_AND_LOCATION_ID_IS_NULL_ERROR.getCode(), error.getCode());
});
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class OpenCompositeOrderPieceServiceTest method shouldCreatePieceWithLocationReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces.
@ParameterizedTest
@CsvSource(value = { "P/E Mix:Instance:None:2:3", "P/E Mix:None:Instance:2:3", "P/E Mix:None:None:2:3", "P/E Mix:Instance:Instance:2:3" }, delimiter = ':')
void shouldCreatePieceWithLocationReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces(String lineType, String elecCreateInventory, String physCreateInventory, int elecQty1, int physQty2) {
// given
String lineId = UUID.randomUUID().toString();
String locationId1 = UUID.randomUUID().toString();
String locationId2 = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
Location location1 = new Location().withLocationId(locationId1).withQuantityElectronic(elecQty1).withQuantity(elecQty1);
Location location2 = new Location().withLocationId(locationId2).withQuantityPhysical(physQty2).withQuantity(physQty2);
Cost cost = new Cost().withQuantityElectronic(elecQty1 + physQty2);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(elecCreateInventory));
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.fromValue(physCreateInventory));
CompositePoLine line = new CompositePoLine().withId(lineId).withCost(cost).withLocations(List.of(location1, location2)).withIsPackage(false).withEresource(eresource).withPhysical(physical).withOrderFormat(CompositePoLine.OrderFormat.fromValue(lineType));
CompositePurchaseOrder compOrder = new CompositePurchaseOrder().withCompositePoLines(List.of(line));
doReturn(completedFuture(null)).when(openCompositeOrderPieceService).openOrderUpdateInventory(any(CompositePoLine.class), any(Piece.class), any(Boolean.class), eq(requestContext));
doReturn(completedFuture(Collections.emptyList())).when(pieceStorageService).getPiecesByPoLineId(line, requestContext);
doReturn(completedFuture(new Piece())).when(pieceStorageService).insertPiece(any(Piece.class), eq(requestContext));
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(compOrder)).when(purchaseOrderStorageService).getCompositeOrderByPoLineId(eq(lineId), eq(requestContext));
final ArgumentCaptor<Piece> pieceArgumentCaptor = ArgumentCaptor.forClass(Piece.class);
doAnswer((Answer<CompletableFuture<Piece>>) invocation -> {
Piece piece = invocation.getArgument(0);
return completedFuture(piece);
}).when(pieceStorageService).insertPiece(pieceArgumentCaptor.capture(), eq(requestContext));
// When
List<Piece> createdPieces = openCompositeOrderPieceService.handlePieces(line, titleId, Collections.emptyList(), false, requestContext).join();
// Then
List<Piece> piecesLoc1 = createdPieces.stream().filter(piece -> piece.getLocationId().equals(locationId1)).collect(toList());
assertEquals(elecQty1, piecesLoc1.size());
piecesLoc1.forEach(piece -> {
assertNull(piece.getHoldingId());
assertNull(piece.getItemId());
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
assertEquals(Piece.Format.ELECTRONIC, piece.getFormat());
});
List<Piece> piecesLoc2 = createdPieces.stream().filter(piece -> piece.getLocationId().equals(locationId2)).collect(toList());
assertEquals(physQty2, piecesLoc2.size());
piecesLoc2.forEach(piece -> {
assertNull(piece.getHoldingId());
assertNull(piece.getItemId());
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
assertEquals(Piece.Format.PHYSICAL, piece.getFormat());
});
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class OpenCompositeOrderPieceServiceTest method shouldCreatePieceWithLocationReferenceIfLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces.
@ParameterizedTest
@CsvSource(value = { "Physical Resource:Instance:2:3:Physical", "Physical Resource:None:2:3:Physical", "Other:Instance:2:3:Other", "Other:None:2:3:Other" }, delimiter = ':')
void shouldCreatePieceWithLocationReferenceIfLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces(String lineType, String createInventory, int qty1, int qty2, String pieceFormat) {
// given
String lineId = UUID.randomUUID().toString();
String locationId1 = UUID.randomUUID().toString();
String locationId2 = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
Location location1 = new Location().withLocationId(locationId1).withQuantityPhysical(qty1).withQuantity(qty1);
Location location2 = new Location().withLocationId(locationId2).withQuantityPhysical(qty2).withQuantity(qty2);
Cost cost = new Cost().withQuantityPhysical(qty1 + qty2).withQuantityElectronic(null);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.fromValue(createInventory));
CompositePoLine line = new CompositePoLine().withId(lineId).withCost(cost).withLocations(List.of(location1, location2)).withIsPackage(false).withPhysical(physical).withOrderFormat(CompositePoLine.OrderFormat.fromValue(lineType));
CompositePurchaseOrder compOrder = new CompositePurchaseOrder().withCompositePoLines(List.of(line));
doReturn(completedFuture(null)).when(openCompositeOrderPieceService).openOrderUpdateInventory(any(CompositePoLine.class), any(Piece.class), any(Boolean.class), eq(requestContext));
doReturn(completedFuture(Collections.emptyList())).when(pieceStorageService).getPiecesByPoLineId(line, requestContext);
doReturn(completedFuture(new Piece())).when(pieceStorageService).insertPiece(any(Piece.class), eq(requestContext));
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(compOrder)).when(purchaseOrderStorageService).getCompositeOrderByPoLineId(eq(lineId), eq(requestContext));
final ArgumentCaptor<Piece> pieceArgumentCaptor = ArgumentCaptor.forClass(Piece.class);
doAnswer((Answer<CompletableFuture<Piece>>) invocation -> {
Piece piece = invocation.getArgument(0);
return completedFuture(piece);
}).when(pieceStorageService).insertPiece(pieceArgumentCaptor.capture(), eq(requestContext));
// When
List<Piece> createdPieces = openCompositeOrderPieceService.handlePieces(line, titleId, Collections.emptyList(), false, requestContext).join();
// Then
List<Piece> piecesLoc1 = createdPieces.stream().filter(piece -> piece.getLocationId().equals(locationId1)).collect(toList());
assertEquals(qty1, piecesLoc1.size());
piecesLoc1.forEach(piece -> {
assertNull(piece.getHoldingId());
assertNull(piece.getItemId());
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
assertEquals(Piece.Format.fromValue(pieceFormat), piece.getFormat());
});
List<Piece> piecesLoc2 = createdPieces.stream().filter(piece -> piece.getLocationId().equals(locationId2)).collect(toList());
assertEquals(qty2, piecesLoc2.size());
piecesLoc2.forEach(piece -> {
assertNull(piece.getHoldingId());
assertNull(piece.getItemId());
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
assertEquals(Piece.Format.fromValue(pieceFormat), piece.getFormat());
});
}
Aggregations