Search in sources :

Example 1 with PrecedingSucceedingTitles

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

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

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

the class PrecedingSucceedingTitleTest method failedUpdatePrecedingSucceedingTitleCollectionWhenTitleNotContainsInstanceId.

@Test
public void failedUpdatePrecedingSucceedingTitleCollectionWhenTitleNotContainsInstanceId() throws Exception {
    String instanceId = UUID.randomUUID().toString();
    PrecedingSucceedingTitle precedingSucceedingTitle = new PrecedingSucceedingTitle(null, null, null, null, null);
    var titles = new PrecedingSucceedingTitles(List.of(precedingSucceedingTitle));
    CompletableFuture<Response> putCompleted = new CompletableFuture<>();
    client.put(precedingSucceedingTitleUrl("/instances/" + instanceId), titles.getJson(), TENANT_ID, ResponseHandler.any(putCompleted));
    Response response = putCompleted.get(10, SECONDS);
    assertThat(response.getStatusCode(), is(422));
    assertThat(response.getBody(), containsString("The precedingInstanceId or succeedingInstanceId should contain instanceId"));
}
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)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)3 PrecedingSucceedingTitle (org.folio.rest.api.entities.PrecedingSucceedingTitle)3 PrecedingSucceedingTitles (org.folio.rest.api.entities.PrecedingSucceedingTitles)3 Response (org.folio.rest.support.Response)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Test (org.junit.Test)3 IndividualResource (org.folio.rest.support.IndividualResource)1