Search in sources :

Example 1 with StatisticalCodeBuilder

use of org.folio.rest.support.builders.StatisticalCodeBuilder 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));
}
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 2 with StatisticalCodeBuilder

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

the class ItemStorageTest method canCreateAnItemViaCollectionResource.

@Test
public void canCreateAnItemViaCollectionResource() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
    UUID id = UUID.randomUUID();
    final String inTransitServicePointId = UUID.randomUUID().toString();
    String adminNote = "an admin note";
    final var statisticalCode = statisticalCodeFixture.createSerialManagementCode(new StatisticalCodeBuilder().withCode("stcone").withName("Statistical code 1"));
    final UUID statisticalCodeId = UUID.fromString(statisticalCode.getJson().getString("id"));
    JsonObject itemToCreate = new JsonObject();
    itemToCreate.put("administrativeNotes", new JsonArray().add(adminNote));
    itemToCreate.put("id", id.toString());
    itemToCreate.put("holdingsRecordId", holdingsRecordId.toString());
    itemToCreate.put("barcode", "565578437802");
    itemToCreate.put("status", new JsonObject().put("name", "Available"));
    itemToCreate.put("materialTypeId", journalMaterialTypeID);
    itemToCreate.put("permanentLoanTypeId", canCirculateLoanTypeID);
    itemToCreate.put("temporaryLocationId", annexLibraryLocationId.toString());
    itemToCreate.put("tags", new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)));
    itemToCreate.put("copyNumber", "copy1");
    itemToCreate.put("itemLevelCallNumber", "PS3623.R534 P37 2005");
    itemToCreate.put("itemLevelCallNumberSuffix", "allOwnComponentsCNS");
    itemToCreate.put("itemLevelCallNumberPrefix", "allOwnComponentsCNP");
    itemToCreate.put("itemLevelCallNumberTypeId", ITEM_LEVEL_CALL_NUMBER_TYPE);
    itemToCreate.put("statisticalCodeIds", Arrays.asList(statisticalCodeId));
    // TODO: Replace with real service point when validated
    itemToCreate.put("inTransitDestinationServicePointId", inTransitServicePointId);
    setItemSequence(1);
    CompletableFuture<Response> createCompleted = new CompletableFuture<>();
    client.post(itemsStorageUrl(""), itemToCreate, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
    Response postResponse = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(postResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
    JsonObject itemFromPost = postResponse.getJson();
    assertThat(itemFromPost.getString("id"), is(id.toString()));
    assertThat(itemFromPost.getJsonArray("administrativeNotes").contains(adminNote), is(true));
    assertThat(itemFromPost.getString("holdingsRecordId"), is(holdingsRecordId.toString()));
    assertThat(itemFromPost.getString("barcode"), is("565578437802"));
    assertThat(itemFromPost.getJsonObject("status").getString("name"), is("Available"));
    assertThat(itemFromPost.getString("materialTypeId"), is(journalMaterialTypeID));
    assertThat(itemFromPost.getString("permanentLoanTypeId"), is(canCirculateLoanTypeID));
    assertThat(itemFromPost.getString("temporaryLocationId"), is(annexLibraryLocationId.toString()));
    assertThat(itemFromPost.getString("inTransitDestinationServicePointId"), is(inTransitServicePointId));
    assertThat(itemFromPost.getString("hrid"), is("it00000000001"));
    assertThat(itemFromPost.getString("copyNumber"), is("copy1"));
    assertThat(itemFromPost.getString("effectiveShelvingOrder"), is("PS 43623 R534 P37 42005 COP Y1 allOwnComponentsCNS"));
    Response getResponse = getById(id);
    assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject itemFromGet = getResponse.getJson();
    assertThat(itemFromGet.getString("id"), is(id.toString()));
    assertThat(itemFromGet.getJsonArray("administrativeNotes").contains(adminNote), is(true));
    assertThat(itemFromGet.getString("holdingsRecordId"), is(holdingsRecordId.toString()));
    assertThat(itemFromGet.getString("barcode"), is("565578437802"));
    assertThat(itemFromGet.getJsonObject("status").getString("name"), is("Available"));
    assertThat(itemFromGet.getString("materialTypeId"), is(journalMaterialTypeID));
    assertThat(itemFromGet.getString("permanentLoanTypeId"), is(canCirculateLoanTypeID));
    assertThat(itemFromGet.getString("temporaryLocationId"), is(annexLibraryLocationId.toString()));
    assertThat(itemFromGet.getString("inTransitDestinationServicePointId"), is(inTransitServicePointId));
    assertThat(itemFromGet.getString("hrid"), is("it00000000001"));
    List<String> tags = getTags(itemFromGet);
    assertThat(tags.size(), is(1));
    assertThat(tags, hasItem(TAG_VALUE));
    assertThat(itemFromGet.getString("copyNumber"), is("copy1"));
    assertCreateEventForItem(itemFromGet);
    assertThat(itemFromGet.getString("effectiveShelvingOrder"), is("PS 43623 R534 P37 42005 COP Y1 allOwnComponentsCNS"));
    assertThat(itemFromGet.getJsonArray("statisticalCodeIds"), hasItem(statisticalCodeId.toString()));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.rest.support.Response) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) CompletableFuture(java.util.concurrent.CompletableFuture) StatisticalCodeBuilder(org.folio.rest.support.builders.StatisticalCodeBuilder) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with StatisticalCodeBuilder

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

the class StatisticalCodeTest method canNotDeleteStatisticalCodeIfInUseByInstance.

@Test
public void canNotDeleteStatisticalCodeIfInUseByInstance() 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(withStatisticalCode(createdCode, smallAngryPlanet(instanceId)));
    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 \"instance\"."));
}
Also used : Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) StatisticalCodeBuilder(org.folio.rest.support.builders.StatisticalCodeBuilder) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with StatisticalCodeBuilder

use of org.folio.rest.support.builders.StatisticalCodeBuilder 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 5 with StatisticalCodeBuilder

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

the class ItemStorageTest method canUpdateItemWithStatisticalCodeId.

@Test
public void canUpdateItemWithStatisticalCodeId() throws Exception {
    final var statisticalCode = statisticalCodeFixture.createSerialManagementCode(new StatisticalCodeBuilder().withCode("stcone").withName("Statistical code 1"));
    final UUID holdingsRecordId = createInstanceAndHolding(mainLibraryLocationId);
    final UUID statisticalCodeId = UUID.fromString(statisticalCode.getJson().getString("id"));
    JsonObject item = new JsonObject();
    String itemId = UUID.randomUUID().toString();
    item.put("id", itemId);
    item.put("status", new JsonObject().put("name", "Available"));
    item.put("holdingsRecordId", holdingsRecordId.toString());
    item.put("permanentLoanTypeId", canCirculateLoanTypeID);
    item.put("materialTypeId", bookMaterialTypeID);
    item.put("hrid", "testHRID");
    createItem(item);
    item = getById(itemId).getJson();
    item.put("statisticalCodeIds", Arrays.asList(statisticalCodeId));
    CompletableFuture<Response> completed = new CompletableFuture<>();
    client.put(itemsStorageUrl("/" + itemId), item, StorageTestSuite.TENANT_ID, ResponseHandler.empty(completed));
    Response response = completed.get(5, TimeUnit.SECONDS);
    assertThat(response.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
}
Also used : Response(org.folio.rest.support.Response) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) CompletableFuture(java.util.concurrent.CompletableFuture) StatisticalCodeBuilder(org.folio.rest.support.builders.StatisticalCodeBuilder) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) 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