use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method canUsePutToCreateAHoldingsWhenHRIDIsSupplied.
@Test
public void canUsePutToCreateAHoldingsWhenHRIDIsSupplied() {
log.info("Starting canUsePutToCreateAHoldingsWhenHRIDIsSupplied");
final UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
final UUID holdingsId = UUID.randomUUID();
final String hrid = "TEST1001";
holdingsClient.replace(holdingsId, new HoldingRequestBuilder().withId(holdingsId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withHrid(hrid).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE))));
final Response getResponse = holdingsClient.getById(holdingsId);
assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
final JsonObject holdingsFromGet = getResponse.getJson();
assertThat(holdingsFromGet.getString("hrid"), is(hrid));
// Make sure a create event published vs update event
assertCreateEventForHolding(holdingsFromGet);
assertNoUpdateEventForHolding(instanceId.toString(), holdingsId.toString());
log.info("Finished canUsePutToCreateAHoldingsWhenHRIDIsSupplied");
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method holdingsCallNumberPrefixDoesNotSupersedeItemLevelCallNumberPrefix.
@Test
public void holdingsCallNumberPrefixDoesNotSupersedeItemLevelCallNumberPrefix() throws MalformedURLException, InterruptedException, TimeoutException, ExecutionException {
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("holdingsCallNumberPrefix").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);
itemToCreate.put("itemLevelCallNumberPrefix", "itemLevelCallNumberPrefix");
Response postItemResponse = create(itemsStorageUrl(""), itemToCreate);
assertThat(postItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
JsonObject itemFromPost = postItemResponse.getJson();
String itemId = itemFromPost.getString("id");
assertThat(itemId, is(notNullValue()));
URL getItemUrl = itemsStorageUrl(String.format("/%s", itemId));
Response getItemResponse = get(getItemUrl);
JsonObject itemFromGet = getItemResponse.getJson();
assertThat(itemFromGet.getString("id"), is(itemId));
assertThat(itemFromGet.getString("holdingsRecordId"), is(holdingId.toString()));
assertThat(itemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("itemLevelCallNumberPrefix"));
URL holdingsUrl = holdingsStorageUrl(String.format("/%s", holdingId));
holding.remove("callNumberPrefix");
holding.put("callNumberPrefix", "updatedHoldingCallNumberPrefix");
Response putResponse = update(holdingsUrl, holding);
assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
Response getUpdatedItemResponse = get(getItemUrl);
JsonObject updatedItemFromGet = getUpdatedItemResponse.getJson();
assertThat(getUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
assertThat(updatedItemFromGet.getString("id"), is(itemId));
assertThat(updatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("itemLevelCallNumberPrefix"));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method canSetHoldingStatementWithNotes.
@Test
public void canSetHoldingStatementWithNotes() throws Exception {
UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
UUID holdingId = UUID.randomUUID();
JsonObject holdingsStatement = new JsonObject();
holdingsStatement.put("statement", "Test statement");
holdingsStatement.put("note", "Test note");
holdingsStatement.put("staffNote", "Test staff note");
JsonArray holdingsStatements = new JsonArray().add(holdingsStatement);
IndividualResource holdingResponse = holdingsClient.create(new HoldingRequestBuilder().withId(holdingId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE))).withHoldingsStatements(holdingsStatements));
JsonObject holding = holdingResponse.getJson();
assertThat(holding.getString("instanceId"), is(instanceId.toString()));
assertThat(holding.getString("permanentLocationId"), is(mainLibraryLocationId.toString()));
JsonObject responseStatement = holding.getJsonArray("holdingsStatements").getJsonObject(0);
assertThat(responseStatement.getString("statement"), is("Test statement"));
assertThat(responseStatement.getString("note"), is("Test note"));
assertThat(responseStatement.getString("staffNote"), is("Test staff note"));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method updatingHoldingsUpdatesItemEffectiveCallNumber.
@Test
public void updatingHoldingsUpdatesItemEffectiveCallNumber() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
UUID holdingId = UUID.randomUUID();
JsonObject holding = holdingsClient.create(new HoldingRequestBuilder().withId(holdingId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withCallNumber("testCallNumber").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);
Response postSecondItemResponse = create(itemsStorageUrl(""), itemToCreate);
assertThat(postFirstItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
assertThat(postSecondItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
JsonObject firstItem = postFirstItemResponse.getJson();
JsonObject secondItem = postSecondItemResponse.getJson();
String firstItemId = firstItem.getString("id");
String secondItemId = secondItem.getString("id");
assertThat(firstItemId, is(notNullValue()));
assertThat(secondItemId, is(notNullValue()));
URL getFirstItemUrl = itemsStorageUrl(String.format("/%s", firstItemId));
URL getSecondItemUrl = itemsStorageUrl(String.format("/%s", secondItemId));
Response getFirstItemResponse = get(getFirstItemUrl);
Response getSecondItemResponse = get(getSecondItemUrl);
JsonObject firstItemFromGet = getFirstItemResponse.getJson();
JsonObject secondItemFromGet = getSecondItemResponse.getJson();
assertThat(firstItemFromGet.getString("id"), is(firstItemId));
assertThat(firstItemFromGet.getString("holdingsRecordId"), is(holdingId.toString()));
assertThat(firstItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("callNumber"), is("testCallNumber"));
assertThat(secondItemFromGet.getString("id"), is(secondItemId));
assertThat(secondItemFromGet.getString("holdingsRecordId"), is(holdingId.toString()));
assertThat(secondItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("callNumber"), is("testCallNumber"));
URL holdingsUrl = holdingsStorageUrl(String.format("/%s", holdingId));
holding.put("callNumber", "updatedCallNumber");
Response putResponse = update(holdingsUrl, holding);
assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
assertThat(holding.getString("callNumber"), is("updatedCallNumber"));
Response getFirstUpdatedItemResponse = get(getFirstItemUrl);
Response getSecondUpdatedItemResponse = get(getSecondItemUrl);
JsonObject firstUpdatedItemFromGet = getFirstUpdatedItemResponse.getJson();
JsonObject secondUpdatedItemFromGet = getSecondUpdatedItemResponse.getJson();
assertThat(getFirstUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
assertThat(firstUpdatedItemFromGet.getString("id"), is(firstItemId));
assertThat(firstUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("callNumber"), is("updatedCallNumber"));
assertThat(getSecondUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
assertThat(secondUpdatedItemFromGet.getString("id"), is(secondItemId));
assertThat(secondUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("callNumber"), is("updatedCallNumber"));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method holdingsCallNumberSuffixDoesNotSupersedeItemLevelCallNumberSuffix.
@Test
public void holdingsCallNumberSuffixDoesNotSupersedeItemLevelCallNumberSuffix() throws MalformedURLException, InterruptedException, TimeoutException, ExecutionException {
UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
UUID holdingId = UUID.randomUUID();
JsonObject holding = holdingsClient.create(new HoldingRequestBuilder().withId(holdingId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withCallNumberSuffix("holdingsCallNumberSuffix").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);
itemToCreate.put("itemLevelCallNumberSuffix", "itemLevelCallNumberSuffix");
Response postItemResponse = create(itemsStorageUrl(""), itemToCreate);
assertThat(postItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
JsonObject itemFromPost = postItemResponse.getJson();
String itemId = itemFromPost.getString("id");
assertThat(itemId, is(notNullValue()));
URL getItemUrl = itemsStorageUrl(String.format("/%s", itemId));
Response getItemResponse = get(getItemUrl);
JsonObject itemFromGet = getItemResponse.getJson();
assertThat(itemFromGet.getString("id"), is(itemId));
assertThat(itemFromGet.getString("holdingsRecordId"), is(holdingId.toString()));
assertThat(itemFromGet.getJsonObject("effectiveCallNumberComponents").getString("suffix"), is("itemLevelCallNumberSuffix"));
URL holdingsUrl = holdingsStorageUrl(String.format("/%s", holdingId));
holding.put("callNumberSuffix", "updatedHoldingCallNumberSuffix");
Response putResponse = update(holdingsUrl, holding);
assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
Response getUpdatedItemResponse = get(getItemUrl);
JsonObject updatedItemFromGet = getUpdatedItemResponse.getJson();
assertThat(getUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
assertThat(updatedItemFromGet.getString("id"), is(itemId));
assertThat(updatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("suffix"), is("itemLevelCallNumberSuffix"));
}
Aggregations