Search in sources :

Example 11 with ElasticsearchCommand

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());
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 12 with ElasticsearchCommand

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());
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 13 with ElasticsearchCommand

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);
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) Test(org.junit.Test)

Example 14 with ElasticsearchCommand

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);
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HashMap(java.util.HashMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Map(java.util.Map) Test(org.junit.Test)

Example 15 with ElasticsearchCommand

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");
}
Also used : ElasticsearchCommand(com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand) Test(org.junit.Test)

Aggregations

ElasticsearchCommand (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand)17 Test (org.junit.Test)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 ElasticsearchSetupException (com.github.alexcojocaru.mojo.elasticsearch.v2.ElasticsearchSetupException)7 HashMap (java.util.HashMap)4 ElasticsearchClientException (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClientException)3 Map (java.util.Map)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 List (java.util.List)2 ArgumentMatchers.anyMap (org.mockito.ArgumentMatchers.anyMap)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ClusterConfiguration (com.github.alexcojocaru.mojo.elasticsearch.v2.ClusterConfiguration)1 InstanceConfiguration (com.github.alexcojocaru.mojo.elasticsearch.v2.InstanceConfiguration)1 ElasticsearchClient (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchClient)1 RequestMethod (com.github.alexcojocaru.mojo.elasticsearch.v2.client.ElasticsearchCommand.RequestMethod)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1