protected void parseScript(ElasticsearchClient client, Log log, Path path) { try (Stream<String> stream = Files.lines(path)) { stream.forEach(command -> { log.debug(String.format("Parsing command: %s", command)); ElasticsearchCommand esCommand = parseStringCommand(command); if (esCommand.isSkip() == false) { executeInitCommand(client, log, esCommand); } }); } catch (IOException e) { throw new ElasticsearchSetupException("Cannot read the init script file", e); } }
@Test(expected = ElasticsearchSetupException.class) public void parseStringCommandWith1Segment() { step.parseStringCommand("PUT"); }
@Test(expected = ElasticsearchSetupException.class) public void parseStringCommandWith2Segments() { step.parseStringCommand("PUT:index"); }
@Test(expected = IllegalArgumentException.class) public void parseStringCommandInvalidRequestMethod() { step.parseStringCommand("PAT:index:{}"); }
.parseStringCommand("PUT:load_test_index:{ \"settings\" : { \"number_of_shards\" : 1, \"number_of_replicas\" : 0 } }"); doReturn(esCommands[1]) .when(step) .parseStringCommand("PUT:load_test_index/test_type/1:{ \"name\" : \"alex\" }"); doReturn(esCommands[2]) .when(step) .parseStringCommand("DELETE:load_test_index/test_type/2:"); doReturn(esCommands[3]) .when(step) .parseStringCommand("POST:load_test_index/_refresh:{}"); doReturn(emptyCommand).when(step).parseStringCommand("# create the index"); doReturn(emptyCommand).when(step).parseStringCommand("# the index name is hardcoded"); doReturn(emptyCommand).when(step).parseStringCommand("# index a document"); doReturn(emptyCommand).when(step).parseStringCommand("# delete the 2nd document"); doReturn(emptyCommand).when(step).parseStringCommand("# refresh the index"); verify(step, times(12)).parseStringCommand(captor.capture());
@Test public void parseStringCommandSkip() { String command = " # comment"; ElasticsearchCommand esCommand = step.parseStringCommand(command); assertTrue(esCommand.isSkip()); }
@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()); }