Search in sources :

Example 1 with HoldingRequestBuilder

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

the class HoldingsSourceTest method canAssociateSourceWithHolding.

@Test
public void canAssociateSourceWithHolding() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID instanceId = UUID.randomUUID();
    UUID sourceId = UUID.randomUUID();
    JsonObject instanceToCreate = new JsonObject();
    instanceToCreate.put("id", instanceId.toString());
    instanceToCreate.put("source", "Test Source");
    instanceToCreate.put("title", "Test Instance");
    instanceToCreate.put("instanceTypeId", "535e3160-763a-42f9-b0c0-d8ed7df6e2a2");
    instancesClient.create(instanceToCreate);
    holdingsSourceClient.create(new JsonObject().put("id", sourceId.toString()).put("name", "associatable source")).getJson();
    IndividualResource holdingsResponse = holdingsClient.create(new HoldingRequestBuilder().withId(UUID.randomUUID()).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withSource(sourceId));
    assertThat(holdingsResponse.getJson().getString("sourceId"), is(sourceId.toString()));
}
Also used : HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 2 with HoldingRequestBuilder

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

the class HoldingsSourceTest method canNotRemoveHoldingsSourcesAttachedToHoldings.

@Test
public void canNotRemoveHoldingsSourcesAttachedToHoldings() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID instanceId = UUID.randomUUID();
    UUID sourceId = UUID.randomUUID();
    JsonObject instanceToCreate = new JsonObject();
    instanceToCreate.put("id", instanceId.toString());
    instanceToCreate.put("source", "Test Source");
    instanceToCreate.put("title", "Test Instance");
    instanceToCreate.put("instanceTypeId", "535e3160-763a-42f9-b0c0-d8ed7df6e2a2");
    instancesClient.create(instanceToCreate);
    holdingsSourceClient.create(new JsonObject().put("id", sourceId.toString()).put("name", "associated source")).getJson();
    holdingsClient.create(new HoldingRequestBuilder().withId(UUID.randomUUID()).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withSource(sourceId));
    Response sourceDeleteResponse = holdingsSourceClient.attemptToDelete(sourceId);
    // the associated source should not have been deleted:
    assertThat(sourceDeleteResponse.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
}
Also used : Response(org.folio.rest.support.Response) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with HoldingRequestBuilder

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

the class HoldingsStorageTest method canGetAllHoldings.

