Search in sources :

Example 1 with EndpointFailureDescriptor

use of support.fakes.EndpointFailureDescriptor in project mod-inventory by folio-org.

the class InstanceRelationshipsTest method canForwardInstancePrecedingSucceedingTitlesFetchFailure.

@Test
public void canForwardInstancePrecedingSucceedingTitlesFetchFailure() throws Exception {
    final int expectedCount = 4;
    createPrecedingSucceedingInstances(expectedCount);
    final JsonObject expectedErrorResponse = new JsonObject().put("message", "Server error");
    precedingSucceedingTitlesClient.emulateFailure(new EndpointFailureDescriptor().setFailureExpireDate(DateTime.now().plusSeconds(2).toDate()).setStatusCode(500).setContentType("application/json").setBody(expectedErrorResponse.toString()).setMethod(HttpMethod.GET.name()));
    Response response = instancesClient.attemptGetMany("title=(\"preceding\" or \"succeeding\"", expectedCount);
    assertThat(response.getStatusCode(), is(500));
    assertThat(response.getContentType(), is("application/json"));
    assertThat(response.getJson(), is(expectedErrorResponse));
}
Also used : Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject) EndpointFailureDescriptor(support.fakes.EndpointFailureDescriptor) Test(org.junit.Test)

Example 2 with EndpointFailureDescriptor

use of support.fakes.EndpointFailureDescriptor in project mod-inventory by folio-org.

the class InstanceRelationshipsTest method canForwardInstancePrecedingSucceedingTitlesDeleteFailure.

@Test
public void canForwardInstancePrecedingSucceedingTitlesDeleteFailure() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID nodId = UUID.randomUUID();
    JsonObject succeedingTitle = new JsonObject().put("id", UUID.randomUUID().toString()).put("title", "A web semantic");
    JsonObject nod = nod(nodId).put("hrid", "inst0006320").put("succeedingTitles", new JsonArray().add(succeedingTitle));
    instancesClient.create(nod);
    final JsonObject expectedErrorResponse = new JsonObject().put("message", "Server error");
    precedingSucceedingTitlesClient.emulateFailure(new EndpointFailureDescriptor().setFailureExpireDate(DateTime.now().plusSeconds(2).toDate()).setStatusCode(500).setContentType("application/json").setBody(expectedErrorResponse.toString()).setMethod(HttpMethod.DELETE.name()));
    JsonObject newNod = nod.copy();
    newNod.put("succeedingTitles", new JsonArray());
    Response response = instancesClient.attemptToReplace(nodId, newNod);
    assertThat(response.getStatusCode(), is(500));
    assertThat(response.getContentType(), is("application/json"));
    assertThat(response.getJson(), is(expectedErrorResponse));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) EndpointFailureDescriptor(support.fakes.EndpointFailureDescriptor) Test(org.junit.Test)

Example 3 with EndpointFailureDescriptor

use of support.fakes.EndpointFailureDescriptor in project mod-inventory by folio-org.

the class InstancesApiExamples method canFrowardInstanceCreateFailureFromStorage.

@Test
public void canFrowardInstanceCreateFailureFromStorage() throws Exception {
    final String expectedErrorMessage = "Instance-storage is temporary unavailable for create";
    instancesStorageClient.emulateFailure(new EndpointFailureDescriptor().setFailureExpireDate(DateTime.now(UTC).plusSeconds(2).toDate()).setBody(expectedErrorMessage).setContentType("plain/text").setStatusCode(500).setMethod(POST.name()));
    final Response response = instancesClient.attemptToCreate(smallAngryPlanet(UUID.randomUUID()));
    assertThat(response.getStatusCode(), is(500));
    assertThat(response.getBody(), is(expectedErrorMessage));
}
Also used : Response(org.folio.inventory.support.http.client.Response) EndpointFailureDescriptor(support.fakes.EndpointFailureDescriptor) Test(org.junit.Test)

Example 4 with EndpointFailureDescriptor

