@Test public void testCreateCommandThrowsInvalidTimeoutException() { LocalPingInputs localPingInputs = new LocalPingInputs.LocalPingInputsBuilder() .targetHost("10.0.0.1") .timeout("invalid") .build(); expectedException.expect(RuntimeException.class); expectedException.expectMessage(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); new SunOsPingCommand().createCommand(localPingInputs); }
@Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } final Long timeoutValue = parseLong(timeout) / 1000; command.append(localPingInputs.getTargetHost()) .append(" ") .append(valueOf(timeoutValue)); } else { final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-A inet6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-A inet "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } command.append(format("-s %s", localPingInputs.getTargetHost())); final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format(" %s ", packetSize)); } else { command.append(format(" %s ", DEFAULT_PACKET_SIZE)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("%s", packetCount)); } else { command.append(format("%s", DEFAULT_PACKET_COUNT)); } } return command.toString(); }
SunOsPingCommand implements LocalPingCommand { @Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } final Long timeoutValue = parseLong(timeout) / 1000; command.append(localPingInputs.getTargetHost()) .append(" ") .append(valueOf(timeoutValue)); } else { final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-A inet6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-A inet "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } command.append(format("-s %s", localPingInputs.getTargetHost())); final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format(" %s ", packetSize)); } else { command.append(format(" %s ", DEFAULT_PACKET_SIZE)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("%s", packetCount)); } else { command.append(format("%s", DEFAULT_PACKET_COUNT)); } } return command.toString(); } }
SunOsPingCommand implements LocalPingCommand { @Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } final Long timeoutValue = parseLong(timeout) / 1000; command.append(localPingInputs.getTargetHost()) .append(" ") .append(valueOf(timeoutValue)); } else { final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-A inet6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-A inet "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } command.append(format("-s %s", localPingInputs.getTargetHost())); final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format(" %s ", packetSize)); } else { command.append(format(" %s ", DEFAULT_PACKET_SIZE)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("%s", packetCount)); } else { command.append(format("%s", DEFAULT_PACKET_COUNT)); } } return command.toString(); }  }
SunOsPingCommand implements LocalPingCommand { @Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } final Long timeoutValue = parseLong(timeout) / 1000; command.append(localPingInputs.getTargetHost()) .append(" ") .append(valueOf(timeoutValue)); } else { final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-A inet6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-A inet "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } command.append(format("-s %s", localPingInputs.getTargetHost())); final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format(" %s ", packetSize)); } else { command.append(format(" %s ", DEFAULT_PACKET_SIZE)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("%s", packetCount)); } else { command.append(format("%s", DEFAULT_PACKET_COUNT)); } } return command.toString(); }  @Override String createCommand(LocalPingInputs localPingInputs); @Override Map<String, String> parseOutput(String output); }
SunOsPingCommand implements LocalPingCommand { @Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } final Long timeoutValue = parseLong(timeout) / 1000; command.append(localPingInputs.getTargetHost()) .append(" ") .append(valueOf(timeoutValue)); } else { final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-A inet6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-A inet "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } command.append(format("-s %s", localPingInputs.getTargetHost())); final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format(" %s ", packetSize)); } else { command.append(format(" %s ", DEFAULT_PACKET_SIZE)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("%s", packetCount)); } else { command.append(format("%s", DEFAULT_PACKET_COUNT)); } } return command.toString(); }  @Override String createCommand(LocalPingInputs localPingInputs); @Override Map<String, String> parseOutput(String output);  }