Search in sources :

Example 1 with HoldingRequestBuilder

use of api.support.builders.HoldingRequestBuilder 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 2 with HoldingRequestBuilder

use of api.support.builders.HoldingRequestBuilder 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 3 with HoldingRequestBuilder

use of api.support.builders.HoldingRequestBuilder 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)

Example 4 with HoldingRequestBuilder

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

the class ItemApiExamples method canUpdateAnItemWithExistingCirculationNote.

@Test
public void canUpdateAnItemWithExistingCirculationNote() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject createdInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID holdingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(createdInstance.getString("id")))).getId();
    UUID itemId = UUID.randomUUID();
    JsonObject newItemRequest = new ItemRequestBuilder().withId(itemId).forHolding(holdingId).withBarcode("645398607547").canCirculate().temporarilyInReadingRoom().withCheckInNote().create();
    DateTime createItemRequestMade = DateTime.now();
    itemsClient.create(newItemRequest).getJson();
    JsonObject createdItem = itemsClient.getById(itemId).getJson();
    String createdItemCirculationNoteDate = createdItem.getJsonArray(CIRCULATION_NOTES_KEY).getJsonObject(0).getString(DATE_KEY);
    JsonObject updateItemRequest = newItemRequest.copy().put("hrid", createdItem.getString("hrid")).put("status", new JsonObject().put("name", "Checked out"));
    itemsClient.replace(itemId, updateItemRequest);
    Response getResponse = itemsClient.getById(itemId);
    assertThat(getResponse.getStatusCode(), is(200));
    JsonObject updatedItem = getResponse.getJson();
    assertThat(updatedItem.containsKey("id"), is(true));
    assertThat(updatedItem.getString("title"), is("Long Way to a Small Angry Planet"));
    assertThat(updatedItem.getString("barcode"), is("645398607547"));
    assertThat(updatedItem.getJsonObject("status").getString("name"), is("Checked out"));
    JsonObject materialType = updatedItem.getJsonObject("materialType");
    assertThat(materialType.getString("id"), is(ApiTestSuite.getBookMaterialType()));
    assertThat(materialType.getString("name"), is("Book"));
    JsonObject permanentLoanType = updatedItem.getJsonObject("permanentLoanType");
    assertThat(permanentLoanType.getString("id"), is(ApiTestSuite.getCanCirculateLoanType()));
    assertThat(permanentLoanType.getString("name"), is("Can Circulate"));
    assertThat("Item should not have permanent location", updatedItem.containsKey("permanentLocation"), is(false));
    assertThat(updatedItem.getJsonObject("temporaryLocation").getString("name"), is("Reading Room"));
    JsonObject checkInNote = updatedItem.getJsonArray(CIRCULATION_NOTES_KEY).getJsonObject(0);
    assertThat(checkInNote.getString(DATE_KEY), not(createdItemCirculationNoteDate));
    assertThat(checkInNote.getString(DATE_KEY), withinSecondsAfter(Seconds.seconds(2), createItemRequestMade));
    selfLinkRespectsWayResourceWasReached(updatedItem);
    selfLinkShouldBeReachable(updatedItem);
}
Also used : Response(org.folio.inventory.support.http.client.Response) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with HoldingRequestBuilder

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

the class ItemApiExamples method CanGetAllItemsWithDifferentTemporaryLoanType.

