Search in sources :

Example 31 with IndividualResource

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

the class InstanceDiscoverySuppressMigrationScriptTest method verifyNotSuppressed.

private void verifyNotSuppressed(List<IndividualResource> instances) throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    for (IndividualResource instance : instances) {
        Instance instanceInStorage = instancesClient.getById(instance.getId()).getJson().mapTo(Instance.class);
        assertThat(instanceInStorage.getDiscoverySuppress(), is(false));
    }
}
Also used : Instance(org.folio.rest.jaxrs.model.Instance) IndividualResource(org.folio.rest.support.IndividualResource)

Example 32 with IndividualResource

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

the class InstanceDiscoverySuppressMigrationScriptTest method discoverySuppressedInstancesAreNotUpdated.

@Test
public void discoverySuppressedInstancesAreNotUpdated() throws Exception {
    List<IndividualResource> notSuppressedInstances = createInstances(2);
    List<IndividualResource> suppressedInstances = new ArrayList<>(2);
    suppressedInstances.add(instancesClient.create(smallAngryPlanetSuppressedFromDiscovery()));
    suppressedInstances.add(instancesClient.create(smallAngryPlanetSuppressedFromDiscovery()));
    for (IndividualResource instance : notSuppressedInstances) {
        assertThat(unsetJsonbProperty("instance", instance.getId(), DISCOVERY_SUPPRESS).rowCount(), is(1));
    }
    executeMultipleSqlStatements(MIGRATION_SCRIPT);
    verifyNotSuppressed(notSuppressedInstances);
    verifySuppressed(suppressedInstances);
}
Also used : ArrayList(java.util.ArrayList) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 33 with IndividualResource

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

the class InstanceStorageTest method canPostSynchronousBatchWithExistingIdUpsertTrue.

@Test
public void canPostSynchronousBatchWithExistingIdUpsertTrue() throws Exception {
    UUID duplicateId = UUID.randomUUID();
    final IndividualResource existingInstance = createInstance(nod(duplicateId));
    final JsonObject firstInstanceToCreate = uprooted(UUID.randomUUID());
    final JsonObject instanceToUpdate = smallAngryPlanet(duplicateId);
    final JsonObject secondInstanceToCreate = temeraire(UUID.randomUUID());
    JsonArray instancesArray = new JsonArray();
    instancesArray.add(firstInstanceToCreate);
    instancesArray.add(instanceToUpdate);
    instancesArray.add(secondInstanceToCreate);
    JsonObject instanceCollection = new JsonObject().put(INSTANCES_KEY, instancesArray);
    Response response = instancesStorageSyncClient.attemptToCreate("?upsert=true", instanceCollection);
    assertThat(response, statusCodeIs(HttpStatus.HTTP_CREATED));
    assertExists(instancesArray.getJsonObject(0));
    assertExists(instancesArray.getJsonObject(1));
    assertExists(instancesArray.getJsonObject(2));
    Response getResponse = getById(duplicateId);
    assertThat(getResponse.getStatusCode(), is(HTTP_OK));
    JsonObject updatedInstance = getResponse.getJson();
    assertThat(updatedInstance.getString("title"), is("Long Way to a Small Angry Planet"));
    assertUpdateEventForInstance(existingInstance.getJson(), updatedInstance);
    assertCreateEventForInstance(getById(firstInstanceToCreate.getString("id")).getJson());
    assertCreateEventForInstance(getById(secondInstanceToCreate.getString("id")).getJson());
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) Response(org.folio.rest.support.Response) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 34 with IndividualResource

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

the class InstanceStorageTest method canDeleteAnInstance.

@Test
public void canDeleteAnInstance() throws InterruptedException, TimeoutException, ExecutionException {
    UUID id = UUID.randomUUID();
    JsonObject instanceToCreate = smallAngryPlanet(id);
    final IndividualResource createdInstance = createInstance(instanceToCreate);
    CompletableFuture<Response> deleteCompleted = new CompletableFuture<>();
    URL url = instancesStorageUrl(String.format("/%s", id));
    client.delete(url, TENANT_ID, ResponseHandler.empty(deleteCompleted));
    Response deleteResponse = deleteCompleted.get(5, SECONDS);
    assertThat(deleteResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
    assertGetNotFound(url);
    assertRemoveEventForInstance(createdInstance.getJson());
}
Also used : JsonErrorResponse(org.folio.rest.support.JsonErrorResponse) InstancesBatchResponse(org.folio.rest.jaxrs.model.InstancesBatchResponse) Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) URL(java.net.URL) Test(org.junit.Test)

Example 35 with IndividualResource

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

the class BoundWithStorageTest method cannotDeleteItemThatHasBoundWithParts.

@Test
public void cannotDeleteItemThatHasBoundWithParts() {
    IndividualResource instance1 = createInstance("Instance 1");
    IndividualResource holdingsRecord1 = createHoldingsRecord(instance1.getId());
    IndividualResource instance2 = createInstance("Instance 2");
    IndividualResource holdingsRecord2 = createHoldingsRecord(instance2.getId());
    IndividualResource item = createItem(holdingsRecord1.getId());
    boundWithPartsClient.create(createBoundWithPartJson(holdingsRecord1.getId(), item.getId()));
    boundWithPartsClient.create(createBoundWithPartJson(holdingsRecord2.getId(), item.getId()));
    Response deleteBoundWithItemResponse = itemsClient.attemptToDelete(item.getId());
    assertThat(deleteBoundWithItemResponse.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
}
Also used : Response(org.folio.rest.support.Response) IndividualResource(org.folio.rest.support.IndividualResource) 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