Search in sources :

Example 6 with HoldingRequestBuilder

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

the class ItemApiExamples method cannotSearchForItemsByTitle.

@Test
public void cannotSearchForItemsByTitle() 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();
    itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().canCirculate().withBarcode("564566456546"));
    final var searchGetCompleted = okapiClient.get(ApiRoot.items("query=title=*Small%20Angry*"));
    Response searchGetResponse = searchGetCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(searchGetResponse.getStatusCode(), is(200));
    List<JsonObject> items = JsonArrayHelper.toList(searchGetResponse.getJson().getJsonArray("items"));
    assertThat(items.size(), is(0));
    assertThat(searchGetResponse.getJson().getInteger("totalRecords"), is(0));
}
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) Test(org.junit.Test)

Example 7 with HoldingRequestBuilder

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

the class ItemApiExamples method canCreateAnItemWithACirculationNote.

@Test
public void canCreateAnItemWithACirculationNote() 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);
    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));
    assertThat(source.getString(ID_KEY), is(createdUser.getString(ID_KEY)));
    assertThat(source.getJsonObject(PERSONAL_KEY).getString(LAST_NAME_KEY), is(source.getJsonObject(PERSONAL_KEY).getString(LAST_NAME_KEY)));
    assertThat(source.getJsonObject(PERSONAL_KEY).getString(FIRST_NAME_KEY), is(source.getJsonObject(PERSONAL_KEY).getString(FIRST_NAME_KEY)));
    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)

Example 8 with HoldingRequestBuilder

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

the class ItemApiExamples method createInstanceAndHolding.

private UUID createInstanceAndHolding() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID instanceId = UUID.randomUUID();
    createInstance(smallAngryPlanet(instanceId));
    return holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instanceId)).getId();
}
Also used : HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) UUID(java.util.UUID)

Example 9 with HoldingRequestBuilder

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

the class ItemApiExamples method canPageAllItems.

@Test
public void canPageAllItems() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject smallAngryInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID smallAngryHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(smallAngryInstance.getString("id"))).withCallNumber(CALL_NUMBER).withCallNumberSuffix(CALL_NUMBER_SUFFIX).withCallNumberPrefix(CALL_NUMBER_PREFIX).withCallNumberTypeId(CALL_NUMBER_TYPE_ID)).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().withBarcode("645398607547"));
    itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().courseReserves().withBarcode("175848607547"));
    JsonObject girlOnTheTrainInstance = createInstance(girlOnTheTrain(UUID.randomUUID()));
    UUID girlOnTheTrainHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(girlOnTheTrainInstance.getString("id"))).withCallNumber(CALL_NUMBER).withCallNumberSuffix(CALL_NUMBER_SUFFIX).withCallNumberPrefix(CALL_NUMBER_PREFIX).withCallNumberTypeId(CALL_NUMBER_TYPE_ID)).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(girlOnTheTrainHoldingId).dvd().canCirculate().temporarilyCourseReserves().withBarcode("645334645247"));
    JsonObject nodInstance = createInstance(nod(UUID.randomUUID()));
    UUID nodHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(nodInstance.getString("id"))).withCallNumber(CALL_NUMBER).withCallNumberSuffix(CALL_NUMBER_SUFFIX).withCallNumberPrefix(CALL_NUMBER_PREFIX).withCallNumberTypeId(CALL_NUMBER_TYPE_ID)).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().courseReserves().withBarcode("564566456546"));
    itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().courseReserves().withBarcode("943209584495"));
    final var firstPageGetCompleted = okapiClient.get(ApiRoot.items("limit=3"));
    final var secondPageGetCompleted = okapiClient.get(ApiRoot.items("limit=3&offset=3"));
    Response firstPageResponse = firstPageGetCompleted.toCompletableFuture().get(5, SECONDS);
    Response secondPageResponse = secondPageGetCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(firstPageResponse.getStatusCode(), is(200));
    assertThat(secondPageResponse.getStatusCode(), is(200));
    List<JsonObject> firstPageItems = JsonArrayHelper.toList(firstPageResponse.getJson().getJsonArray("items"));
    assertThat(firstPageItems.size(), is(3));
    assertThat(firstPageResponse.getJson().getInteger("totalRecords"), is(5));
    List<JsonObject> secondPageItems = JsonArrayHelper.toList(secondPageResponse.getJson().getJsonArray("items"));
    assertThat(secondPageItems.size(), is(2));
    assertThat(secondPageResponse.getJson().getInteger("totalRecords"), is(5));
    firstPageItems.forEach(ItemApiExamples::selfLinkRespectsWayResourceWasReached);
    firstPageItems.forEach(this::selfLinkShouldBeReachable);
    firstPageItems.forEach(ItemApiExamples::hasConsistentMaterialType);
    firstPageItems.forEach(ItemApiExamples::hasConsistentPermanentLoanType);
    firstPageItems.forEach(ItemApiExamples::hasConsistentTemporaryLoanType);
    firstPageItems.forEach(ItemApiExamples::hasStatus);
    firstPageItems.forEach(ItemApiExamples::hasConsistentPermanentLocation);
    firstPageItems.forEach(ItemApiExamples::hasConsistentTemporaryLocation);
    firstPageItems.forEach(this::assertCallNumbers);
    secondPageItems.forEach(ItemApiExamples::selfLinkRespectsWayResourceWasReached);
    secondPageItems.forEach(this::selfLinkShouldBeReachable);
    secondPageItems.forEach(ItemApiExamples::hasConsistentMaterialType);
    secondPageItems.forEach(ItemApiExamples::hasConsistentPermanentLoanType);
    secondPageItems.forEach(ItemApiExamples::hasConsistentTemporaryLoanType);
    secondPageItems.forEach(ItemApiExamples::hasStatus);
    secondPageItems.forEach(ItemApiExamples::hasConsistentPermanentLocation);
    secondPageItems.forEach(ItemApiExamples::hasConsistentTemporaryLocation);
    secondPageItems.forEach(this::assertCallNumbers);
}
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) Test(org.junit.Test)

Example 10 with HoldingRequestBuilder

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

the class ItemApiExamples method canChangeBarcodeForExistingItem.

@Test
public void canChangeBarcodeForExistingItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    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(204));
    final var getItemCompleted = okapiClient.get(nodItemLocation);
    Response getItemResponse = getItemCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(getItemResponse.getStatusCode(), is(200));
    assertThat(getItemResponse.getJson().getString("barcode"), is("645398607547"));
}
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) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) URL(java.net.URL) Test(org.junit.Test)

Aggregations

HoldingRequestBuilder (api.support.builders.HoldingRequestBuilder)41 Test (org.junit.Test)30 JsonObject (io.vertx.core.json.JsonObject)28 IndividualResource (org.folio.inventory.support.http.client.IndividualResource)25 UUID (java.util.UUID)24 Response (org.folio.inventory.support.http.client.Response)19 ItemRequestBuilder (api.support.builders.ItemRequestBuilder)15 Before (org.junit.Before)9 URL (java.net.URL)4 DateTime (org.joda.time.DateTime)4 Ignore (org.junit.Ignore)3 JsonArray (io.vertx.core.json.JsonArray)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)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 ApiTestSuite.getReadingRoomLocation (api.ApiTestSuite.getReadingRoomLocation)1 ApiTestSuite.getThirdFloorLocation (api.ApiTestSuite.getThirdFloorLocation)1