use of io.searchbox.core.Ping in project graylog2-server by Graylog2.
the class JestUtilsTest method executeWithUnsuccessfulResponseAndErrorDetails.
@Test
public void executeWithUnsuccessfulResponseAndErrorDetails() throws Exception {
final Ping request = new Ping.Builder().build();
final JestResult resultMock = mock(JestResult.class);
when(resultMock.isSucceeded()).thenReturn(false);
final ObjectNode rootCauseStub = objectMapper.createObjectNode();
rootCauseStub.set("reason", new TextNode("foobar"));
final ArrayNode rootCausesStub = objectMapper.createArrayNode();
rootCausesStub.add(rootCauseStub);
final ObjectNode errorStub = objectMapper.createObjectNode();
errorStub.set("root_cause", rootCausesStub);
final ObjectNode responseStub = objectMapper.createObjectNode();
responseStub.set("error", errorStub);
when(resultMock.getJsonObject()).thenReturn(responseStub);
when(clientMock.execute(request)).thenReturn(resultMock);
try {
JestUtils.execute(clientMock, request, () -> "BOOM");
fail("Expected ElasticsearchException to be thrown");
} catch (ElasticsearchException e) {
assertThat(e).hasMessageStartingWith("BOOM").hasMessageEndingWith("foobar").hasNoSuppressedExceptions();
assertThat(e.getErrorDetails()).containsExactly("foobar");
}
}
use of io.searchbox.core.Ping in project graylog2-server by Graylog2.
the class JestUtilsTest method executeWithIOException.
@Test
public void executeWithIOException() throws Exception {
final Ping request = new Ping.Builder().build();
when(clientMock.execute(request)).thenThrow(IOException.class);
expectedException.expect(ElasticsearchException.class);
expectedException.expectMessage("BOOM");
JestUtils.execute(clientMock, request, () -> "BOOM");
}
use of io.searchbox.core.Ping in project graylog2-server by Graylog2.
the class JestUtilsTest method executeWithSuccessfulResponse.
@Test
public void executeWithSuccessfulResponse() throws Exception {
final Ping request = new Ping.Builder().build();
final JestResult resultMock = mock(JestResult.class);
when(resultMock.isSucceeded()).thenReturn(true);
when(clientMock.execute(request)).thenReturn(resultMock);
final JestResult result = JestUtils.execute(clientMock, request, () -> "BOOM");
assertThat(result.isSucceeded()).isTrue();
}
use of io.searchbox.core.Ping in project graylog2-server by Graylog2.
the class JestUtilsTest method executeFailsWithCustomMessage.
@Test
public void executeFailsWithCustomMessage() throws Exception {
final Ping request = new Ping.Builder().build();
final JestResult resultMock = mock(JestResult.class);
when(resultMock.isSucceeded()).thenReturn(false);
final ObjectNode responseStub = objectMapper.createObjectNode();
final ObjectNode errorStub = objectMapper.createObjectNode();
responseStub.set("Message", new TextNode("Authorization header requires 'Credential' parameter."));
errorStub.set("error", responseStub);
when(resultMock.getJsonObject()).thenReturn(errorStub);
when(clientMock.execute(request)).thenReturn(resultMock);
try {
JestUtils.execute(clientMock, request, () -> "BOOM");
fail("Expected ElasticsearchException to be thrown");
} catch (ElasticsearchException e) {
assertThat(e).hasMessageStartingWith("BOOM").hasMessageEndingWith("{\"Message\":\"Authorization header requires 'Credential' parameter.\"}").hasNoSuppressedExceptions();
assertThat(e.getErrorDetails()).containsExactly("{\"Message\":\"Authorization header requires 'Credential' parameter.\"}");
}
}
use of io.searchbox.core.Ping in project graylog2-server by Graylog2.
the class JestUtilsTest method executeWithUnsuccessfulResponse.
@Test
public void executeWithUnsuccessfulResponse() throws Exception {
final Ping request = new Ping.Builder().build();
final JestResult resultMock = mock(JestResult.class);
when(resultMock.isSucceeded()).thenReturn(false);
when(resultMock.getJsonObject()).thenReturn(objectMapper.createObjectNode());
when(clientMock.execute(request)).thenReturn(resultMock);
expectedException.expect(ElasticsearchException.class);
expectedException.expectMessage("BOOM");
JestUtils.execute(clientMock, request, () -> "BOOM");
}
Aggregations