Search in sources :

Example 6 with ItemRequestBuilder

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));
}
Also used : Response(org.folio.rest.support.Response) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 7 with ItemRequestBuilder

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()));
}
Also used : Response(org.folio.rest.support.Response) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 8 with ItemRequestBuilder

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()));
}
Also used : UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 9 with ItemRequestBuilder

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\"."));
}
Also used : Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) ArrayList(java.util.ArrayList) StatisticalCodeBuilder(org.folio.rest.support.builders.StatisticalCodeBuilder) UUID(java.util.UUID) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 10 with ItemRequestBuilder

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();
}
Also used : JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder)

Aggregations

ItemRequestBuilder (org.folio.rest.support.builders.ItemRequestBuilder)19 UUID (java.util.UUID)17 Test (org.junit.Test)17 JsonObject (io.vertx.core.json.JsonObject)10 IndividualResource (org.folio.rest.support.IndividualResource)8 Response (org.folio.rest.support.Response)6 HoldingRequestBuilder (org.folio.rest.support.builders.HoldingRequestBuilder)6 JsonErrorResponse (org.folio.rest.support.JsonErrorResponse)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 JsonArray (io.vertx.core.json.JsonArray)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Parameters (junitparams.Parameters)2 StatisticalCodeBuilder (org.folio.rest.support.builders.StatisticalCodeBuilder)2 Vertx (io.vertx.core.Vertx)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 IOException (java.io.IOException)1