@Test(expected = ElasticsearchSetupException.class) public void testValidateFile() { step.validateFile("not_a_file"); }
@Test public void testExecuteJsonFile() { String filePath = "folder/init.json"; when(config.getPathInitScript()).thenReturn(filePath); doNothing().when(step).validateFile(filePath); doNothing() .when(step) .parseJson(any(ElasticsearchClient.class), eq(log), any(Path.class)); step.execute(config); verify(step).validateFile(filePath); ArgumentCaptor<Path> pathCaptor = ArgumentCaptor.forClass(Path.class); verify(step).parseJson(any(ElasticsearchClient.class), eq(log), pathCaptor.capture()); assertEquals(filePath, pathCaptor.getValue().toString().replace('\\', '/')); }
@Test public void testExecuteScriptFile() { String filePath = "folder/init.script"; when(config.getPathInitScript()).thenReturn(filePath); doNothing().when(step).validateFile(filePath); doNothing() .when(step) .parseScript(any(ElasticsearchClient.class), eq(log), any(Path.class)); step.execute(config); verify(step).validateFile(filePath); ArgumentCaptor<Path> pathCaptor = ArgumentCaptor.forClass(Path.class); verify(step).parseScript(any(ElasticsearchClient.class), eq(log), pathCaptor.capture()); assertEquals(filePath, pathCaptor.getValue().toString().replace('\\', '/')); }
@Override public void execute(ClusterConfiguration config) { if (StringUtils.isBlank(config.getPathInitScript())) { // nothing to do; return return; } String filePath = config.getPathInitScript(); validateFile(filePath); // we'll run all commands against the first node in the cluster ElasticsearchClient client = new ElasticsearchClient.Builder() .withInstanceConfiguration(config.getInstanceConfigurationList().get(0)) .withHostname("localhost") .build(); Path path = Paths.get(filePath); if ("json".equalsIgnoreCase(FilenameUtils.getExtension(filePath))) { parseJson(client, config.getLog(), path); } else { parseScript(client, config.getLog(), path); } }