SystemRaiderImpl implements SystemRaider { @Override public String executeScript(String ip, String path, String... params) { String response; SessionFactory sessionFactory; try { sessionFactory = createSessionFactory(ip); scpScript(sessionFactory, path); response = executer(ip, params); } catch (JSchException e) { return "unable to connect to " + ip; } catch (IOException e) { return "unable to copy file to the host, error: " + e; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } return response; } SystemRaiderImpl(); @Override String executeScript(String ip, String path, String... params); @Override String executeScript(String ip, String path, List<String> params);  }
@Test public void executeTest() throws URISyntaxException { String path = getClass().getClassLoader().getResource("test.sh").getPath(); Assert.assertEquals("success",systemRaider.executeScript("127.0.0.1",path,"param1","param2")); }
@Test public void executeFileNotFoundTest(){ Assert.assertEquals("Failed","unable to copy file to the host, error: java.io.FileNotFoundException: invalid.sh (No such file or directory)",systemRaider.executeScript("127.0.0.1","invalid.sh","param1","param2")); }
@Test public void executeWithListOfParamsTest(){ String path = getClass().getClassLoader().getResource("test.sh").getPath(); List<String> params = new ArrayList<String>(); params.add("param1"); params.add("param2"); Assert.assertEquals("success",systemRaider.executeScript("127.0.0.1",path,params)); }