Search in sources :

Example 6 with StatisticalCodeBuilder

use of org.folio.rest.support.builders.StatisticalCodeBuilder in project mod-inventory-storage by folio-org.

the class ItemStorageTest method cannotCreateItemWithAtLeastOneNonExistentStatisticalCodeId.

@Test
public void cannotCreateItemWithAtLeastOneNonExistentStatisticalCodeId() throws Exception {
    final var statisticalCode = statisticalCodeFixture.createSerialManagementCode(new StatisticalCodeBuilder().withCode("stcone").withName("Statistical code 1"));
    final UUID nonExistentStatisticalCodeId = UUID.randomUUID();
    final UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
    final UUID statisticalCodeId = UUID.fromString(statisticalCode.getJson().getString("id"));
    final String status = "Available";
    final JsonObject itemToCreate = new ItemRequestBuilder().forHolding(holdingsRecordId).withMaterialType(journalMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withStatus(status).withStatisticalCodeIds(Arrays.asList(statisticalCodeId, 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) StatisticalCodeBuilder(org.folio.rest.support.builders.StatisticalCodeBuilder) 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 StatisticalCodeBuilder

use of org.folio.rest.support.builders.StatisticalCodeBuilder in project mod-inventory-storage by folio-org.

the class StatisticalCodeTest method canNotDeleteStatisticalCodeIfInUseByHoldings.

@Test
public void canNotDeleteStatisticalCodeIfInUseByHoldings() 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();
    List<UUID> codes = new ArrayList<>();
    codes.add(createdCode.getId());
    final var holdingToCreate = new HoldingRequestBuilder().withId(holdingId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withStatisticalCodeIds(codes);
    holdingsClient.create(holdingToCreate);
    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 \"holdings record\"."));
}
Also used : Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) StatisticalCodeBuilder(org.folio.rest.support.builders.StatisticalCodeBuilder) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

UUID (java.util.UUID)7 Response (org.folio.rest.support.Response)7 StatisticalCodeBuilder (org.folio.rest.support.builders.StatisticalCodeBuilder)7 Test (org.junit.Test)7 CompletableFuture (java.util.concurrent.CompletableFuture)5 JsonObject (io.vertx.core.json.JsonObject)4 JsonErrorResponse (org.folio.rest.support.JsonErrorResponse)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 ItemRequestBuilder (org.folio.rest.support.builders.ItemRequestBuilder)3 ArrayList (java.util.ArrayList)2 HoldingRequestBuilder (org.folio.rest.support.builders.HoldingRequestBuilder)2 JsonArray (io.vertx.core.json.JsonArray)1