@Test
public void canGetAllHoldings() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID firstInstanceId = UUID.randomUUID();
    UUID secondInstanceId = UUID.randomUUID();
    UUID thirdInstanceId = UUID.randomUUID();
    instancesClient.create(smallAngryPlanet(firstInstanceId));
    instancesClient.create(nod(secondInstanceId));
    instancesClient.create(uprooted(thirdInstanceId));
    UUID firstHoldingId = holdingsClient.create(new HoldingRequestBuilder().forInstance(firstInstanceId).withPermanentLocation(mainLibraryLocationId)).getId();
    UUID secondHoldingId = holdingsClient.create(new HoldingRequestBuilder().forInstance(secondInstanceId).withPermanentLocation(annexLibraryLocationId)).getId();
    UUID thirdHoldingId = holdingsClient.create(new HoldingRequestBuilder().forInstance(thirdInstanceId).withPermanentLocation(mainLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getId();
    CompletableFuture<Response> getCompleted = new CompletableFuture<>();
    client.get(holdingsStorageUrl(""), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    Response response = getCompleted.get(5, TimeUnit.SECONDS);
    JsonObject responseBody = response.getJson();
    List<JsonObject> allHoldings = JsonArrayHelper.toList(responseBody.getJsonArray("holdingsRecords"));
    assertThat(allHoldings.size(), is(3));
    assertThat(responseBody.getInteger("totalRecords"), is(3));
    assertThat(allHoldings.stream().anyMatch(filterById(firstHoldingId)), is(true));
    assertThat(allHoldings.stream().anyMatch(filterById(secondHoldingId)), is(true));
    assertThat(allHoldings.stream().anyMatch(filterById(thirdHoldingId)), is(true));
}
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 4 with HoldingRequestBuilder

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

the class HoldingsStorageTest method cannotCreateAHoldingsWhenDuplicateHRIDIsSupplied.

@Test
public void cannotCreateAHoldingsWhenDuplicateHRIDIsSupplied() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    log.info("Starting cannotCreateAHoldingsWhenDuplicateHRIDIsSupplied");
    final UUID instanceId = UUID.randomUUID();
    instancesClient.create(smallAngryPlanet(instanceId));
    final UUID holdingsId = UUID.randomUUID();
    setHoldingsSequence(1);
    final JsonObject holdings = holdingsClient.create(new HoldingRequestBuilder().withId(holdingsId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getJson();
    assertThat(holdings.getString("hrid"), is("ho00000000001"));
    final Response getResponse = holdingsClient.getById(holdingsId);
    assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    final JsonObject holdingsFromGet = getResponse.getJson();
    assertThat(holdingsFromGet.getString("hrid"), is("ho00000000001"));
    final JsonObject duplicateHoldings = new HoldingRequestBuilder().withId(UUID.randomUUID()).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE))).withHrid("ho00000000001").create();
    final Response duplicateResponse = create(holdingsStorageUrl(""), duplicateHoldings);
    assertThat(duplicateResponse.getStatusCode(), is(422));
    final Errors errors = duplicateResponse.getJson().mapTo(Errors.class);
    assertThat(errors, notNullValue());
    assertThat(errors.getErrors(), notNullValue());
    assertThat(errors.getErrors().size(), is(1));
    assertThat(errors.getErrors().get(0), notNullValue());
    assertThat(errors.getErrors().get(0).getMessage(), containsString("value already exists in table holdings_record: ho00000000001"));
    assertThat(errors.getErrors().get(0).getParameters(), notNullValue());
    assertThat(errors.getErrors().get(0).getParameters().size(), is(1));
    assertThat(errors.getErrors().get(0).getParameters().get(0), notNullValue());
    assertThat(errors.getErrors().get(0).getParameters().get(0).getKey(), is("lower(f_unaccent(jsonb ->> 'hrid'::text))"));
    assertThat(errors.getErrors().get(0).getParameters().get(0).getValue(), is("ho00000000001"));
    log.info("Finished cannotCreateAHoldingsWhenDuplicateHRIDIsSupplied");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Errors(org.folio.rest.jaxrs.model.Errors) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with HoldingRequestBuilder

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

the class HoldingsStorageTest method updatingHoldingsUpdatesItemEffectiveCallNumberPrefix.

@Test
public void updatingHoldingsUpdatesItemEffectiveCallNumberPrefix() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID instanceId = UUID.randomUUID();
    instancesClient.create(smallAngryPlanet(instanceId));
    UUID holdingId = UUID.randomUUID();
    JsonObject holding = holdingsClient.create(new HoldingRequestBuilder().withId(holdingId).forInstance(instanceId).withPermanentLocation(mainLibraryLocationId).withCallNumberPrefix("testCallNumberPrefix").withTags(new JsonObject().put("tagList", new JsonArray().add(TAG_VALUE)))).getJson();
    JsonObject itemToCreate = new JsonObject();
    itemToCreate.put("holdingsRecordId", holdingId.toString());
    itemToCreate.put("status", new JsonObject().put("name", "Available"));
    itemToCreate.put("permanentLoanTypeId", canCirculateLoanTypeID);
    itemToCreate.put("temporaryLocationId", annexLibraryLocationId.toString());
    itemToCreate.put("materialTypeId", bookMaterialTypeID);
    Response postFirstItemResponse = create(itemsStorageUrl(""), itemToCreate);
    Response postSecondItemResponse = create(itemsStorageUrl(""), itemToCreate);
    assertThat(postFirstItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
    assertThat(postSecondItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));
    JsonObject firstItem = postFirstItemResponse.getJson();
    JsonObject secondItem = postSecondItemResponse.getJson();
    String firstItemId = firstItem.getString("id");
    String secondItemId = secondItem.getString("id");
    assertThat(firstItemId, is(notNullValue()));
    assertThat(secondItemId, is(notNullValue()));
    URL getFirstItemUrl = itemsStorageUrl(String.format("/%s", firstItemId));
    URL getSecondItemUrl = itemsStorageUrl(String.format("/%s", secondItemId));
    Response getFirstItemResponse = get(getFirstItemUrl);
    Response getSecondItemResponse = get(getSecondItemUrl);
    JsonObject firstItemFromGet = getFirstItemResponse.getJson();
    JsonObject secondItemFromGet = getSecondItemResponse.getJson();
    assertThat(firstItemFromGet.getString("id"), is(firstItemId));
    assertThat(firstItemFromGet.getString("holdingsRecordId"), is(holdingId.toString()));
    assertThat(firstItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("testCallNumberPrefix"));
    assertThat(secondItemFromGet.getString("id"), is(secondItemId));
    assertThat(secondItemFromGet.getString("holdingsRecordId"), is(holdingId.toString()));
    assertThat(secondItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("testCallNumberPrefix"));
    URL holdingsUrl = holdingsStorageUrl(String.format("/%s", holdingId));
    holding.remove("callNumberPrefix");
    holding.put("callNumberPrefix", "updatedCallNumberPrefix");
    Response putResponse = update(holdingsUrl, holding);
    assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
    assertThat(holding.getString("callNumberPrefix"), is("updatedCallNumberPrefix"));
    Response getFirstUpdatedItemResponse = get(getFirstItemUrl);
    Response getSecondUpdatedItemResponse = get(getSecondItemUrl);
    JsonObject firstUpdatedItemFromGet = getFirstUpdatedItemResponse.getJson();
    JsonObject secondUpdatedItemFromGet = getSecondUpdatedItemResponse.getJson();
    assertThat(getFirstUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    assertThat(firstUpdatedItemFromGet.getString("id"), is(firstItemId));
    assertThat(firstUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("updatedCallNumberPrefix"));
    assertThat(getSecondUpdatedItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    assertThat(secondUpdatedItemFromGet.getString("id"), is(secondItemId));
    assertThat(secondUpdatedItemFromGet.getJsonObject("effectiveCallNumberComponents").getString("prefix"), is("updatedCallNumberPrefix"));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HoldingRequestBuilder(org.folio.rest.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UUID(java.util.UUID) URL(java.net.URL) 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