Search in sources :

Example 21 with HoldingRequestBuilder

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

the class BoundWithTests method boundWithFlagsArePresentOnInstancesAndItemsAsExpected.

@Test
public void boundWithFlagsArePresentOnInstancesAndItemsAsExpected() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    IndividualResource instance1 = instancesStorageClient.create(InstanceSamples.smallAngryPlanet(UUID.randomUUID()));
    IndividualResource holdings1a = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instance1.getId()).permanentlyInMainLibrary().withCallNumber("HOLDINGS 1A"));
    IndividualResource item1a = itemsClient.create(new ItemRequestBuilder().forHolding(holdings1a.getId()).withBarcode("ITEM 1A"));
    IndividualResource instance2 = instancesStorageClient.create(InstanceSamples.girlOnTheTrain(UUID.randomUUID()));
    IndividualResource holdings2a = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instance2.getId()).permanentlyInMainLibrary().withCallNumber("HOLDINGS 2A"));
    IndividualResource item2a = itemsClient.create(new ItemRequestBuilder().forHolding(holdings2a.getId()).withBarcode("ITEM 2A"));
    IndividualResource instance3 = instancesStorageClient.create(InstanceSamples.leviathanWakes(UUID.randomUUID()));
    IndividualResource holdings3a = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instance3.getId()).permanentlyInMainLibrary().withCallNumber("HOLDINGS 3A"));
    IndividualResource item3a = itemsClient.create(new ItemRequestBuilder().forHolding(holdings3a.getId()).withBarcode("ITEM 3A"));
    // Adding 'holdings2a' to bound-with item 'item1a' means
    // 'item1a' becomes a bound-with and
    // 'holdings2a' becomes a bound-with part
    // 'holdings1a' becomes a bound-with part, inferred by it's direct relation to bound-with item 'item1a'
    // 'instance1' becomes a bound-with part (through holdings1a)
    // 'instance2' becomes a bound-with part (through holdings2a)
    // 'item2a' and 'item3a' are not bound-with items
    // 'holdings3a', 'instance3a' are not parts of any bound-with
    JsonObject boundWithPart = makeObjectBoundWithPart(item1a.getJson().getString("id"), holdings2a.getJson().getString("id"));
    boundWithPartsStorageClient.create(boundWithPart);
    for (JsonObject item : itemsClient.getAll()) {
        if (item.getString("id").equals(item1a.getJson().getString("id"))) {
            assertThat("Item1a is bound-with " + item.encodePrettily(), item.getBoolean("isBoundWith"), is(true));
        } else if (item.getString("id").equals(item2a.getJson().getString("id"))) {
            assertThat("Item2a is NOT bound-with " + item.encodePrettily(), item.getBoolean("isBoundWith"), is(false));
        } else if (item.getString("id").equals(item3a.getJson().getString("id"))) {
            assertThat("Item3a is NOT bound-with " + item.encodePrettily(), item.getBoolean("isBoundWith"), is(false));
        } else {
            fail("Unexpected item received from storage: " + item.encodePrettily());
        }
    }
    for (JsonObject instance : instancesClient.getAll()) {
        if (instance.getString("id").equals(instance1.getJson().getString("id"))) {
            assertThat("Instance 1 is bound-with: " + instance.encodePrettily(), instance.getBoolean("isBoundWith"), is(true));
        } else if (instance.getString("id").equals(instance2.getJson().getString("id"))) {
            assertThat("Instance 2 is bound-with: " + instance.encodePrettily(), instance.getBoolean("isBoundWith"), is(true));
        } else if (instance.getString("id").equals(instance3.getJson().getString("id"))) {
            assertThat("Instance 3 is NOT bound-with: " + instance.encodePrettily(), instance.getBoolean("isBoundWith"), is(false));
        } else {
            fail("Unexpected Instance received from storage: " + instance.encodePrettily());
        }
    }
    Response instance1byId = instancesClient.getById(instance1.getId());
    assertThat("Instance 1 fetched by ID is bound-with", instance1byId.getJson().getBoolean("isBoundWith"), is(true));
    Response instance3byId = instancesClient.getById(instance3.getId());
    assertThat("instance 3 fetched by ID is NOT bound-with", instance3byId.getJson().getBoolean("isBoundWith"), is(false));
    Response item1byId = itemsClient.getById(item1a.getId());
    assertThat("Item 1 fetched by ID is a bound-with", item1byId.getJson().getBoolean("isBoundWith"), is(true));
    Response item2byId = itemsClient.getById(item2a.getId());
    assertThat("Item 2 fetched by ID is NOT a bound-with", item2byId.getJson().getBoolean("isBoundWith"), is(false));
}
Also used : Response(org.folio.inventory.support.http.client.Response) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 22 with HoldingRequestBuilder

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

