Search in sources :

Example 6 with EndpointFailureDescriptor

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

the class InstanceRelationshipsTest method canForwardInstanceRelationshipUpdateFailure.

@Test
public void canForwardInstanceRelationshipUpdateFailure() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID nodId = UUID.randomUUID();
    String parentInstanceId = UUID.randomUUID().toString();
    String boundWithInstanceRelationshipTypeId = instanceRelationshipTypeFixture.boundWith().getId();
    IndividualResource smallAngryPlanet = instancesClient.create(smallAngryPlanet(UUID.randomUUID()));
    JsonObject parentInstance = new JsonObject().put("id", parentInstanceId).put("superInstanceId", smallAngryPlanet.getId().toString()).put("instanceRelationshipTypeId", 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.PUT.name()));
    JsonObject newParentInstances = new JsonObject().put("id", parentInstanceId).put("superInstanceId", UUID.randomUUID().toString()).put("instanceRelationshipTypeId", boundWithInstanceRelationshipTypeId);
    JsonArray parentInstances = new JsonArray().add(newParentInstances);
    JsonObject newNod = nod.copy();
    newNod.put(PARENT_INSTANCES, parentInstances);
    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)

Example 7 with EndpointFailureDescriptor

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

the class InstancesApiExamples method canFrowardInstanceUpdateFailureFromStorage.

@Test
public void canFrowardInstanceUpdateFailureFromStorage() throws Exception {
    final String expectedErrorMessage = "Instance-storage is temporary unavailable for updates";
    final IndividualResource instance = instancesClient.create(smallAngryPlanet(UUID.randomUUID()));
    instancesStorageClient.emulateFailure(new EndpointFailureDescriptor().setFailureExpireDate(DateTime.now(UTC).plusSeconds(2).toDate()).setBody(expectedErrorMessage).setContentType("plain/text").setStatusCode(500).setMethod(PUT.name()));
    final Response updateResponse = instancesClient.attemptToReplace(instance.getId(), instance.getJson().copy().put("subjects", new JsonArray().add("Small angry planet subject")));
    assertThat(updateResponse.getStatusCode(), is(500));
    assertThat(updateResponse.getBody(), is(expectedErrorMessage));
}
Also used : Response(org.folio.inventory.support.http.client.Response) JsonArray(io.vertx.core.json.JsonArray) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) EndpointFailureDescriptor(support.fakes.EndpointFailureDescriptor) Test(org.junit.Test)

Example 8 with EndpointFailureDescriptor

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

the class InstanceRelationshipsTest method canForwardInstanceRelationshipsFetchFailure.

@Test
public void canForwardInstanceRelationshipsFetchFailure() throws Exception {
    final int expectedCount = 4;
    createSuperInstanceSubInstance(expectedCount);
    final JsonObject expectedErrorResponse = new JsonObject().put("message", "Can not fetch relationships");
    instanceRelationshipClient.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=(\"super\" or \"sub\"", 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)

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