Search in sources :

Example 6 with PrecedingSucceedingTitle

use of org.folio.rest.api.entities.PrecedingSucceedingTitle 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 7 with PrecedingSucceedingTitle

use of org.folio.rest.api.entities.PrecedingSucceedingTitle 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 8 with PrecedingSucceedingTitle

use of org.folio.rest.api.entities.PrecedingSucceedingTitle 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 9 with PrecedingSucceedingTitle

use of org.folio.rest.api.entities.PrecedingSucceedingTitle in project mod-inventory-storage by folio-org.

the class PrecedingSucceedingTitleTest method failedUpdatePrecedingSucceedingTitleCollectionWhenInstanceIsMissing.

@Test
public void failedUpdatePrecedingSucceedingTitleCollectionWhenInstanceIsMissing() throws Exception {
    String missedInstanceId = UUID.randomUUID().toString();
    PrecedingSucceedingTitle precedingSucceedingTitle1 = new PrecedingSucceedingTitle(missedInstanceId, null, null, null, null);
    PrecedingSucceedingTitle precedingSucceedingTitle2 = new PrecedingSucceedingTitle(null, missedInstanceId, null, null, null);
    var titles = new PrecedingSucceedingTitles(List.of(precedingSucceedingTitle1, precedingSucceedingTitle2));
    CompletableFuture<Response> putCompleted = new CompletableFuture<>();
    client.put(precedingSucceedingTitleUrl("/instances/" + missedInstanceId), titles.getJson(), TENANT_ID, ResponseHandler.any(putCompleted));
    Response response = putCompleted.get(10, SECONDS);
    assertThat(response.getStatusCode(), is(404));
    assertThat(response.getBody(), is("Instance not found"));
}
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) Test(org.junit.Test)

Example 10 with PrecedingSucceedingTitle

use of org.folio.rest.api.entities.PrecedingSucceedingTitle 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)

Aggregations

PrecedingSucceedingTitle (org.folio.rest.api.entities.PrecedingSucceedingTitle)14 Test (org.junit.Test)14 IndividualResource (org.folio.rest.support.IndividualResource)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 JsonArray (io.vertx.core.json.JsonArray)10 Response (org.folio.rest.support.Response)8 CompletableFuture (java.util.concurrent.CompletableFuture)3 PrecedingSucceedingTitles (org.folio.rest.api.entities.PrecedingSucceedingTitles)3 JsonObject (io.vertx.core.json.JsonObject)1