Search in sources :

Example 26 with IndividualResource

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

the class InstanceStorageTest method updateInstance.

private IndividualResource updateInstance(JsonObject instance) {
    Response putResponse = update(instance);
    assertThat(putResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
    Response getResponse = getById(instance.getString("id"));
    assertThat(getResponse.getStatusCode(), is(HTTP_OK));
    return new IndividualResource(getResponse);
}
Also used : JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) Response(org.folio.rest.support.Response) IndividualResource(org.folio.rest.support.IndividualResource)

Example 27 with IndividualResource

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

the class ItemEffectiveCallNumberComponentsTest method canCalculateEffectiveCallNumberPropertyOnUpdate.

@Test
@Parameters(source = ItemEffectiveCallNumberComponentsTestData.class, method = "updatePropertiesParams")
@TestCaseName("[{index}]: {params}")
public void canCalculateEffectiveCallNumberPropertyOnUpdate(CallNumberComponentPropertyNames callNumberProperties, String holdingsInitValue, String holdingsTargetValue, String itemInitValue, String itemTargetValue) {
    final String holdingsPropertyName = callNumberProperties.holdingsPropertyName;
    final String itemPropertyName = callNumberProperties.itemPropertyName;
    final String effectivePropertyName = callNumberProperties.effectivePropertyName;
    final String initEffectiveValue = StringUtils.firstNonBlank(itemInitValue, holdingsInitValue);
    final String targetEffectiveValue = StringUtils.firstNonBlank(itemTargetValue, holdingsTargetValue);
    IndividualResource holdings = createHoldingsWithPropertySetAndInstance(holdingsPropertyName, holdingsInitValue);
    IndividualResource createdItem = itemsClient.create(nodWithNoBarcode(holdings.getId()).put(itemPropertyName, itemInitValue));
    JsonObject effectiveCallNumberComponents = createdItem.getJson().getJsonObject("effectiveCallNumberComponents");
    assertNotNull(effectiveCallNumberComponents);
    assertThat(effectiveCallNumberComponents.getString(effectivePropertyName), is(initEffectiveValue));
    holdingsClient.replace(holdings.getId(), getHoldingsById(holdings.getJson()).put(holdingsPropertyName, holdingsTargetValue));
    var itemAfterHoldingsUpdate = getById(createdItem.getJson());
    assertUpdateEventForItem(createdItem.getJson(), itemAfterHoldingsUpdate);
    if (!Objects.equals(itemInitValue, itemTargetValue)) {
        itemsClient.replace(createdItem.getId(), itemAfterHoldingsUpdate.copy().put(itemPropertyName, itemTargetValue));
        await().untilAsserted(() -> {
            var instanceId = holdings.getJson().getString("instanceId");
            var itemId = createdItem.getId().toString();
            var lastItemEvent = getLastItemEvent(instanceId, itemId);
            assertTrue(lastItemEvent.value().getJsonObject("new").getInteger("_version") > 1);
            assertUpdateEventForItem(itemAfterHoldingsUpdate, itemsClient.getById(createdItem.getId()).getJson());
        });
    }
    final JsonObject updatedItem = itemsClient.getById(createdItem.getId()).getJson();
    final JsonObject updatedEffectiveCallNumberComponents = updatedItem.getJsonObject("effectiveCallNumberComponents");
    assertNotNull(updatedEffectiveCallNumberComponents);
    assertThat(updatedEffectiveCallNumberComponents.getString(effectivePropertyName), is(targetEffectiveValue));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) Parameters(junitparams.Parameters) Test(org.junit.Test) TestCaseName(junitparams.naming.TestCaseName)

Example 28 with IndividualResource

use of org.folio.rest.support.IndividualResource 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 29 with IndividualResource

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

the class HoldingsSourceTest method canCreateHoldingsSourcesWithoutProvidingAnId.

@Test
public void canCreateHoldingsSourcesWithoutProvidingAnId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    IndividualResource sourceResponse = holdingsSourceClient.create(new JsonObject().put("name", "test source without id"));
    JsonObject source = sourceResponse.getJson();
    assertThat(source.getString("id"), is(notNullValue()));
    assertThat(source.getString("name"), is("test source without id"));
    UUID sourceId = sourceResponse.getId();
    Response getResponse = holdingsSourceClient.getById(sourceId);
    assertThat(getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject sourceFromGet = getResponse.getJson();
    assertThat(sourceFromGet.getString("id"), is(sourceId.toString()));
    assertThat(sourceFromGet.getString("name"), is("test source without id"));
}
Also used : Response(org.folio.rest.support.Response) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) UUID(java.util.UUID) Test(org.junit.Test)

Example 30 with IndividualResource

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

the class HoldingsSourceTest method canRemoveAHoldingsSource.

@Test
public void canRemoveAHoldingsSource() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    IndividualResource holdingsSource = holdingsSourceClient.create(new JsonObject().put("name", "deleteable source"));
    UUID deleteableHoldingsSourceId = holdingsSource.getId();
    holdingsSourceClient.delete(deleteableHoldingsSourceId);
    Response deleteResponse = holdingsSourceClient.getById(deleteableHoldingsSourceId);
    assertThat(deleteResponse.getStatusCode(), is(HttpURLConnection.HTTP_NOT_FOUND));
}
Also used : Response(org.folio.rest.support.Response) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

IndividualResource (org.folio.rest.support.IndividualResource)89 Test (org.junit.Test)73 JsonObject (io.vertx.core.json.JsonObject)44 UUID (java.util.UUID)37 Response (org.folio.rest.support.Response)20 CompletableFuture (java.util.concurrent.CompletableFuture)19 JsonArray (io.vertx.core.json.JsonArray)17 JsonResponse (org.folio.rest.support.JsonResponse)17 LoanRequestBuilder (org.folio.rest.support.builders.LoanRequestBuilder)17 DateTime (org.joda.time.DateTime)12 PrecedingSucceedingTitle (org.folio.rest.api.entities.PrecedingSucceedingTitle)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 TextResponse (org.folio.rest.support.TextResponse)7 ItemRequestBuilder (org.folio.rest.support.builders.ItemRequestBuilder)7 InstancesBatchResponse (org.folio.rest.jaxrs.model.InstancesBatchResponse)6 JsonErrorResponse (org.folio.rest.support.JsonErrorResponse)6 TRUE (java.lang.Boolean.TRUE)4 HttpURLConnection (java.net.HttpURLConnection)4 MalformedURLException (java.net.MalformedURLException)4 DateFormat (java.text.DateFormat)4