StormCLIWrapper { protected String stormClientVersionInstalled() throws RestException { String stormClientVersionInstalled = "Storm client is not installed"; ProcessBuilder pb = getProcessBuilder("storm", "version"); pb.redirectErrorStream(true); Process p; try { p = pb.start(); } catch (IOException e) { throw new RestException(e); } BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8)); List<String> lines = reader.lines().collect(toList()); lines.forEach(System.out::println); if (lines.size() > 1) { stormClientVersionInstalled = lines.get(1).replaceFirst("Storm ", ""); } return stormClientVersionInstalled; }  @Autowired void setEnvironment(final Environment environment); int startParserTopology(String name); int stopParserTopology(String name, boolean stopNow); int startEnrichmentTopology(); int stopEnrichmentTopology(boolean stopNow); int startIndexingTopology(String scriptPath); int stopIndexingTopology(String name, boolean stopNow); Map<String, String> getStormClientStatus();  }
@Test public void stormClientVersionInstalledShouldReturnDefault() throws Exception { Process process = mock(Process.class); InputStream inputStream = new ByteArrayInputStream("".getBytes(UTF_8)); when(processBuilder.start()).thenReturn(process); when(process.getInputStream()).thenReturn(inputStream); assertEquals("Storm client is not installed", stormCLIWrapper.stormClientVersionInstalled()); }
@Test public void stormClientVersionInstalledShouldReturnRestExceptionOnError() throws Exception { when(processBuilder.start()).thenThrow(new IOException()); assertThrows(RestException.class, () -> stormCLIWrapper.stormClientVersionInstalled()); }