use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.
the class ItemStorageTest method cannotCreateItemWithNonExistentStatisticalCodeId.
@Test
public void cannotCreateItemWithNonExistentStatisticalCodeId() throws Exception {
final UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
final UUID nonExistentStatisticalCodeId = UUID.randomUUID();
final String status = "Available";
final JsonObject itemToCreate = new ItemRequestBuilder().forHolding(holdingsRecordId).withMaterialType(journalMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withStatus(status).withStatisticalCodeIds(Arrays.asList(nonExistentStatisticalCodeId)).create();
final String itemId = itemToCreate.getString("id");
final Response createdItem = itemsClient.attemptToCreate(itemToCreate);
String expectedMessage = String.format("statistical code doesn't exist: %s foreign key violation in statisticalCodeIds array of item with id=%s", nonExistentStatisticalCodeId.toString(), itemId);
assertThat(createdItem, hasValidationError(expectedMessage, "item", itemId));
}
use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.
the class ItemStorageTest method cannotCreateItemWithNonExistentHoldingsRecordId.
@Test
public void cannotCreateItemWithNonExistentHoldingsRecordId() throws Exception {
final UUID nonExistentHoldingsRecordId = UUID.randomUUID();
final JsonObject itemToCreate = new ItemRequestBuilder().forHolding(nonExistentHoldingsRecordId).withMaterialType(journalMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).create();
final Response createdItem = itemsClient.attemptToCreate(itemToCreate);
assertThat(createdItem, hasValidationError("Holdings record does not exist", "holdingsRecordId", nonExistentHoldingsRecordId.toString()));
}
use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.
the class ItemStorageTest method shouldFindItemByCallNumberWhenThereIsSuffix.
@Test
public void shouldFindItemByCallNumberWhenThereIsSuffix() throws Exception {
final UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
final IndividualResource firstItemToMatch = itemsClient.create(new ItemRequestBuilder().forHolding(holdingsRecordId).withMaterialType(journalMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withItemLevelCallNumber("GE77 .F73 2014").available());
final IndividualResource secondItemToMatch = itemsClient.create(new ItemRequestBuilder().forHolding(holdingsRecordId).withMaterialType(journalMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withItemLevelCallNumber("GE77 .F73 2014").withItemLevelCallNumberSuffix("Curriculum Materials Collection").available());
itemsClient.create(new ItemRequestBuilder().forHolding(holdingsRecordId).withMaterialType(journalMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withItemLevelCallNumber("GE77 .F73 ").withItemLevelCallNumberSuffix("2014 Curriculum Materials Collection").available());
final List<UUID> foundItems = searchByCallNumberEyeReadable("GE77 .F73 2014");
assertThat(foundItems.size(), is(2));
assertThat(foundItems, hasItems(firstItemToMatch.getId(), secondItemToMatch.getId()));
}
use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.
the class StatisticalCodeTest method canNotDeleteStatisticalCodeIfInUseByItem.
@Test
public void canNotDeleteStatisticalCodeIfInUseByItem() throws Exception {
final var statisticalCode = new StatisticalCodeBuilder().withId(UUID.fromString("b06fa5fe-a267-4597-8e74-3b308bd4c932")).withCode("stcone").withName("STATISTICAL CODE 1");
final var createdCode = statisticalCodeFixture.createSerialManagementCode(statisticalCode);
UUID instanceId = UUID.randomUUID();
instancesClient.create(smallAngryPlanet(instanceId));
UUID holdingId = UUID.randomUUID();
final var holdingToCreate = new HoldingRequestBuilder().withId(holdingId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId);
holdingsClient.create(holdingToCreate);
UUID itemId = UUID.randomUUID();
List<UUID> codes = new ArrayList<>();
codes.add(createdCode.getId());
final var itemToCreate = new ItemRequestBuilder().withId(itemId).forHolding(holdingId).withMaterialType(bookMaterialTypeId).withPermanentLoanTypeId(canCirculateLoanTypeId).withStatisticalCodeIds(codes);
itemsClient.create(itemToCreate);
CompletableFuture<Response> deleteCompleted = new CompletableFuture<>();
client.delete(statisticalCodesUrl("/" + createdCode.getId().toString()), StorageTestSuite.TENANT_ID, ResponseHandler.text(deleteCompleted));
Response response = deleteCompleted.get(5, TimeUnit.SECONDS);
assertThat(response.getStatusCode(), is(400));
assertThat(response.getBody().trim(), is("foreign_key_violation: Key (id)=(b06fa5fe-a267-4597-8e74-3b308bd4c932) is still referenced from table \"item\"."));
}
use of org.folio.rest.support.builders.ItemRequestBuilder in project mod-inventory-storage by folio-org.
the class UpdateItemStatusDateFunctionMigrationTest method createAndChangeItemStatus.
private UUID createAndChangeItemStatus() {
final UUID holdingsId = createInstanceAndHolding(mainLibraryLocationId);
final IndividualResource item = itemsClient.create(new ItemRequestBuilder().available().withMaterialType(bookMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).forHolding(holdingsId));
itemsClient.replace(item.getId(), item.copyJson().put("status", new JsonObject().put("name", "Checked out")));
return item.getId();
}
Aggregations