Skip to content

Commit

Permalink
Add testcase for holding creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Jun 6, 2024
1 parent cce489d commit e218b99
Showing 1 changed file with 61 additions and 4 deletions.
65 changes: 61 additions & 4 deletions src/test/java/org/folio/rest/impl/CheckinReceivingApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.hasValue;
import static org.hamcrest.Matchers.in;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -1004,7 +1005,8 @@ void testBindPiecesToTitleWithItem() {
var pieceIds = List.of(bindingPiece1.getId(), bindingPiece2.getId());
var bindPiecesCollection = new BindPiecesCollection()
.withPoLineId(poLine.getId())
.withBindItem(getMinimalContentBindItem())
.withBindItem(getMinimalContentBindItem()
.withHoldingId(holdingId))
.withBindPieceIds(pieceIds);

var response = verifyPostResponse(ORDERS_BIND_ENDPOINT, JsonObject.mapFrom(bindPiecesCollection).encode(),
Expand All @@ -1031,6 +1033,58 @@ void testBindPiecesToTitleWithItem() {

}

@Test
void testBindPiecesWithLocationIdOnly() {
logger.info("=== Test POST Bind to Title With Item using locationId");

var receivingStatus = Piece.ReceivingStatus.UNRECEIVABLE;
var format = Piece.Format.ELECTRONIC;
var order = getMinimalContentCompositePurchaseOrder()
.withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
var poLine = getMinimalContentCompositePoLine(order.getId());
var bindingPiece = getMinimalContentPiece(poLine.getId())
.withReceivingStatus(receivingStatus)
.withFormat(format);

addMockEntry(PURCHASE_ORDER_STORAGE, order);
addMockEntry(PO_LINES_STORAGE, poLine);
addMockEntry(PIECES_STORAGE, bindingPiece);
addMockEntry(TITLES, getTitle(poLine));


var locationId = UUID.randomUUID().toString();
var pieceIds = List.of(bindingPiece.getId());
var bindPiecesCollection = new BindPiecesCollection()
.withPoLineId(poLine.getId())
.withBindItem(getMinimalContentBindItem()
.withLocationId(locationId))
.withBindPieceIds(pieceIds);

var response = verifyPostResponse(ORDERS_BIND_ENDPOINT, JsonObject.mapFrom(bindPiecesCollection).encode(),
prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, HttpStatus.HTTP_OK.toInt())
.as(BindPiecesResult.class);

assertThat(response.getPoLineId(), is(poLine.getId()));
assertThat(response.getBoundPieceIds(), is(pieceIds));
assertThat(response.getItemId(), notNullValue());

var pieceUpdates = getPieceUpdates();
assertThat(pieceUpdates, notNullValue());
assertThat(pieceUpdates, hasSize(bindPiecesCollection.getBindPieceIds().size()));

var pieceList = pieceUpdates.stream().filter(pol -> {
Piece piece = pol.mapTo(Piece.class);
String pieceId = piece.getId();
return Objects.equals(bindingPiece.getId(), pieceId);
}).toList();
assertThat(pieceList.size(), is(2));

var createdHoldings = getCreatedHoldings();
assertThat(createdHoldings, notNullValue());
assertThat(createdHoldings, hasSize(1));
assertThat(createdHoldings.get(0).getString(HOLDING_PERMANENT_LOCATION_ID), is(locationId));
}

@Test
void testBindPiecesToTitleWithItemWithOutstandingRequest() {
logger.info("=== Test POST Bind to Title with Item with Outstanding Request");
Expand All @@ -1046,7 +1100,8 @@ void testBindPiecesToTitleWithItemWithOutstandingRequest() {
.withFormat(org.folio.rest.jaxrs.model.Piece.Format.ELECTRONIC);
var bindPiecesCollection = new BindPiecesCollection()
.withPoLineId(poLine.getId())
.withBindItem(getMinimalContentBindItem())
.withBindItem(getMinimalContentBindItem()
.withHoldingId(UUID.randomUUID().toString()))
.withBindPieceIds(List.of(bindingPiece.getId()));

addMockEntry(PURCHASE_ORDER_STORAGE, order);
Expand Down Expand Up @@ -1078,7 +1133,8 @@ void testBindPiecesToTitleWithBindItemWithDifferentTenantId() {
var bindPiecesCollection = new BindPiecesCollection()
.withPoLineId(poLine.getId())
.withBindItem(getMinimalContentBindItem()
.withTenantId("differentTenantId"))
.withTenantId("differentTenantId")
.withHoldingId(UUID.randomUUID().toString()))
.withBindPieceIds(List.of(bindingPiece.getId()))
.withRequestsAction(BindPiecesCollection.RequestsAction.TRANSFER);

Expand Down Expand Up @@ -1110,7 +1166,8 @@ void testBindPiecesToTitleWithTransferRequestsAction() {
.withFormat(org.folio.rest.jaxrs.model.Piece.Format.ELECTRONIC);
var bindPiecesCollection = new BindPiecesCollection()
.withPoLineId(poLine.getId())
.withBindItem(getMinimalContentBindItem())
.withBindItem(getMinimalContentBindItem()
.withHoldingId(UUID.randomUUID().toString()))
.withBindPieceIds(List.of(bindingPiece.getId()))
.withRequestsAction(BindPiecesCollection.RequestsAction.TRANSFER);

Expand Down

0 comments on commit e218b99

Please sign in to comment.