if (ElasticsearchCommand.RequestMethod.DELETE == esCommand.getRequestMethod())
switch (command.getRequestMethod()) default: throw new IllegalStateException(String.format( "Unsupported request method: %s", command.getRequestMethod()));
@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); }
@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"); }
@Test public void testExecuteInitCommandPut() throws ElasticsearchClientException { ElasticsearchCommand command = mock(ElasticsearchCommand.class); when(command.getRequestMethod()).thenReturn(RequestMethod.PUT); when(command.getJson()).thenReturn("json"); when(command.getRelativeUrl()).thenReturn("index/type/id"); step.executeInitCommand(client, log, command); verify(client).put("/index/type/id", "json"); }
@Test public void testExecuteInitCommandPost() throws ElasticsearchClientException { ElasticsearchCommand command = mock(ElasticsearchCommand.class); when(command.getRequestMethod()).thenReturn(RequestMethod.POST); when(command.getJson()).thenReturn("json"); when(command.getRelativeUrl()).thenReturn("index/type/id"); step.executeInitCommand(client, log, command); verify(client).post("/index/type/id", "json", String.class); }
@Test public void testParseMapCommand() { Map<String, Object> command = new HashMap<>(); command.put("method", "PUT"); command.put("path", "index_name"); Map<String, String> payload = new HashMap<>(); payload.put("attribute1", "value1"); payload.put("attribute2", "value2"); command.put("payload", payload); ElasticsearchCommand esCommand = step.parseMapCommand(command); assertEquals(RequestMethod.PUT, esCommand.getRequestMethod()); assertEquals("index_name", esCommand.getRelativeUrl()); assertEquals("{\"attribute1\":\"value1\",\"attribute2\":\"value2\"}", esCommand.getJson()); }
@Test public void testParseMapCommandDelete() { Map<String, Object> command = new HashMap<>(); command.put("method", "DELETE"); command.put("path", "index_name"); ElasticsearchCommand esCommand = step.parseMapCommand(command); assertEquals(RequestMethod.DELETE, esCommand.getRequestMethod()); assertEquals("index_name", esCommand.getRelativeUrl()); assertNull(esCommand.getJson()); }
@Test public void parseStringCommand() { 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()); }
@Test public void parseStringCommandWithSpaces() { String command = " PUT : index/type/id : { \"name\" : \"value\" } "; ElasticsearchCommand esCommand = step.parseStringCommand(command); assertFalse(esCommand.isSkip()); assertEquals(RequestMethod.PUT, esCommand.getRequestMethod()); assertEquals("index/type/id", esCommand.getRelativeUrl()); assertEquals("{ \"name\" : \"value\" }", esCommand.getJson()); }
@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()); }