Search in sources :

Example 1 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method canCreateItemWithAnIDAndHRID.

@Test
public void canCreateItemWithAnIDAndHRID() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID itemId = UUID.randomUUID();
    final String hrid = "it777";
    UUID holdingId = createInstanceAndHolding();
    IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().withId(itemId).withHrid(hrid).forHolding(holdingId).withBarcode("645398607547").temporarilyInReadingRoom().canCirculate().withTagList(new JsonObject().put(Item.TAG_LIST_KEY, new JsonArray().add("test-tag").add("test-tag2"))).temporarilyCourseReserves());
    JsonObject createdItem = itemsClient.getById(postResponse.getId()).getJson();
    assertThat(createdItem.containsKey("id"), is(true));
    assertThat(createdItem.getString("id"), is(itemId.toString()));
    assertThat(createdItem.getString("title"), is("Long Way to a Small Angry Planet"));
    assertThat(createdItem.getString("barcode"), is("645398607547"));
    assertThat(createdItem.getJsonObject("status").getString("name"), is("Available"));
    JsonObject materialType = createdItem.getJsonObject("materialType");
    assertThat(getTags(createdItem), hasItems("test-tag", "test-tag2"));
    assertThat(materialType.getString("id"), is(ApiTestSuite.getBookMaterialType()));
    assertThat(materialType.getString("name"), is("Book"));
    JsonObject permanentLoanType = createdItem.getJsonObject("permanentLoanType");
    JsonObject temporaryLoanType = createdItem.getJsonObject("temporaryLoanType");
    assertThat(permanentLoanType.getString("id"), is(ApiTestSuite.getCanCirculateLoanType()));
    assertThat(permanentLoanType.getString("name"), is("Can Circulate"));
    assertThat(temporaryLoanType.getString("id"), is(ApiTestSuite.getCourseReserveLoanType()));
    assertThat(temporaryLoanType.getString("name"), is("Course Reserves"));
    assertThat("Item should not have permanent location", createdItem.containsKey("permanentLocation"), is(false));
    assertThat(createdItem.getJsonObject("temporaryLocation").getString("name"), is("Reading Room"));
    selfLinkRespectsWayResourceWasReached(createdItem);
    selfLinkShouldBeReachable(createdItem);
    assertThat(createdItem.getString("hrid"), is(hrid));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 2 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method cannotUpdateItemToSameBarcodeAsExistingItem.

@Test
public void cannotUpdateItemToSameBarcodeAsExistingItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject smallAngryInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID smallAngryHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(smallAngryInstance.getString("id")))).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().withBarcode("645398607547"));
    JsonObject nodInstance = createInstance(nod(UUID.randomUUID()));
    UUID nodHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(nodInstance.getString("id")))).getId();
    IndividualResource nodItemResponse = itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().canCirculate().withBarcode("654647774352"));
    JsonObject changedNodItem = nodItemResponse.getJson().copy().put("barcode", "645398607547");
    URL nodItemLocation = new URL(String.format("%s/%s", ApiRoot.items(), nodItemResponse.getId()));
    final var putItemCompleted = okapiClient.put(nodItemLocation, changedNodItem);
    Response putItemResponse = putItemCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(putItemResponse.getStatusCode(), is(400));
    assertThat(putItemResponse.getBody(), is("Barcode must be unique, 645398607547 is already assigned to another item"));
}
Also used : Response(org.folio.inventory.support.http.client.Response) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method CanDeleteSingleItem.

@Test
public void CanDeleteSingleItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject createdInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID holdingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(createdInstance.getString("id")))).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645398607547"));
    IndividualResource itemToDeleteResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("175848607547"));
    itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645334645247"));
    itemsClient.delete(itemToDeleteResponse.getId());
    final var getAllCompleted = okapiClient.get(ApiRoot.items());
    Response getAllResponse = getAllCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(getAllResponse.getJson().getJsonArray("items").size(), is(2));
    assertThat(getAllResponse.getJson().getInteger("totalRecords"), is(2));
}
Also used : Response(org.folio.inventory.support.http.client.Response) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) Test(org.junit.Test)

Example 4 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method cannotCreateItemWithUnrecognisedStatusName.

@Test
public void cannotCreateItemWithUnrecognisedStatusName() throws InterruptedException, ExecutionException, TimeoutException {
    JsonObject itemWithUnrecognizedStatus = new ItemRequestBuilder().forHolding(UUID.randomUUID()).withBarcode("645398607547").temporarilyInReadingRoom().create().put("status", new JsonObject().put("name", "Unrecognized name"));
    final var postCompleted = okapiClient.post(items(""), itemWithUnrecognizedStatus);
    Response response = postCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(response, hasValidationError("Undefined status specified", "status.name", "Unrecognized name"));
}
Also used : Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 5 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method cannotChangeHRID.

@Test
public void cannotChangeHRID() throws Exception {
    UUID holdingId = createInstanceAndHolding();
    IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645398607547").temporarilyInReadingRoom());
    JsonObject createdItem = postResponse.getJson();
    assertThat(createdItem.getString("hrid"), notNullValue());
    JsonObject updatedItem = createdItem.copy().put("barcode", "645398607548").put("itemLevelCallNumber", "callNumber").put("hrid", "updatedHrid");
    Response updateResponse = updateItem(updatedItem);
    assertThat(updateResponse, hasValidationError("HRID can not be updated", "hrid", "updatedHrid"));
    JsonObject existingItem = itemsClient.getById(postResponse.getId()).getJson();
    assertThat(existingItem, is(createdItem));
}
Also used : Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Aggregations

ItemRequestBuilder (api.support.builders.ItemRequestBuilder)96 Test (org.junit.Test)96 IndividualResource (org.folio.inventory.support.http.client.IndividualResource)83 Response (org.folio.inventory.support.http.client.Response)41 JsonObject (io.vertx.core.json.JsonObject)40 UUID (java.util.UUID)38 Parameters (junitparams.Parameters)29 HoldingRequestBuilder (api.support.builders.HoldingRequestBuilder)15 JsonArray (io.vertx.core.json.JsonArray)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 ItemsMoveRequestBuilder (api.support.builders.ItemsMoveRequestBuilder)5 DateTime (org.joda.time.DateTime)5 URL (java.net.URL)4 List (java.util.List)3 Date (java.util.Date)2 ApiTestSuite (api.ApiTestSuite)1 USER_ID (api.ApiTestSuite.USER_ID)1 ApiTestSuite.getCanCirculateLoanType (api.ApiTestSuite.getCanCirculateLoanType)1 ApiTestSuite.getDvdMaterialType (api.ApiTestSuite.getDvdMaterialType)1 ApiTestSuite.getMainLibraryLocation (api.ApiTestSuite.getMainLibraryLocation)1