use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand in project elasticsearch-maven-plugin by alexcojocaru.
the class BootstrapClusterStepTest method parseStringCommandSkip.
@Test
public void parseStringCommandSkip() {
String command = " # comment";
ElasticsearchCommand esCommand = step.parseStringCommand(command);
assertTrue(esCommand.isSkip());
}
use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand in project elasticsearch-maven-plugin by alexcojocaru.
the class BootstrapClusterStepTest method parseStringCommandEmptyJson.
@Test
public void parseStringCommandEmptyJson() {
String command = "PUT:index/type/id:";
ElasticsearchCommand esCommand = step.parseStringCommand(command);
assertFalse(esCommand.isSkip());
assertEquals(RequestMethod.PUT, esCommand.getRequestMethod());
assertEquals("index/type/id", esCommand.getRelativeUrl());
assertEquals("", esCommand.getJson());
}
use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand in project elasticsearch-maven-plugin by alexcojocaru.
the class BootstrapClusterStepTest method testExecuteInitCommandWithException.
@Test(expected = ElasticsearchSetupException.class)
public void testExecuteInitCommandWithException() throws ElasticsearchClientException {
ElasticsearchCommand command = mock(ElasticsearchCommand.class);
when(command.getRequestMethod()).thenReturn(RequestMethod.DELETE);
when(command.getRelativeUrl()).thenReturn("index/type/id");
doThrow(ElasticsearchClientException.class).when(client).delete("/index/type/id");
step.executeInitCommand(client, log, command);
}
use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand in project elasticsearch-maven-plugin by alexcojocaru.
the class BootstrapClusterStepTest method testParseJson.
@SuppressWarnings("unchecked")
@Test
public void testParseJson() {
String jsonFile = "src/test/resources/init.json";
// there are 2 requests in the json file;
// mock two ElasticsearchCommand objects to be returned for each
ElasticsearchCommand esCommand1 = mock(ElasticsearchCommand.class);
ElasticsearchCommand esCommand2 = mock(ElasticsearchCommand.class);
doReturn(esCommand1, esCommand2).when(step).parseMapCommand(anyMap());
doNothing().when(step).executeInitCommand(eq(client), eq(log), eq(esCommand1));
doNothing().when(step).executeInitCommand(eq(client), eq(log), eq(esCommand2));
step.parseJson(client, log, Paths.get(jsonFile));
ArgumentCaptor<Map<String, Object>> captor = ArgumentCaptor.forClass(Map.class);
verify(step, times(2)).parseMapCommand(captor.capture());
// verify the first argument (ie. the first request in the json)
Map<String, Object> command1 = captor.getAllValues().get(0);
assertEquals(3, command1.size());
assertEquals("PUT", command1.get("method"));
assertEquals("load_test_index/test_type/1", command1.get("path"));
assertTrue(command1.get("payload") instanceof Map);
assertEquals(1, ((Map<String, String>) command1.get("payload")).size());
assertEquals("alex", ((Map<String, String>) command1.get("payload")).get("name"));
// verify the second argument (ie. the second request in the json)
Map<String, Object> command2 = captor.getAllValues().get(1);
assertEquals(2, command2.size());
assertEquals("POST", command2.get("method"));
assertEquals("load_test_index/_refresh", command2.get("path"));
verify(step).executeInitCommand(client, log, esCommand1);
verify(step).executeInitCommand(client, log, esCommand2);
}
use of com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand in project elasticsearch-maven-plugin by alexcojocaru.
the class BootstrapClusterStepTest method testExecuteInitCommandDelete.
@Test
public void testExecuteInitCommandDelete() throws ElasticsearchClientException {
ElasticsearchCommand command = mock(ElasticsearchCommand.class);
when(command.getRequestMethod()).thenReturn(RequestMethod.DELETE);
when(command.getRelativeUrl()).thenReturn("index/type/id");
step.executeInitCommand(client, log, command);
verify(client).delete("/index/type/id");
}
Aggregations