use of api.support.builders.HoldingRequestBuilder in project mod-inventory by folio-org.
the class BoundWithTests method boundWithFlagsArePresentOnInstancesAndItemsAsExpected.
@Test
public void boundWithFlagsArePresentOnInstancesAndItemsAsExpected() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
IndividualResource instance1 = instancesStorageClient.create(InstanceSamples.smallAngryPlanet(UUID.randomUUID()));
IndividualResource holdings1a = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instance1.getId()).permanentlyInMainLibrary().withCallNumber("HOLDINGS 1A"));
IndividualResource item1a = itemsClient.create(new ItemRequestBuilder().forHolding(holdings1a.getId()).withBarcode("ITEM 1A"));
IndividualResource instance2 = instancesStorageClient.create(InstanceSamples.girlOnTheTrain(UUID.randomUUID()));
IndividualResource holdings2a = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instance2.getId()).permanentlyInMainLibrary().withCallNumber("HOLDINGS 2A"));
IndividualResource item2a = itemsClient.create(new ItemRequestBuilder().forHolding(holdings2a.getId()).withBarcode("ITEM 2A"));
IndividualResource instance3 = instancesStorageClient.create(InstanceSamples.leviathanWakes(UUID.randomUUID()));
IndividualResource holdings3a = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instance3.getId()).permanentlyInMainLibrary().withCallNumber("HOLDINGS 3A"));
IndividualResource item3a = itemsClient.create(new ItemRequestBuilder().forHolding(holdings3a.getId()).withBarcode("ITEM 3A"));
// Adding 'holdings2a' to bound-with item 'item1a' means
// 'item1a' becomes a bound-with and
// 'holdings2a' becomes a bound-with part
// 'holdings1a' becomes a bound-with part, inferred by it's direct relation to bound-with item 'item1a'
// 'instance1' becomes a bound-with part (through holdings1a)
// 'instance2' becomes a bound-with part (through holdings2a)
// 'item2a' and 'item3a' are not bound-with items
// 'holdings3a', 'instance3a' are not parts of any bound-with
JsonObject boundWithPart = makeObjectBoundWithPart(item1a.getJson().getString("id"), holdings2a.getJson().getString("id"));
boundWithPartsStorageClient.create(boundWithPart);
for (JsonObject item : itemsClient.getAll()) {
if (item.getString("id").equals(item1a.getJson().getString("id"))) {
assertThat("Item1a is bound-with " + item.encodePrettily(), item.getBoolean("isBoundWith"), is(true));
} else if (item.getString("id").equals(item2a.getJson().getString("id"))) {
assertThat("Item2a is NOT bound-with " + item.encodePrettily(), item.getBoolean("isBoundWith"), is(false));
} else if (item.getString("id").equals(item3a.getJson().getString("id"))) {
assertThat("Item3a is NOT bound-with " + item.encodePrettily(), item.getBoolean("isBoundWith"), is(false));
} else {
fail("Unexpected item received from storage: " + item.encodePrettily());
}
}
for (JsonObject instance : instancesClient.getAll()) {
if (instance.getString("id").equals(instance1.getJson().getString("id"))) {
assertThat("Instance 1 is bound-with: " + instance.encodePrettily(), instance.getBoolean("isBoundWith"), is(true));
} else if (instance.getString("id").equals(instance2.getJson().getString("id"))) {
assertThat("Instance 2 is bound-with: " + instance.encodePrettily(), instance.getBoolean("isBoundWith"), is(true));
} else if (instance.getString("id").equals(instance3.getJson().getString("id"))) {
assertThat("Instance 3 is NOT bound-with: " + instance.encodePrettily(), instance.getBoolean("isBoundWith"), is(false));
} else {
fail("Unexpected Instance received from storage: " + instance.encodePrettily());
}
}
Response instance1byId = instancesClient.getById(instance1.getId());
assertThat("Instance 1 fetched by ID is bound-with", instance1byId.getJson().getBoolean("isBoundWith"), is(true));
Response instance3byId = instancesClient.getById(instance3.getId());
assertThat("instance 3 fetched by ID is NOT bound-with", instance3byId.getJson().getBoolean("isBoundWith"), is(false));
Response item1byId = itemsClient.getById(item1a.getId());
assertThat("Item 1 fetched by ID is a bound-with", item1byId.getJson().getBoolean("isBoundWith"), is(true));
Response item2byId = itemsClient.getById(item2a.getId());
assertThat("Item 2 fetched by ID is NOT a bound-with", item2byId.getJson().getBoolean("isBoundWith"), is(false));
}
use of api.support.builders.HoldingRequestBuilder in project mod-inventory by folio-org.
the class HoldingsApiExamples method canUpdateAnExistingHoldings.
@Test
public void canUpdateAnExistingHoldings() throws Exception {
UUID instanceId = instancesClient.create(InstanceRequestExamples.smallAngryPlanet()).getId();
String adminNote = "This is a note.";
List<String> administrativeNotes = new ArrayList<String>();
administrativeNotes.add(adminNote);
JsonObject newHoldings = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instanceId).withAdministrativeNotes(administrativeNotes)).getJson();
JsonObject updateHoldingsRequest = newHoldings.copy().put("permanentLocationId", "fcd64ce1-6995-48f0-840e-89ffa2288371");
Response putResponse = updateHoldings(updateHoldingsRequest);
assertThat(putResponse.getStatusCode(), is(NO_CONTENT.code()));
Response getResponse = holdingsStorageClient.getById(getId(newHoldings));
assertThat(getResponse.getStatusCode(), is(OK.code()));
JsonObject updatedHoldings = getResponse.getJson();
assertThat(updatedHoldings.containsKey("administrativeNotes"), is(true));
List<String> retrievedNotes = JsonArrayHelper.toListOfStrings(updatedHoldings.getJsonArray("administrativeNotes"));
assertThat(retrievedNotes, contains(adminNote));
assertThat(updatedHoldings.getString("id"), is(newHoldings.getString("id")));
assertThat(updatedHoldings.getString("permanentLocationId"), is("fcd64ce1-6995-48f0-840e-89ffa2288371"));
}
use of api.support.builders.HoldingRequestBuilder in project mod-inventory by folio-org.
the class HoldingsApiExamples method cannotUpdateAnHoldingsThatDoesNotExist.
@Test
public void cannotUpdateAnHoldingsThatDoesNotExist() throws Exception {
UUID instanceId = instancesClient.create(InstanceRequestExamples.smallAngryPlanet()).getId();
JsonObject updateHoldingsRequest = new HoldingRequestBuilder().forInstance(instanceId).create();
Response putResponse = updateHoldings(updateHoldingsRequest);
assertThat(putResponse.getStatusCode(), is(NOT_FOUND.code()));
assertThat(putResponse.getBody(), is("Holdings not found"));
}
use of api.support.builders.HoldingRequestBuilder in project mod-inventory by folio-org.
the class HoldingsApiExamples method canNotUpdateAnExistingMARCHoldingsIfBlockedFieldsAreChanged.
@Test
public void canNotUpdateAnExistingMARCHoldingsIfBlockedFieldsAreChanged() throws Exception {
UUID instanceId = instancesClient.create(InstanceRequestExamples.smallAngryPlanet()).getId();
JsonObject newHoldings = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instanceId).withMarcSource()).getJson();
JsonObject holdingsForUpdate = marcHoldingsWithDefaultBlockedFields(getId(newHoldings));
for (String field : config.getHoldingsBlockedFields()) {
Response putResponse = updateHoldings(holdingsForUpdate);
assertThat(putResponse.getStatusCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
assertThat(putResponse.getJson().getJsonArray("errors").size(), is(1));
holdingsForUpdate.remove(field);
}
}
use of api.support.builders.HoldingRequestBuilder in project mod-inventory by folio-org.
the class ItemApiExamples method canRemoveBarcodeFromAnExistingItem.
@Test
public void canRemoveBarcodeFromAnExistingItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
JsonObject smallAngryInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
UUID smallAngryHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(smallAngryInstance.getString("id")))).getId();
// Existing item with no barcode, to ensure empty barcode doesn't match
itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().withNoBarcode());
JsonObject nodInstance = createInstance(nod(UUID.randomUUID()));
UUID nodHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(nodInstance.getString("id")))).getId();
IndividualResource nodItemResponse = itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().canCirculate().withBarcode("654647774352"));
JsonObject changedNodItem = nodItemResponse.getJson().copy();
changedNodItem.remove("barcode");
URL nodItemLocation = new URL(String.format("%s/%s", ApiRoot.items(), nodItemResponse.getId()));
final var putItemCompleted = okapiClient.put(nodItemLocation, changedNodItem);
Response putItemResponse = putItemCompleted.toCompletableFuture().get(5, SECONDS);
assertThat(putItemResponse.getStatusCode(), is(204));
final var getItemCompleted = okapiClient.get(nodItemLocation);
Response getItemResponse = getItemCompleted.toCompletableFuture().get(5, SECONDS);
assertThat(getItemResponse.getStatusCode(), is(200));
assertThat(getItemResponse.getJson().containsKey("barcode"), is(false));
}
Aggregations