Search in sources :

Example 46 with IndividualResource

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

the class PrecedingSucceedingTitleTest method cannotPutByInvalidPrecedingSucceedingId.

@Test
public void cannotPutByInvalidPrecedingSucceedingId() {
    IndividualResource instance1Resource = createInstance("Title One");
    JsonArray identifiers = new JsonArray();
    identifiers.add(identifier(UUID_ISBN, "9781473619777"));
    PrecedingSucceedingTitle precedingSucceedingTitle = new PrecedingSucceedingTitle(instance1Resource.getId().toString(), null, TITLE, HRID, identifiers);
    Response putResponse = precedingSucceedingTitleClient.attemptToReplace("abc", precedingSucceedingTitle.getJson());
    assertThat(putResponse.getStatusCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
    assertErrors(putResponse, INVALID_UUID_ERROR_MESSAGE);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.rest.support.Response) PrecedingSucceedingTitle(org.folio.rest.api.entities.PrecedingSucceedingTitle) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 47 with IndividualResource

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

the class PrecedingSucceedingTitleTest method canCreateUnconnectedPrecedingTitle.

@Test
public void canCreateUnconnectedPrecedingTitle() {
    IndividualResource instanceResource = createInstance("Title One");
    String instanceId = instanceResource.getId().toString();
    JsonArray identifiers = new JsonArray();
    identifiers.add(identifier(UUID_ISBN, "9781473619777"));
    PrecedingSucceedingTitle precedingSucceedingTitle = new PrecedingSucceedingTitle(null, instanceId, TITLE, HRID, identifiers);
    IndividualResource response = precedingSucceedingTitleClient.create(precedingSucceedingTitle.getJson());
    assertPrecedingSucceedingTitle(response, null, instanceId, TITLE, HRID, identifiers);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) PrecedingSucceedingTitle(org.folio.rest.api.entities.PrecedingSucceedingTitle) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 48 with IndividualResource

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

the class PrecedingSucceedingTitleTest method canUpdatePrecedingSucceedingTitleCollection.

@Test
public void canUpdatePrecedingSucceedingTitleCollection() throws Exception {
    IndividualResource instance1Resource = createInstance("Title One");
    String instanceId = instance1Resource.getId().toString();
    PrecedingSucceedingTitle precedingSucceedingTitle1 = new PrecedingSucceedingTitle(instanceId, null, null, null, null);
    precedingSucceedingTitleClient.create(precedingSucceedingTitle1.getJson());
    PrecedingSucceedingTitle precedingSucceedingTitle2 = new PrecedingSucceedingTitle(instanceId, null, null, null, null);
    precedingSucceedingTitleClient.create(precedingSucceedingTitle2.getJson());
    precedingSucceedingTitle1.put(PRECEDING_INSTANCE_ID_KEY, null);
    precedingSucceedingTitle1.put(SUCCEEDING_INSTANCE_ID_KEY, instanceId);
    precedingSucceedingTitle2.put(PRECEDING_INSTANCE_ID_KEY, null);
    precedingSucceedingTitle2.put(SUCCEEDING_INSTANCE_ID_KEY, instanceId);
    var titles = new PrecedingSucceedingTitles(List.of(precedingSucceedingTitle1, precedingSucceedingTitle2));
    CompletableFuture<Response> putCompleted = new CompletableFuture<>();
    client.put(precedingSucceedingTitleUrl("/instances/" + instanceId), titles.getJson(), TENANT_ID, ResponseHandler.empty(putCompleted));
    Response response = putCompleted.get(10, SECONDS);
    assertThat(response.getStatusCode(), is(204));
    var existedTitles = precedingSucceedingTitleClient.getByQuery(String.format("?query=succeedingInstanceId==(%s)+or+precedingInstanceId==(%s)", instanceId, instanceId));
    existedTitles.forEach(entry -> {
        assertThat(entry.getString("succeedingInstanceId"), equalTo(instanceId));
        assertThat(entry.getString("precedingInstanceId"), nullValue());
    });
    precedingSucceedingTitleClient.delete(UUID.fromString(existedTitles.get(0).getString("id")));
    precedingSucceedingTitleClient.delete(UUID.fromString(existedTitles.get(1).getString("id")));
}
Also used : Response(org.folio.rest.support.Response) CompletableFuture(java.util.concurrent.CompletableFuture) PrecedingSucceedingTitles(org.folio.rest.api.entities.PrecedingSucceedingTitles) PrecedingSucceedingTitle(org.folio.rest.api.entities.PrecedingSucceedingTitle) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 49 with IndividualResource

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

the class PrecedingSucceedingTitleTest method canUpdateUnconnectedPrecedingSucceedingTitle.

@Test
public void canUpdateUnconnectedPrecedingSucceedingTitle() {
    IndividualResource instance1Resource = createInstance("Title One");
    String instance1Id = instance1Resource.getId().toString();
    JsonArray identifiers = new JsonArray();
    identifiers.add(identifier(UUID_ISBN, "9781473619777"));
    PrecedingSucceedingTitle precedingSucceedingTitle = new PrecedingSucceedingTitle(instance1Id, null, TITLE, HRID, identifiers);
    IndividualResource response = precedingSucceedingTitleClient.create(precedingSucceedingTitle.getJson());
    IndividualResource instance2Resource = createInstance("Title Two");
    String instance2Id = instance2Resource.getId().toString();
    String newTitle = "New";
    String newHrid = "inst000000000133";
    JsonArray newIdentifiers = new JsonArray();
    newIdentifiers.add(identifier(UUID_ISBN, "1081473619777"));
    PrecedingSucceedingTitle newPrecedingSucceedingTitle = new PrecedingSucceedingTitle(instance2Id, instance1Id, newTitle, newHrid, newIdentifiers);
    precedingSucceedingTitleClient.replace(response.getId(), newPrecedingSucceedingTitle.getJson());
    assertPrecedingSucceedingTitle(response, instance2Id, instance1Id, newTitle, newHrid, newIdentifiers);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) PrecedingSucceedingTitle(org.folio.rest.api.entities.PrecedingSucceedingTitle) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 50 with IndividualResource

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

the class PrecedingSucceedingTitleTest method cannotCreatePrecedingSucceedingTitleWithNonExistingSucceedingInstance.

@Test
public void cannotCreatePrecedingSucceedingTitleWithNonExistingSucceedingInstance() {
    String nonExistingInstanceId = "14b65645-2e49-4a85-8dc1-43d444710570";
    IndividualResource instance1Response = createInstance("Title One");
    JsonArray identifiers = new JsonArray();
    identifiers.add(identifier(UUID_ISBN, "9781473619777"));
    PrecedingSucceedingTitle precedingSucceedingTitle = new PrecedingSucceedingTitle(instance1Response.getId().toString(), nonExistingInstanceId, TITLE, HRID, identifiers);
    Response response = precedingSucceedingTitleClient.attemptToCreate(precedingSucceedingTitle.getJson());
    assertThat(response.getStatusCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
    assertErrors(response, "Cannot set preceding_succeeding_title.succeedinginstanceid = " + "14b65645-2e49-4a85-8dc1-43d444710570 because it does not exist in instance.id.");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.rest.support.Response) PrecedingSucceedingTitle(org.folio.rest.api.entities.PrecedingSucceedingTitle) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) 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