use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsSourceTest method canAssociateSourceWithHolding.
@Test
public void canAssociateSourceWithHolding() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID instanceId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
JsonObject instanceToCreate = new JsonObject();
instanceToCreate.put("id", instanceId.toString());
instanceToCreate.put("source", "Test Source");
instanceToCreate.put("title", "Test Instance");
instanceToCreate.put("instanceTypeId", "535e3160-763a-42f9-b0c0-d8ed7df6e2a2");
instancesClient.create(instanceToCreate);
holdingsSourceClient.create(new JsonObject().put("id", sourceId.toString()).put("name", "associatable source")).getJson();
IndividualResource holdingsResponse = holdingsClient.create(new HoldingRequestBuilder().withId(UUID.randomUUID()).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withSource(sourceId));
assertThat(holdingsResponse.getJson().getString("sourceId"), is(sourceId.toString()));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsSourceTest method canNotRemoveHoldingsSourcesAttachedToHoldings.
@Test
public void canNotRemoveHoldingsSourcesAttachedToHoldings() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID instanceId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
JsonObject instanceToCreate = new JsonObject();
instanceToCreate.put("id", instanceId.toString());
instanceToCreate.put("source", "Test Source");
instanceToCreate.put("title", "Test Instance");
instanceToCreate.put("instanceTypeId", "535e3160-763a-42f9-b0c0-d8ed7df6e2a2");
instancesClient.create(instanceToCreate);
holdingsSourceClient.create(new JsonObject().put("id", sourceId.toString()).put("name", "associated source")).getJson();
holdingsClient.create(new HoldingRequestBuilder().withId(UUID.randomUUID()).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withSource(sourceId));
Response sourceDeleteResponse = holdingsSourceClient.attemptToDelete(sourceId);
// the associated source should not have been deleted:
assertThat(sourceDeleteResponse.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method canGetAllHoldings.
@Test
public void canGetAllHoldings() 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).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getId();
CompletableFuture<Response> getCompleted = new CompletableFuture<>();
client.get(holdingsStorageUrl(""), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
Response response = getCompleted.get(5, TimeUnit.SECONDS);
JsonObject responseBody = response.getJson();
List<JsonObject> allHoldings = JsonArrayHelper.toList(responseBody.getJsonArray("holdingsRecords"));
assertThat(allHoldings.size(), is(3));
assertThat(responseBody.getInteger("totalRecords"), is(3));
assertThat(allHoldings.stream().anyMatch(filterById(firstHoldingId)), is(true));
assertThat(allHoldings.stream().anyMatch(filterById(secondHoldingId)), is(true));
assertThat(allHoldings.stream().anyMatch(filterById(thirdHoldingId)), is(true));
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method cannotCreateAHoldingsWhenDuplicateHRIDIsSupplied.
@Test
public void cannotCreateAHoldingsWhenDuplicateHRIDIsSupplied() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
log.info("Starting cannotCreateAHoldingsWhenDuplicateHRIDIsSupplied");
final UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
final UUID holdingsId = UUID.randomUUID();
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"));
final Response getResponse = holdingsClient.getById(holdingsId);
assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
final JsonObject holdingsFromGet = getResponse.getJson();
assertThat(holdingsFromGet.getString("hrid"), is("ho00000000001"));
final JsonObject duplicateHoldings = new HoldingRequestBuilder().withId(UUID.randomUUID()).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE))).withHrid("ho00000000001").create();
final Response duplicateResponse = create(holdingsStorageUrl(""), duplicateHoldings);
assertThat(duplicateResponse.getStatusCode(), is(422));
final Errors errors = duplicateResponse.getJson().mapTo(Errors.class);
assertThat(errors, notNullValue());
assertThat(errors.getErrors(), notNullValue());
assertThat(errors.getErrors().size(), is(1));
assertThat(errors.getErrors().get(0), notNullValue());
assertThat(errors.getErrors().get(0).getMessage(), containsString("value already exists in table holdings_record: ho00000000001"));
assertThat(errors.getErrors().get(0).getParameters(), notNullValue());
assertThat(errors.getErrors().get(0).getParameters().size(), is(1));
assertThat(errors.getErrors().get(0).getParameters().get(0), notNullValue());
assertThat(errors.getErrors().get(0).getParameters().get(0).getKey(), is("lower(f_unaccent(jsonb ->> 'hrid'::text))"));
assertThat(errors.getErrors().get(0).getParameters().get(0).getValue(), is("ho00000000001"));
log.info("Finished cannotCreateAHoldingsWhenDuplicateHRIDIsSupplied");
}
use of org.folio.rest.support.builders.HoldingRequestBuilder in project mod-inventory-storage by folio-org.
the class HoldingsStorageTest method updatingHoldingsUpdatesItemEffectiveCallNumberPrefix.
@Test
public void updatingHoldingsUpdatesItemEffectiveCallNumberPrefix() 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).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);
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("prefix"), is("testCallNumberPrefix"));
assertThat(secondItemFromGet.getString("id"), is(secondItemId));
assertThat(secondItemFromGet.getString("holdingsRecordId"), is(holdingId.toString()));
assertThat(secondItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("testCallNumberPrefix"));
URL holdingsUrl = holdingsStorageUrl(String.format("/%s", holdingId));
holding.remove("callNumberPrefix");
holding.put("callNumberPrefix", "updatedCallNumberPrefix");
Response putResponse = update(holdingsUrl, holding);
assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
assertThat(holding.getString("callNumberPrefix"), is("updatedCallNumberPrefix"));
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("prefix"), is("updatedCallNumberPrefix"));
assertThat(getSecondUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
assertThat(secondUpdatedItemFromGet.getString("id"), is(secondItemId));
assertThat(secondUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("updatedCallNumberPrefix"));
}
Aggregations