@Test public void executeCommand() throws Exception { Assert.assertEquals("Expected \"valid output\", got", mockCommand("valid output"), service.executeCommand("test cmd")); Mockito.when(systemCall.execute(ArgumentMatchers.anyString())).thenThrow(new IOException()); Assert.assertEquals("Expected \"\", got", "", service.executeCommand("invalid cmd")); }
public String executeCommand(String command) { LOG.debug("Execute CMD {}", command); try { final Process p = processFunction.execute(command); p.waitFor(3, TimeUnit.SECONDS); try (BufferedReader buffer = new BufferedReader(new InputStreamReader(p.getInputStream()))) { return buffer.lines().collect(Collectors.joining("\n")); } } catch (InterruptedException | IOException e) { return ""; } }
LinuxRoutingService implements Routing { public String executeCommand(String command) { LOG.debug("Execute CMD {}", command); try { final Process p = processFunction.execute(command); p.waitFor(3, TimeUnit.SECONDS); try (BufferedReader buffer = new BufferedReader(new InputStreamReader(p.getInputStream()))) { return buffer.lines().collect(Collectors.joining("\n")); } } catch (InterruptedException | IOException e) { return ""; } } }
LinuxRoutingService implements Routing { public String executeCommand(String command) { LOG.debug("Execute CMD {}", command); try { final Process p = processFunction.execute(command); p.waitFor(3, TimeUnit.SECONDS); try (BufferedReader buffer = new BufferedReader(new InputStreamReader(p.getInputStream()))) { return buffer.lines().collect(Collectors.joining("\n")); } } catch (InterruptedException | IOException e) { return ""; } } LinuxRoutingService(SystemCall systemCall, RoutingDefinition initializer); }
LinuxRoutingService implements Routing { public String executeCommand(String command) { LOG.debug("Execute CMD {}", command); try { final Process p = processFunction.execute(command); p.waitFor(3, TimeUnit.SECONDS); try (BufferedReader buffer = new BufferedReader(new InputStreamReader(p.getInputStream()))) { return buffer.lines().collect(Collectors.joining("\n")); } } catch (InterruptedException | IOException e) { return ""; } } LinuxRoutingService(SystemCall systemCall, RoutingDefinition initializer); String executeCommand(String command); int executeCommandRC(String command); @Override synchronized Routing setInterface(String inf); @Override Routing setNetmask(final IpAddress netmask); @Override IpAddress getNetmask(); @Override synchronized String getInterface(); @Override synchronized IpAddress getVirtualIp(); @Override synchronized boolean isActive(); @Override synchronized boolean removeRouteForCurrentService(); @Override synchronized boolean addRouteForCurrentService(); @Override boolean updateArpTableForCurrentService(); @Override String toString(); }
LinuxRoutingService implements Routing { public String executeCommand(String command) { LOG.debug("Execute CMD {}", command); try { final Process p = processFunction.execute(command); p.waitFor(3, TimeUnit.SECONDS); try (BufferedReader buffer = new BufferedReader(new InputStreamReader(p.getInputStream()))) { return buffer.lines().collect(Collectors.joining("\n")); } } catch (InterruptedException | IOException e) { return ""; } } LinuxRoutingService(SystemCall systemCall, RoutingDefinition initializer); String executeCommand(String command); int executeCommandRC(String command); @Override synchronized Routing setInterface(String inf); @Override Routing setNetmask(final IpAddress netmask); @Override IpAddress getNetmask(); @Override synchronized String getInterface(); @Override synchronized IpAddress getVirtualIp(); @Override synchronized boolean isActive(); @Override synchronized boolean removeRouteForCurrentService(); @Override synchronized boolean addRouteForCurrentService(); @Override boolean updateArpTableForCurrentService(); @Override String toString();  }