Search in sources :

Example 26 with HoldingRequestBuilder

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

the class ItemApiTitleExamples method noTitleWhenHoldingOrInstanceNotFound.

@Ignore("mod-inventory-storage disallows this scenario, change to be isolated test")
@Test
public void noTitleWhenHoldingOrInstanceNotFound() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID firstInstanceId = instancesClient.create(InstanceRequestExamples.smallAngryPlanet()).getId();
    UUID firstHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(firstInstanceId).create()).getId();
    UUID firstItemId = itemsClient.create(ItemRequestExamples.basedUponSmallAngryPlanet().forHolding(firstHoldingId)).getId();
    UUID secondInstanceId = instancesClient.create(InstanceRequestExamples.temeraire()).getId();
    UUID secondHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(secondInstanceId).create()).getId();
    UUID secondItemId = itemsClient.create(ItemRequestExamples.basedUponTemeraire().forHolding(secondHoldingId)).getId();
    // Delete instance or holding
    instancesClient.delete(firstInstanceId);
    holdingsStorageClient.delete(secondHoldingId);
    List<JsonObject> fetchedItemsResponse = itemsClient.getAll();
    assertThat(fetchedItemsResponse.size(), is(2));
    JsonObject firstFetchedItem = getRecordById(fetchedItemsResponse, firstItemId).orElse(new JsonObject());
    assertThat("has no title", firstFetchedItem.containsKey("title"), is(false));
    JsonObject secondFetchedItem = getRecordById(fetchedItemsResponse, secondItemId).orElse(new JsonObject());
    assertThat("has no title", secondFetchedItem.containsKey("title"), is(false));
}
Also used : HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with HoldingRequestBuilder

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

the class ItemApiTitleExamples method titlesComeFromInstancesForMultipleMultipleItems.

@Test
public void titlesComeFromInstancesForMultipleMultipleItems() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    UUID firstInstanceId = instancesClient.create(InstanceRequestExamples.smallAngryPlanet()).getId();
    UUID firstHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(firstInstanceId)).getId();
    UUID firstItemId = itemsClient.create(ItemRequestExamples.basedUponSmallAngryPlanet().forHolding(firstHoldingId)).getId();
    UUID secondInstanceId = instancesClient.create(InstanceRequestExamples.temeraire()).getId();
    UUID secondHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(secondInstanceId)).getId();
    UUID secondItemId = itemsClient.create(ItemRequestExamples.basedUponTemeraire().forHolding(secondHoldingId)).getId();
    List<JsonObject> fetchedItemsResponse = itemsClient.getAll();
    assertThat(fetchedItemsResponse.size(), is(2));
    JsonObject firstFetchedItem = getRecordById(fetchedItemsResponse, firstItemId).orElse(new JsonObject());
    assertThat("has title from instance", firstFetchedItem.getString("title"), is("The Long Way to a Small, Angry Planet"));
    JsonObject secondFetchedItem = getRecordById(fetchedItemsResponse, secondItemId).orElse(new JsonObject());
    assertThat("has title from instance", secondFetchedItem.getString("title"), is("Temeraire"));
}
Also used : HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with HoldingRequestBuilder

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

the class ItemApiExamples method canDeleteAllItems.

@Test
public void canDeleteAllItems() 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"));
    itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("175848607547"));
    itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645334645247"));
    itemsClient.deleteAll();
    final var getAllCompleted = okapiClient.get(ApiRoot.items());
    Response getAllResponse = getAllCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(getAllResponse.getJson().getJsonArray("items").size(), is(0));
    assertThat(getAllResponse.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 29 with HoldingRequestBuilder

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

the class ItemApiExamples method cannotCreateSecondItemWithSameBarcode.

@Test
public void cannotCreateSecondItemWithSameBarcode() 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();
    JsonObject sameBarcodeItemRequest = new ItemRequestBuilder().forHolding(nodHoldingId).book().canCirculate().withBarcode("645398607547").create();
    final var createItemCompleted = okapiClient.post(ApiRoot.items(), sameBarcodeItemRequest);
    Response sameBarcodeCreateResponse = createItemCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(sameBarcodeCreateResponse.getStatusCode(), is(400));
    assertThat(sameBarcodeCreateResponse.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) Test(org.junit.Test)

Example 30 with HoldingRequestBuilder

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

the class MarkItemMissingApiTests method createInstanceAndHoldingsRecord.

@Before
public void createInstanceAndHoldingsRecord() throws Exception {
    final IndividualResource instance = instancesClient.create(smallAngryPlanet(UUID.randomUUID()));
    holdingsRecord = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instance.getId()));
}
Also used : HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) Before(org.junit.Before)

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