@Test
public void CanGetAllItemsWithDifferentTemporaryLoanType() 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"));
    itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().temporarilyCourseReserves().withBarcode("175848607547"));
    final var getAllCompleted = okapiClient.get(ApiRoot.items());
    Response getAllResponse = getAllCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(getAllResponse.getStatusCode(), is(200));
    List<JsonObject> items = JsonArrayHelper.toList(getAllResponse.getJson().getJsonArray("items"));
    assertThat(items.size(), is(2));
    assertThat(getAllResponse.getJson().getInteger("totalRecords"), is(2));
    assertThat(items.stream().filter(item -> StringUtils.equals(item.getString("barcode"), "645398607547")).findFirst().orElse(new JsonObject()).getJsonObject("permanentLoanType").getString("id"), is(ApiTestSuite.getCanCirculateLoanType()));
    assertThat(items.stream().filter(item -> StringUtils.equals(item.getString("barcode"), "645398607547")).findFirst().orElse(new JsonObject()).containsKey("temporaryLoanType"), is(false));
    assertThat(items.stream().filter(item -> StringUtils.equals(item.getString("barcode"), "175848607547")).findFirst().orElse(new JsonObject()).getJsonObject("permanentLoanType").getString("id"), is(ApiTestSuite.getCanCirculateLoanType()));
    assertThat(items.stream().filter(item -> StringUtils.equals(item.getString("barcode"), "175848607547")).findFirst().orElse(new JsonObject()).getJsonObject("temporaryLoanType").getString("id"), is(ApiTestSuite.getCourseReserveLoanType()));
    items.forEach(ItemApiExamples::hasConsistentPermanentLoanType);
    items.forEach(ItemApiExamples::hasConsistentTemporaryLoanType);
    items.forEach(ItemApiExamples::hasConsistentPermanentLocation);
    items.forEach(ItemApiExamples::hasConsistentTemporaryLocation);
}
Also used : Response(org.folio.inventory.support.http.client.Response) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ApiTestSuite.getCanCirculateLoanType(api.ApiTestSuite.getCanCirculateLoanType) InstanceSamples.nod(api.support.InstanceSamples.nod) CoreMatchers(org.hamcrest.CoreMatchers) ApiTestSuite(api.ApiTestSuite) DateTimeZone(org.joda.time.DateTimeZone) URL(java.net.URL) ApiTestSuite.getDvdMaterialType(api.ApiTestSuite.getDvdMaterialType) ApiTestSuite.getMainLibraryLocation(api.ApiTestSuite.getMainLibraryLocation) TimeoutException(java.util.concurrent.TimeoutException) JsonArrayHelper(org.folio.inventory.support.JsonArrayHelper) DATE_KEY(org.folio.inventory.domain.items.CirculationNote.DATE_KEY) Item(org.folio.inventory.domain.items.Item) StringUtils(org.apache.commons.lang3.StringUtils) USER_ID(api.ApiTestSuite.USER_ID) InstanceSamples.girlOnTheTrain(api.support.InstanceSamples.girlOnTheTrain) FIRST_NAME_KEY(org.folio.inventory.domain.user.Personal.FIRST_NAME_KEY) Seconds(org.joda.time.Seconds) JsonObject(io.vertx.core.json.JsonObject) JUnitParamsRunner(junitparams.JUnitParamsRunner) NOTE_TYPE_KEY(org.folio.inventory.domain.items.CirculationNote.NOTE_TYPE_KEY) STAFF_ONLY_KEY(org.folio.inventory.domain.items.CirculationNote.STAFF_ONLY_KEY) ApiRoot(api.support.ApiRoot) CIRCULATION_NOTES_KEY(org.folio.inventory.domain.items.Item.CIRCULATION_NOTES_KEY) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ID_KEY(org.folio.inventory.domain.user.User.ID_KEY) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) InstanceSamples.smallAngryPlanet(api.support.InstanceSamples.smallAngryPlanet) Assert.assertFalse(org.junit.Assert.assertFalse) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) StringUtil.urlEncode(org.folio.util.StringUtil.urlEncode) Parameters(junitparams.Parameters) LAST_NAME_KEY(org.folio.inventory.domain.user.Personal.LAST_NAME_KEY) ResponseMatchers.hasValidationError(support.matchers.ResponseMatchers.hasValidationError) SOURCE_KEY(org.folio.inventory.domain.items.CirculationNote.SOURCE_KEY) ApiTestSuite.getReadingRoomLocation(api.ApiTestSuite.getReadingRoomLocation) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) Response(org.folio.inventory.support.http.client.Response) PERSONAL_KEY(org.folio.inventory.domain.user.User.PERSONAL_KEY) InstanceApiClient(api.support.InstanceApiClient) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) BusinessLogicInterfaceUrls.items(api.support.http.BusinessLogicInterfaceUrls.items) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) MalformedURLException(java.net.MalformedURLException) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Assert.assertNotNull(org.junit.Assert.assertNotNull) DateTime(org.joda.time.DateTime) Test(org.junit.Test) NOTE_KEY(org.folio.inventory.domain.items.CirculationNote.NOTE_KEY) ApiTests(api.support.ApiTests) ExecutionException(java.util.concurrent.ExecutionException) JsonArray(io.vertx.core.json.JsonArray) Matchers.hasItem(org.hamcrest.Matchers.hasItem) TextDateTimeMatcher.withinSecondsAfter(support.matchers.TextDateTimeMatcher.withinSecondsAfter) Assert(org.junit.Assert) ApiTestSuite.getThirdFloorLocation(api.ApiTestSuite.getThirdFloorLocation) SECONDS(java.util.concurrent.TimeUnit.SECONDS) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) 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