the class HoldingsApiExamples method canUpdateAnExistingHoldings.

@Test
public void canUpdateAnExistingHoldings() throws Exception {
    UUID instanceId = instancesClient.create(InstanceRequestExamples.smallAngryPlanet()).getId();
    String adminNote = "This is a note.";
    List<String> administrativeNotes = new ArrayList<String>();
    administrativeNotes.add(adminNote);
    JsonObject newHoldings = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instanceId).withAdministrativeNotes(administrativeNotes)).getJson();
    JsonObject updateHoldingsRequest = newHoldings.copy().put("permanentLocationId", "fcd64ce1-6995-48f0-840e-89ffa2288371");
    Response putResponse = updateHoldings(updateHoldingsRequest);
    assertThat(putResponse.getStatusCode(), is(NO_CONTENT.code()));
    Response getResponse = holdingsStorageClient.getById(getId(newHoldings));
    assertThat(getResponse.getStatusCode(), is(OK.code()));
    JsonObject updatedHoldings = getResponse.getJson();
    assertThat(updatedHoldings.containsKey("administrativeNotes"), is(true));
    List<String> retrievedNotes = JsonArrayHelper.toListOfStrings(updatedHoldings.getJsonArray("administrativeNotes"));
    assertThat(retrievedNotes, contains(adminNote));
    assertThat(updatedHoldings.getString("id"), is(newHoldings.getString("id")));
    assertThat(updatedHoldings.getString("permanentLocationId"), is("fcd64ce1-6995-48f0-840e-89ffa2288371"));
}
Also used : Response(org.folio.inventory.support.http.client.Response) ArrayList(java.util.ArrayList) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 23 with HoldingRequestBuilder

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

the class HoldingsApiExamples method cannotUpdateAnHoldingsThatDoesNotExist.

@Test
public void cannotUpdateAnHoldingsThatDoesNotExist() throws Exception {
    UUID instanceId = instancesClient.create(InstanceRequestExamples.smallAngryPlanet()).getId();
    JsonObject updateHoldingsRequest = new HoldingRequestBuilder().forInstance(instanceId).create();
    Response putResponse = updateHoldings(updateHoldingsRequest);
    assertThat(putResponse.getStatusCode(), is(NOT_FOUND.code()));
    assertThat(putResponse.getBody(), is("Holdings not found"));
}
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) Test(org.junit.Test)

Example 24 with HoldingRequestBuilder

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

the class HoldingsApiExamples method canNotUpdateAnExistingMARCHoldingsIfBlockedFieldsAreChanged.

@Test
public void canNotUpdateAnExistingMARCHoldingsIfBlockedFieldsAreChanged() throws Exception {
    UUID instanceId = instancesClient.create(InstanceRequestExamples.smallAngryPlanet()).getId();
    JsonObject newHoldings = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instanceId).withMarcSource()).getJson();
    JsonObject holdingsForUpdate = marcHoldingsWithDefaultBlockedFields(getId(newHoldings));
    for (String field : config.getHoldingsBlockedFields()) {
        Response putResponse = updateHoldings(holdingsForUpdate);
        assertThat(putResponse.getStatusCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
        assertThat(putResponse.getJson().getJsonArray("errors").size(), is(1));
        holdingsForUpdate.remove(field);
    }
}
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) Test(org.junit.Test)

Example 25 with HoldingRequestBuilder

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

the class ItemApiExamples method canRemoveBarcodeFromAnExistingItem.

@Test
public void canRemoveBarcodeFromAnExistingItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject smallAngryInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID smallAngryHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(smallAngryInstance.getString("id")))).getId();
    // Existing item with no barcode, to ensure empty barcode doesn't match
    itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().withNoBarcode());
    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();
    changedNodItem.remove("barcode");
    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().containsKey("barcode"), is(false));
}
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)

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