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