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 public void parseStringCommandSkip() { String command = " # comment"; ElasticsearchCommand esCommand = step.parseStringCommand(command); assertTrue(esCommand.isSkip()); }
when(emptyCommand.isSkip()).thenReturn(true); doReturn(emptyCommand).when(step).parseStringCommand("# create the index"); doReturn(emptyCommand).when(step).parseStringCommand("# the index name is hardcoded");
@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()); }
@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()); }