Search in sources :

Example 21 with HoldingRequestBuilder

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

the class HoldingsStorageTest method cannotCreateAHoldingsWithHRIDFailure.

@Test
public void cannotCreateAHoldingsWithHRIDFailure() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    log.info("Starting cannotCreateAHoldingsWithHRIDFailure");
    final UUID instanceId = UUID.randomUUID();
    instancesClient.create(smallAngryPlanet(instanceId));
    setHoldingsSequence(99_999_999_999L);
    final JsonObject goodHholdings = holdingsClient.create(new HoldingRequestBuilder().withId(UUID.randomUUID()).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getJson();
    assertThat(goodHholdings.getString("hrid"), is("ho99999999999"));
    final JsonObject badHoldings = new HoldingRequestBuilder().withId(UUID.randomUUID()).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE))).create();
    final CompletableFuture<Response> createCompleted = new CompletableFuture<>();
    client.post(holdingsStorageUrl(""), badHoldings, TENANT_ID, text(createCompleted));
    final Response response = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(response.getStatusCode(), is(HttpURLConnection.HTTP_INTERNAL_ERROR));
    assertThat(response.getBody(), isMaximumSequenceValueError("hrid_holdings_seq"));
    log.info("Finished cannotCreateAHoldingsWithHRIDFailure");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 22 with HoldingRequestBuilder

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

the class InstanceDomainEventTest method eventIsNotSentWhenRemoveFailed.

@Test
public void eventIsNotSentWhenRemoveFailed() {
    final var instance = instancesClient.create(smallAngryPlanet(UUID.randomUUID()));
    // create a holding so that instance is not allowed to be removed
    holdingsClient.create(new HoldingRequestBuilder().forInstance(instance.getId()).withPermanentLocation(mainLibraryLocationId));
    final Response removeResponse = instancesClient.attemptToDelete(instance.getId());
    assertThat(removeResponse.getStatusCode(), is(400));
    assertNoRemoveEvent(instance.getId().toString());
}
Also used : Response(org.folio.rest.support.Response) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) Test(org.junit.Test)

Example 23 with HoldingRequestBuilder

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

the class InstanceDomainEventTest method eventIsNotSentWhenRemoveAllFailed.

@Test
public void eventIsNotSentWhenRemoveAllFailed() {
    final var instance = instancesClient.create(smallAngryPlanet(UUID.randomUUID()));
    instancesClient.create(smallAngryPlanet(UUID.randomUUID()));
    // create a holding so that instance is not allowed to be removed
    holdingsClient.create(new HoldingRequestBuilder().forInstance(instance.getId()).withPermanentLocation(mainLibraryLocationId));
    final Response removeResponse = instancesClient.attemptDeleteAll();
    assertThat(removeResponse.getStatusCode(), is(500));
    assertNoRemoveEvent(instance.getId().toString());
}
Also used : Response(org.folio.rest.support.Response) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) Test(org.junit.Test)

Example 24 with HoldingRequestBuilder

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

the class InstanceStorageTest method canSearchByBarcodeAndPermanentLocation.

// This is intended to demonstrate usage of the two different views
@Test
public void canSearchByBarcodeAndPermanentLocation() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID smallAngryPlanetInstanceId = UUID.randomUUID();
    UUID mainLibrarySmallAngryHoldingId = UUID.randomUUID();
    createInstance(smallAngryPlanet(smallAngryPlanetInstanceId));
    createHoldings(new HoldingRequestBuilder().withId(mainLibrarySmallAngryHoldingId).withPermanentLocation(mainLibraryLocationId).forInstance(smallAngryPlanetInstanceId).create());
    createItem(new ItemRequestBuilder().forHolding(mainLibrarySmallAngryHoldingId).withBarcode("706949453641").withPermanentLoanType(canCirculateLoanTypeId).withMaterialType(bookMaterialTypeId).create());
    UUID annexSmallAngryHoldingId = UUID.randomUUID();
    createHoldings(new HoldingRequestBuilder().withId(annexSmallAngryHoldingId).withPermanentLocation(annexLibraryLocationId).forInstance(smallAngryPlanetInstanceId).create());
    createItem(new ItemRequestBuilder().forHolding(annexSmallAngryHoldingId).withBarcode("70704539201").withPermanentLoanType(canCirculateLoanTypeId).withMaterialType(bookMaterialTypeId).create());
    UUID nodInstanceId = UUID.randomUUID();
    UUID nodHoldingId = UUID.randomUUID();
    createInstance(nod(nodInstanceId));
    createHoldings(new HoldingRequestBuilder().withId(nodHoldingId).forInstance(nodInstanceId).withPermanentLocation(mainLibraryLocationId).create());
    createItem(new ItemRequestBuilder().forHolding(nodHoldingId).withMaterialType(bookMaterialTypeId).withPermanentLoanType(canCirculateLoanTypeId).withBarcode("766043059304").create());
    // Use == as exact match is intended for barcode and location ID
    canSort(String.format("item.barcode==706949453641 and holdingsRecords.permanentLocationId==%s", mainLibraryLocationId), "Long Way to a Small Angry Planet");
    canSort(String.format("((contributors =/@name \"becky\") and holdingsRecords.permanentLocationId=\"%s\")", mainLibraryLocationId), "Long Way to a Small Angry Planet");
    System.out.println("canSearchByBarcodeAndPermanentLocation");
}
Also used : HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) UUID(java.util.UUID) ItemRequestBuilder(org.folio.rest.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 25 with HoldingRequestBuilder

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

the class EffectiveLocationMigrationTest method canMigrateToEffectiveLocationForItemsWithPermanentLocationOnly.

@Test
public void canMigrateToEffectiveLocationForItemsWithPermanentLocationOnly() throws InterruptedException, ExecutionException, TimeoutException {
    holdingsClient.create(new HoldingRequestBuilder().withId(holdingsId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId));
    runSql(removeExistingField);
    RowSet<Row> result = runSql(query);
    assertEquals(result.rowCount(), 1);
    JsonObject entry = result.iterator().next().toJson();
    assertNull(entry.getJsonObject("jsonb").getString("effectiveLocationId"));
    runSql(SET_EFFECTIVE_LOCATION);
    RowSet<Row> migrationResult = runSql(query);
    assertEquals(migrationResult.rowCount(), 1);
    JsonObject migrationEntry = migrationResult.iterator().next().toJson();
    assertEquals(mainLibraryLocationId.toString(), migrationEntry.getJsonObject("jsonb").getString("effectiveLocationId"));
}
Also used : HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) Row(io.vertx.sqlclient.Row) Test(org.junit.Test)

Aggregations

HoldingRequestBuilder (org.folio.rest.support.builders.HoldingRequestBuilder)61 Test (org.junit.Test)55 UUID (java.util.UUID)53 JsonObject (io.vertx.core.json.JsonObject)39 JsonArray (io.vertx.core.json.JsonArray)31 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)19 URL (java.net.URL)16 CompletableFuture (java.util.concurrent.CompletableFuture)15 Response (org.folio.rest.support.Response)6 ItemRequestBuilder (org.folio.rest.support.builders.ItemRequestBuilder)6 IndividualResource (org.folio.rest.support.IndividualResource)4 ArrayList (java.util.ArrayList)3 Row (io.vertx.sqlclient.Row)2 Vertx (io.vertx.core.Vertx)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HttpURLConnection (java.net.HttpURLConnection)1