use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method updatingHoldingsDoesNotUpdateItemsOnAnotherHoldings.
@Test
public void updatingHoldingsDoesNotUpdateItemsOnAnotherHoldings() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
UUID firstHoldings = UUID.randomUUID();
UUID secondHoldings = UUID.randomUUID();
JsonObject firstHolding = holdingsClient.create(new HoldingRequestBuilder().withId(firstHoldings).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withCallNumber("firstTestCallNumber").withCallNumberPrefix("firstTestCallNumberPrefix").withCallNumberSuffix("firstTestCallNumberSuffix").withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getJson();
holdingsClient.create(new HoldingRequestBuilder().withId(secondHoldings).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withCallNumber("secondTestCallNumber").withCallNumberPrefix("secondTestCallNumberPrefix").withCallNumberSuffix("secondTestCallNumberSuffix").withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getJson();
Response firstItemResponse = create(itemsStorageUrl(""), new ItemRequestBuilder().forHolding(firstHoldings).withPermanentLoanType(canCirculateLoanTypeId).withMaterialType(bookMaterialTypeId).create());
Response secondItemResponse = create(itemsStorageUrl(""), new ItemRequestBuilder().forHolding(secondHoldings).withPermanentLoanType(canCirculateLoanTypeId).withMaterialType(bookMaterialTypeId).create());
assertThat(firstItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
assertThat(secondItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
JsonObject firstItem = firstItemResponse.getJson();
JsonObject secondItem = secondItemResponse.getJson();
assertThat(firstItem.getJsonObject("effectiveCallNumberComponents").getString("callNumber"), is("firstTestCallNumber"));
assertThat(firstItem.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("firstTestCallNumberPrefix"));
assertThat(firstItem.getJsonObject("effectiveCallNumberComponents").getString("suffix"), is("firstTestCallNumberSuffix"));
assertThat(secondItem.getJsonObject("effectiveCallNumberComponents").getString("callNumber"), is("secondTestCallNumber"));
assertThat(secondItem.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("secondTestCallNumberPrefix"));
assertThat(secondItem.getJsonObject("effectiveCallNumberComponents").getString("suffix"), is("secondTestCallNumberSuffix"));
URL firstHoldingsUrl = holdingsStorageUrl(String.format("/%s", firstHoldings));
firstHolding.put("callNumber", "updatedFirstCallNumber");
firstHolding.put("callNumberPrefix", "updatedFirstCallNumberPrefix");
firstHolding.put("callNumberSuffix", "updatedFirstCallNumberSuffix");
Response putResponse = update(firstHoldingsUrl, firstHolding);
Response updatedFirstHoldingResponse = get(firstHoldingsUrl);
JsonObject updatedFirstHolding = updatedFirstHoldingResponse.getJson();
assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
assertThat(updatedFirstHolding.getString("callNumber"), is("updatedFirstCallNumber"));
String firstItemId = firstItem.getString("id");
String secondItemId = secondItem.getString("id");
URL getFirstItemUrl = itemsStorageUrl(String.format("/%s", firstItemId));
URL getSecondItemUrl = itemsStorageUrl(String.format("/%s", secondItemId));
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("updatedFirstCallNumber"));
assertThat(firstUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("updatedFirstCallNumberPrefix"));
assertThat(firstUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("suffix"), is("updatedFirstCallNumberSuffix"));
assertThat(getSecondUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
assertThat(secondUpdatedItemFromGet.getString("id"), is(secondItemId));
assertThat(secondUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("callNumber"), is("secondTestCallNumber"));
assertThat(secondUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("secondTestCallNumberPrefix"));
assertThat(secondUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("suffix"), is("secondTestCallNumberSuffix"));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method canSearchByDiscoverySuppressProperty.
@Test
public void canSearchByDiscoverySuppressProperty() throws Exception {
final IndividualResource instance = instancesClient.create(smallAngryPlanet(UUID.randomUUID()));
final IndividualResource suppressedHolding = holdingsClient.create(new HoldingRequestBuilder().forInstance(instance.getId()).withPermanentLocation(mainLibraryLocationId).withDiscoverySuppress(true));
final IndividualResource notSuppressedHolding = holdingsClient.create(new HoldingRequestBuilder().forInstance(instance.getId()).withPermanentLocation(mainLibraryLocationId).withDiscoverySuppress(false));
final IndividualResource notSuppressedHoldingDefault = holdingsClient.create(new HoldingRequestBuilder().forInstance(instance.getId()).withPermanentLocation(mainLibraryLocationId));
final List<IndividualResource> suppressedHoldings = holdingsClient.getMany("discoverySuppress==true");
final List<IndividualResource> notSuppressedHoldings = holdingsClient.getMany("cql.allRecords=1 not discoverySuppress==true");
assertThat(suppressedHoldings.size(), is(1));
assertThat(suppressedHoldings.get(0).getId(), is(suppressedHolding.getId()));
assertThat(notSuppressedHoldings.size(), is(2));
assertThat(notSuppressedHoldings.stream().map(IndividualResource::getId).collect(Collectors.toList()), containsInAnyOrder(notSuppressedHolding.getId(), notSuppressedHoldingDefault.getId()));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method canSetHoldingStatementForSupplementsWithNotes.
@Test
public void canSetHoldingStatementForSupplementsWithNotes() 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))).withHoldingsStatementsForSupplements(holdingsStatements));
JsonObject holding = holdingResponse.getJson();
assertThat(holding.getString("instanceId"), is(instanceId.toString()));
assertThat(holding.getString("permanentLocationId"), is(mainLibraryLocationId.toString()));
JsonObject responseStatement = holding.getJsonArray("holdingsStatementsForSupplements").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 updatingHoldingsUpdatesItemEffectiveCallNumberSuffix.
@Test
public void updatingHoldingsUpdatesItemEffectiveCallNumberSuffix() 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).withCallNumberSuffix("testCallNumberSuffix").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("suffix"), is("testCallNumberSuffix"));
assertThat(secondItemFromGet.getString("id"), is(secondItemId));
assertThat(secondItemFromGet.getString("holdingsRecordId"), is(holdingId.toString()));
assertThat(secondItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("suffix"), is("testCallNumberSuffix"));
URL holdingsUrl = holdingsStorageUrl(String.format("/%s", holdingId));
holding.put("callNumberSuffix", "updatedCallNumberSuffix");
Response putResponse = update(holdingsUrl, holding);
assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
assertThat(holding.getString("callNumberSuffix"), is("updatedCallNumberSuffix"));
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("suffix"), is("updatedCallNumberSuffix"));
assertThat(getSecondUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
assertThat(secondUpdatedItemFromGet.getString("id"), is(secondItemId));
assertThat(secondUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("suffix"), is("updatedCallNumberSuffix"));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method updatingPermanentLocationDoesNotChangeEffectiveLocationWhenTemporaryLocationSet.
@Test
public void updatingPermanentLocationDoesNotChangeEffectiveLocationWhenTemporaryLocationSet() 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).withTemporaryLocation(annexLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getJson();
assertThat(holding.getString("effectiveLocationId"), is(annexLibraryLocationId.toString()));
holding.put("permanentLocationId", secondFloorLocationId.toString());
update(holdingsUrl, holding);
Response updatedHolding = holdingsClient.getById(holdingId);
assertThat(updatedHolding.getJson().getString("effectiveLocationId"), is(annexLibraryLocationId.toString()));
}
Aggregations