Search in sources :

Example 1 with IndividualResource

use of org.folio.inventory.support.http.client.IndividualResource 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 IndividualResource

use of org.folio.inventory.support.http.client.IndividualResource 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 IndividualResource

use of org.folio.inventory.support.http.client.IndividualResource 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 IndividualResource

use of org.folio.inventory.support.http.client.IndividualResource 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)

Example 5 with IndividualResource

use of org.folio.inventory.support.http.client.IndividualResource in project mod-inventory by folio-org.

the class ItemApiExamples method canCreateAnItemWithACirculationNoteWithoutSourceField.

@Test
public void canCreateAnItemWithACirculationNoteWithoutSourceField() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject createdInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID holdingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(createdInstance.getString("id")))).getId();
    JsonObject user = new JsonObject().put(ID_KEY, USER_ID).put(PERSONAL_KEY, new JsonObject().put(LAST_NAME_KEY, "Smith").put(FIRST_NAME_KEY, "John"));
    JsonObject createdUser = usersClient.create(user).getJson();
    DateTime requestMade = DateTime.now();
    IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645398607547").temporarilyInReadingRoom().canCirculate().temporarilyCourseReserves().withCheckInNote());
    JsonObject createdItem = itemsClient.getById(postResponse.getId()).getJson();
    assertThat(createdItem.containsKey("id"), is(true));
    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(materialType.getString("id"), CoreMatchers.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"));
    JsonObject checkInNote = createdItem.getJsonArray(CIRCULATION_NOTES_KEY).getJsonObject(0);
    checkInNote.remove("source");
    JsonObject source = checkInNote.getJsonObject(SOURCE_KEY);
    assertThat(checkInNote.getString(NOTE_TYPE_KEY), is("Check in"));
    assertThat(checkInNote.getString(NOTE_KEY), is("Please read this note before checking in the item"));
    assertThat(checkInNote.getBoolean(STAFF_ONLY_KEY), is(false));
    assertThat(checkInNote.getString(DATE_KEY), withinSecondsAfter(Seconds.seconds(2), requestMade));
    selfLinkRespectsWayResourceWasReached(createdItem);
    selfLinkShouldBeReachable(createdItem);
}
Also used : HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

IndividualResource (org.folio.inventory.support.http.client.IndividualResource)118 Test (org.junit.Test)108 ItemRequestBuilder (api.support.builders.ItemRequestBuilder)82 JsonObject (io.vertx.core.json.JsonObject)49 Response (org.folio.inventory.support.http.client.Response)41 UUID (java.util.UUID)37 JsonArray (io.vertx.core.json.JsonArray)28 Parameters (junitparams.Parameters)28 HoldingRequestBuilder (api.support.builders.HoldingRequestBuilder)24 Before (org.junit.Before)9 ItemsMoveRequestBuilder (api.support.builders.ItemsMoveRequestBuilder)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 URL (java.net.URL)3 DateTime (org.joda.time.DateTime)3 EndpointFailureDescriptor (support.fakes.EndpointFailureDescriptor)3 Date (java.util.Date)2 List (java.util.List)2 Ignore (org.junit.Ignore)2 OkapiHttpClient (org.folio.inventory.support.http.client.OkapiHttpClient)1