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));
}
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));
}
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));
}
Aggregations