use of support.fakes.EndpointFailureDescriptor in project mod-inventory by folio-org.

the class InstanceRelationshipsTest method canForwardInstancePrecedingSucceedingTitlesUpdateFailure.

@Test
public void canForwardInstancePrecedingSucceedingTitlesUpdateFailure() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID nodId = UUID.randomUUID();
    String titleId = UUID.randomUUID().toString();
    JsonObject succeedingTitle = new JsonObject().put("id", titleId).put("title", "A web semantic");
    JsonObject nod = nod(nodId).put("hrid", "inst0006320").put("succeedingTitles", new JsonArray().add(succeedingTitle));
    instancesClient.create(nod);
    final JsonObject expectedErrorResponse = new JsonObject().put("message", "Server error");
    precedingSucceedingTitlesClient.emulateFailure(new EndpointFailureDescriptor().setFailureExpireDate(DateTime.now().plusSeconds(2).toDate()).setStatusCode(500).setContentType("application/json").setBody(expectedErrorResponse.toString()).setMethod(HttpMethod.PUT.name()));
    JsonObject newSucceedingTitle = new JsonObject().put("id", titleId).put("succeedingInstanceId", UUID.randomUUID().toString());
    JsonArray succeedingTitles = new JsonArray().add(newSucceedingTitle);
    JsonObject newNod = nod.copy();
    newNod.put("succeedingTitles", succeedingTitles);
    Response response = instancesClient.attemptToReplace(nodId, newNod);
    assertThat(response.getStatusCode(), is(500));
    assertThat(response.getContentType(), is("application/json"));
    assertThat(response.getJson(), is(expectedErrorResponse));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) EndpointFailureDescriptor(support.fakes.EndpointFailureDescriptor) Test(org.junit.Test)

Example 5 with EndpointFailureDescriptor

use of support.fakes.EndpointFailureDescriptor in project mod-inventory by folio-org.

the class InstanceRelationshipsTest method canForwardInstanceRelationshipDeleteFailure.

@Test
public void canForwardInstanceRelationshipDeleteFailure() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID nodId = UUID.randomUUID();
    String boundWithInstanceRelationshipTypeId = instanceRelationshipTypeFixture.boundWith().getId();
    IndividualResource smallAngryPlanet = instancesClient.create(smallAngryPlanet(UUID.randomUUID()));
    JsonObject parentInstance = createParentRelationship(smallAngryPlanet.getId().toString(), boundWithInstanceRelationshipTypeId);
    JsonObject nod = nod(nodId).put("hrid", "inst0006320").put(PARENT_INSTANCES, new JsonArray().add(parentInstance));
    instancesClient.create(nod);
    final JsonObject expectedErrorResponse = new JsonObject().put("message", "Server error");
    instanceRelationshipClient.emulateFailure(new EndpointFailureDescriptor().setFailureExpireDate(DateTime.now().plusSeconds(2).toDate()).setStatusCode(500).setContentType("application/json").setBody(expectedErrorResponse.toString()).setMethod(HttpMethod.DELETE.name()));
    JsonObject newNod = nod.copy();
    newNod.put(PARENT_INSTANCES, new JsonArray());
    Response response = instancesClient.attemptToReplace(nodId, newNod);
    assertThat(response.getStatusCode(), is(500));
    assertThat(response.getContentType(), is("application/json"));
    assertThat(response.getJson(), is(expectedErrorResponse));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) EndpointFailureDescriptor(support.fakes.EndpointFailureDescriptor) Test(org.junit.Test)

Aggregations

Response (org.folio.inventory.support.http.client.Response)8 Test (org.junit.Test)8 EndpointFailureDescriptor (support.fakes.EndpointFailureDescriptor)8 JsonObject (io.vertx.core.json.JsonObject)6 JsonArray (io.vertx.core.json.JsonArray)5 UUID (java.util.UUID)4 IndividualResource (org.folio.inventory.support.http.client.IndividualResource)3