use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method cannotRemoveHRIDAfterCreation.
@Test
public void cannotRemoveHRIDAfterCreation() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
log.info("Starting cannotRemoveHRIDAfterCreation");
final UUID instanceId = UUID.randomUUID();
final UUID holdingsId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
setHoldingsSequence(1);
final JsonObject holdings = holdingsClient.create(new HoldingRequestBuilder().withId(holdingsId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getJson();
assertThat(holdings.getString("hrid"), is("ho00000000001"));
holdings.remove("hrid");
final CompletableFuture<Response> updateCompleted = new CompletableFuture<>();
client.put(holdingsStorageUrl(String.format("/%s", holdingsId)), holdings, TENANT_ID, text(updateCompleted));
final Response response = updateCompleted.get(5, TimeUnit.SECONDS);
assertThat(response.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
assertThat(response.getBody(), is("The hrid field cannot be changed: new=null, old=ho00000000001"));
log.info("Finished cannotRemoveHRIDAfterCreation");
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method tenantIsRequiredForCreatingANewHolding.
@Test
public void tenantIsRequiredForCreatingANewHolding() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
JsonObject request = new HoldingRequestBuilder().forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).create();
CompletableFuture<Response> postCompleted = new CompletableFuture<>();
client.post(holdingsStorageUrl(""), request, null, ResponseHandler.any(postCompleted));
Response response = postCompleted.get(5, TimeUnit.SECONDS);
assertThat(response.getStatusCode(), is(400));
assertThat(response.getBody(), is("Unable to process request Tenant must be set"));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method updatingOrRemovingTemporaryLocationChangesEffectiveLocation.
@Test
public void updatingOrRemovingTemporaryLocationChangesEffectiveLocation() throws InterruptedException, ExecutionException, TimeoutException {
UUID instanceId = UUID.randomUUID();
UUID holdingId = UUID.randomUUID();
URL holdingsUrl = holdingsStorageUrl(String.format("/%s", holdingId));
instancesClient.create(smallAngryPlanet(instanceId));
setHoldingsSequence(1);
JsonObject holding = holdingsClient.create(new HoldingRequestBuilder().withId(holdingId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getJson();
assertThat(holding.getString("effectiveLocationId"), is(mainLibraryLocationId.toString()));
holding.put("temporaryLocationId", annexLibraryLocationId.toString());
update(holdingsUrl, holding);
holding = holdingsClient.getById(holdingId).getJson();
assertThat(holding.getString("effectiveLocationId"), is(annexLibraryLocationId.toString()));
holding.put("temporaryLocationId", secondFloorLocationId.toString());
update(holdingsUrl, holding);
holding = holdingsClient.getById(holdingId).getJson();
assertThat(holding.getString("effectiveLocationId"), is(secondFloorLocationId.toString()));
holding.remove("temporaryLocationId");
update(holdingsUrl, holding);
holding = holdingsClient.getById(holdingId).getJson();
assertThat(holding.getString("effectiveLocationId"), is(mainLibraryLocationId.toString()));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method canPageAllHoldings.
@Test
public void canPageAllHoldings() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID firstInstanceId = UUID.randomUUID();
UUID secondInstanceId = UUID.randomUUID();
UUID thirdInstanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(firstInstanceId));
instancesClient.create(nod(secondInstanceId));
instancesClient.create(uprooted(thirdInstanceId));
UUID firstHoldingId = holdingsClient.create(new HoldingRequestBuilder().forInstance(firstInstanceId).withPermanentLocation(mainLibraryLocationId)).getId();
UUID secondHoldingId = holdingsClient.create(new HoldingRequestBuilder().forInstance(secondInstanceId).withPermanentLocation(annexLibraryLocationId)).getId();
UUID thirdHoldingId = holdingsClient.create(new HoldingRequestBuilder().forInstance(thirdInstanceId).withPermanentLocation(mainLibraryLocationId)).getId();
UUID fourthHoldingId = holdingsClient.create(new HoldingRequestBuilder().forInstance(secondInstanceId).withPermanentLocation(mainLibraryLocationId)).getId();
UUID fifthHoldingId = holdingsClient.create(new HoldingRequestBuilder().forInstance(firstInstanceId).withPermanentLocation(annexLibraryLocationId)).getId();
CompletableFuture<Response> firstPageCompleted = new CompletableFuture<>();
CompletableFuture<Response> secondPageCompleted = new CompletableFuture<>();
client.get(holdingsStorageUrl("") + "?limit=3", StorageTestSuite.TENANT_ID, ResponseHandler.json(firstPageCompleted));
client.get(holdingsStorageUrl("") + "?limit=3&offset=3", StorageTestSuite.TENANT_ID, ResponseHandler.json(secondPageCompleted));
Response firstPageResponse = firstPageCompleted.get(5, TimeUnit.SECONDS);
Response secondPageResponse = secondPageCompleted.get(5, TimeUnit.SECONDS);
assertThat(firstPageResponse.getStatusCode(), is(200));
assertThat(secondPageResponse.getStatusCode(), is(200));
JsonObject firstPage = firstPageResponse.getJson();
JsonObject secondPage = secondPageResponse.getJson();
List<JsonObject> firstPageHoldings = JsonArrayHelper.toList(firstPage.getJsonArray("holdingsRecords"));
List<JsonObject> secondPageHoldings = JsonArrayHelper.toList(secondPage.getJsonArray("holdingsRecords"));
assertThat(firstPageHoldings.size(), is(3));
assertThat(firstPage.getInteger("totalRecords"), is(5));
assertThat(secondPageHoldings.size(), is(2));
assertThat(secondPage.getInteger("totalRecords"), is(5));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method removingHoldingsCallNumberPrefixUpdatesItemEffectiveCallNumberPrefix.
@Test
public void removingHoldingsCallNumberPrefixUpdatesItemEffectiveCallNumberPrefix() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
UUID holdingId = UUID.randomUUID();
JsonObject holding = holdingsClient.create(new HoldingRequestBuilder().withId(holdingId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withCallNumberPrefix("testCallNumberPrefix").withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getJson();
JsonObject itemToCreate = new JsonObject();
itemToCreate.put("holdingsRecordId", holdingId.toString());
itemToCreate.put("status", new JsonObject().put("name", "Available"));
itemToCreate.put("permanentLoanTypeId", canCirculateLoanTypeID);
itemToCreate.put("temporaryLocationId", annexLibraryLocationId.toString());
itemToCreate.put("materialTypeId", bookMaterialTypeID);
Response postFirstItemResponse = create(itemsStorageUrl(""), itemToCreate);
assertThat(postFirstItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
JsonObject firstItemFromPost = postFirstItemResponse.getJson();
String firstItemId = firstItemFromPost.getString("id");
assertThat(firstItemId, is(notNullValue()));
URL getFirstItemUrl = itemsStorageUrl(String.format("/%s", firstItemId));
Response getFirstItemResponse = get(getFirstItemUrl);
JsonObject firstItemFromGet = getFirstItemResponse.getJson();
assertThat(firstItemFromGet.getString("id"), is(firstItemId));
assertThat(firstItemFromGet.getString("holdingsRecordId"), is(holdingId.toString()));
assertThat(firstItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("testCallNumberPrefix"));
URL holdingsUrl = holdingsStorageUrl(String.format("/%s", holdingId));
holding.remove("callNumberPrefix");
Response putResponse = update(holdingsUrl, holding);
assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
assertThat(holding.containsKey("callNumberPrefix"), is(false));
Response getFirstUpdatedItemResponse = get(getFirstItemUrl);
JsonObject firstUpdatedItemFromGet = getFirstUpdatedItemResponse.getJson();
assertThat(getFirstUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
assertThat(firstUpdatedItemFromGet.getString("id"), is(firstItemId));
assertThat(firstUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").containsKey("prefix"), is(false));
}
Aggregations