@Test public void testCreateCommandSuccess() { LocalPingInputs localPingInputs = new LocalPingInputs.LocalPingInputsBuilder() .targetHost("10.0.0.1") .packetCount("5") .packetSize("100") .timeout("30000") .build(); LocalPingCommand windowsPingCommand = new WindowsPingCommand(); String command = windowsPingCommand.createCommand(localPingInputs); assertEquals("ping -w 30000 -n 5 -l 100 10.0.0.1", command); }
@Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-4 "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-w %s ", timeout)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-n %s ", packetCount)); } final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-l %s ", packetSize)); } command.append(localPingInputs.getTargetHost()); return command.toString(); }
WindowsPingCommand implements LocalPingCommand { @Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-4 "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-w %s ", timeout)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-n %s ", packetCount)); } final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-l %s ", packetSize)); } command.append(localPingInputs.getTargetHost()); return command.toString(); } }
WindowsPingCommand implements LocalPingCommand { @Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-4 "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-w %s ", timeout)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-n %s ", packetCount)); } final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-l %s ", packetSize)); } command.append(localPingInputs.getTargetHost()); return command.toString(); }  }
WindowsPingCommand implements LocalPingCommand { @Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-4 "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-w %s ", timeout)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-n %s ", packetCount)); } final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-l %s ", packetSize)); } command.append(localPingInputs.getTargetHost()); return command.toString(); }  @Override String createCommand(LocalPingInputs localPingInputs); @Override Map<String, String> parseOutput(String output); }
WindowsPingCommand implements LocalPingCommand { @Override public String createCommand(LocalPingInputs localPingInputs) { StringBuilder command = new StringBuilder(); command.append("ping "); final String ipVersion = localPingInputs.getIpVersion(); if (isNotEmpty(ipVersion)) { if (ipVersion.equals(IP_VERSION_6)) { command.append("-6 "); } else if (ipVersion.equals(IP_VERSION_4)) { command.append("-4 "); } else { throw new IllegalArgumentException(format(INVALID_ARGUMENT_IP_VERSION, ipVersion)); } } final String timeout = localPingInputs.getTimeout(); if (isNotEmpty(timeout)) { if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-w %s ", timeout)); } final String packetCount = localPingInputs.getPacketCount(); if (isNotEmpty(packetCount)) { if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-n %s ", packetCount)); } final String packetSize = localPingInputs.getPacketSize(); if (isNotEmpty(packetSize)) { if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); } command.append(format("-l %s ", packetSize)); } command.append(localPingInputs.getTargetHost()); return command.toString(); }  @Override String createCommand(LocalPingInputs localPingInputs); @Override Map<String, String> parseOutput(String output);  }