use of org.folio.rest.support.builders.ItemRequestBuilder 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.ItemRequestBuilder in project mod-inventory-storage by folio-org.
the class InstanceStorageTest method canSearchByBarcodeAndPermanentLocation.
// This is intended to demonstrate usage of the two different views
@Test
public void canSearchByBarcodeAndPermanentLocation() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID smallAngryPlanetInstanceId = UUID.randomUUID();
UUID mainLibrarySmallAngryHoldingId = UUID.randomUUID();
createInstance(smallAngryPlanet(smallAngryPlanetInstanceId));
createHoldings(new HoldingRequestBuilder().withId(mainLibrarySmallAngryHoldingId).withPermanentLocation(mainLibraryLocationId).forInstance(smallAngryPlanetInstanceId).create());
createItem(new ItemRequestBuilder().forHolding(mainLibrarySmallAngryHoldingId).withBarcode("706949453641").withPermanentLoanType(canCirculateLoanTypeId).withMaterialType(bookMaterialTypeId).create());
UUID annexSmallAngryHoldingId = UUID.randomUUID();
createHoldings(new HoldingRequestBuilder().withId(annexSmallAngryHoldingId).withPermanentLocation(annexLibraryLocationId).forInstance(smallAngryPlanetInstanceId).create());
createItem(new ItemRequestBuilder().forHolding(annexSmallAngryHoldingId).withBarcode("70704539201").withPermanentLoanType(canCirculateLoanTypeId).withMaterialType(bookMaterialTypeId).create());
UUID nodInstanceId = UUID.randomUUID();
UUID nodHoldingId = UUID.randomUUID();
createInstance(nod(nodInstanceId));
createHoldings(new HoldingRequestBuilder().withId(nodHoldingId).forInstance(nodInstanceId).withPermanentLocation(mainLibraryLocationId).create());
createItem(new ItemRequestBuilder().forHolding(nodHoldingId).withMaterialType(bookMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withBarcode("766043059304").create());
// Use == as exact match is intended for barcode and location ID
canSort(String.format("item.barcode==706949453641 and holdingsRecords.permanentLocationId==%s", mainLibraryLocationId), "Long Way to a Small Angry Planet");
canSort(String.format("((contributors =/@name \"becky\") and holdingsRecords.permanentLocationId=\"%s\")", mainLibraryLocationId), "Long Way to a Small Angry Planet");
System.out.println("canSearchByBarcodeAndPermanentLocation");
}
use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.
the class AuditDeleteTest method testOnlyDeletedItemsAreStoredInAuditTable.
@Test
public void testOnlyDeletedItemsAreStoredInAuditTable() throws Exception {
// given
createItem(new ItemRequestBuilder().forHolding(holdingsRecordId).withMaterialType(bookMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withBarcode("766043059304").create());
final JsonObject record = itemsClient.getAll().get(0);
final String itemId = record.getString("id");
// when
record.remove("yearCaption");
itemsClient.replace(UUID.fromString(itemId), record);
// then
assertThat(getRecordsFromAuditTable(AUDIT_ITEM).size(), is(0));
// when
itemsClient.delete(UUID.fromString(itemId));
// then
assertThat(getRecordIdFromAuditTable(AUDIT_ITEM), is(itemId));
}
use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.
the class ItemStorageTest method canCreateItemWithMultipleStatisticalCodeIds.
@Test
public void canCreateItemWithMultipleStatisticalCodeIds() throws Exception {
final var firstStatisticalCode = statisticalCodeFixture.createSerialManagementCode(new StatisticalCodeBuilder().withCode("stcone").withName("Statistical code 1"));
final var secondStatisticalCode = statisticalCodeFixture.attemptCreateSerialManagementCode(new StatisticalCodeBuilder().withCode("stctwo").withName("Statistical code 2"));
final UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
final UUID firstStatisticalCodeId = UUID.fromString(firstStatisticalCode.getJson().getString("id"));
final UUID secondStatisticalCodeId = UUID.fromString(secondStatisticalCode.getJson().getString("id"));
final String status = "Available";
final JsonObject itemToCreate = new ItemRequestBuilder().forHolding(holdingsRecordId).withMaterialType(journalMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withStatus(status).withStatisticalCodeIds(Arrays.asList(firstStatisticalCodeId, secondStatisticalCodeId)).create();
final Response createdItem = itemsClient.attemptToCreate(itemToCreate);
assertThat(createdItem.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
}
use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.
the class ItemStorageTest method canCreateItemWithAllAllowedStatuses.
@Test
@Parameters({ "Aged to lost", "Available", "Awaiting pickup", "Awaiting delivery", "Checked out", "Claimed returned", "Declared lost", "In process", "In process (non-requestable)", "In transit", "Intellectual item", "Long missing", "Lost and paid", "Missing", "On order", "Paged", "Restricted", "Order closed", "Unavailable", "Unknown", "Withdrawn" })
public void canCreateItemWithAllAllowedStatuses(String status) throws Exception {
final UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
final ItemRequestBuilder itemToCreate = new ItemRequestBuilder().forHolding(holdingsRecordId).withMaterialType(journalMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withStatus(status);
final IndividualResource createdItem = itemsClient.create(itemToCreate);
assertThat(createdItem.getJson().getJsonObject("status").getString("name"), is(status));
JsonObject itemInStorage = itemsClient.getById(createdItem.getId()).getJson();
assertThat(itemInStorage.getJsonObject("status").getString("name"), is(status));
}
Aggregations