@Test public void executePingCommandWithRequiredInputs() throws Exception { Map<String, String> expectedMap = new HashMap<>(); expectedMap.put(RETURN_RESULT, COMMAND_OUTPUT); expectedMap.put(PACKETS_SENT, "4"); doReturn(expectedMap).when(localPingServiceMock).executePingCommand(any(LocalPingInputs.class)); Map<String, String> actualMap = new LocalPing().execute(LOCALHOST, "4", "", "", ""); assertEquals(expectedMap.get(RETURN_RESULT), actualMap.get(RETURN_RESULT)); assertEquals(expectedMap.get(PACKETS_SENT), actualMap.get(PACKETS_SENT)); }
@Action(name = LOCAL_PING_OPERATION_NAME, description = LOCAL_PING_OPERATION_DESC, outputs = { @Output(value = RETURN_RESULT, description = LOCAL_PING_RETURN_RESULT_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = PACKETS_SENT, description = PACKETS_SENT_OUTPUT_DESC), @Output(value = PACKETS_RECEIVED, description = PACKETS_RECEIVED_OUTPUT_DESC), @Output(value = PERCENTAGE_PACKETS_LOST, description = PERCENTAGE_PACKETS_LOST_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MIN, description = TRANSMISSION_TIME_MIN_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MAX, description = TRANSMISSION_TIME_MAX_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_AVG, description = TRANSMISSION_TIME_AVG_OUTPUT_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESC), }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true, description = FAILURE_DESC), } ) public Map<String, String> execute(@Param(value = TARGET_HOST, required = true, description = TARGET_HOST_INPUT_DESC) String targetHost, @Param(value = PACKET_COUNT, description = PACKETS_COUNT_INPUT_DESC) String packetCount, @Param(value = PACKET_SIZE, description = PACKET_SIZE_INPUT_DESC) String packetSize, @Param(value = TIMEOUT, description = TIMEOUT_INPUT_DESC) String timeout, @Param(value = IP_VERSION, description = IP_VERSION_INPUT_DESC) String ipVersion) { try { String targetIpAddress = getByName(targetHost).getHostAddress(); LocalPingInputs localPingInputs = new LocalPingInputs.LocalPingInputsBuilder() .targetHost(targetIpAddress) .ipVersion(ipVersion) .packetCount(packetCount) .packetSize(packetSize) .timeout(timeout) .build(); return new LocalPingService().executePingCommand(localPingInputs); } catch (Exception e) { Map<String, String> resultsMap = getFailureResultsMap(e); resultsMap.put(PACKETS_SENT, EMPTY_STRING); resultsMap.put(PACKETS_RECEIVED, EMPTY_STRING); resultsMap.put(PERCENTAGE_PACKETS_LOST, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); return resultsMap; } }
LocalPing { @Action(name = LOCAL_PING_OPERATION_NAME, description = LOCAL_PING_OPERATION_DESC, outputs = { @Output(value = RETURN_RESULT, description = LOCAL_PING_RETURN_RESULT_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = PACKETS_SENT, description = PACKETS_SENT_OUTPUT_DESC), @Output(value = PACKETS_RECEIVED, description = PACKETS_RECEIVED_OUTPUT_DESC), @Output(value = PERCENTAGE_PACKETS_LOST, description = PERCENTAGE_PACKETS_LOST_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MIN, description = TRANSMISSION_TIME_MIN_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MAX, description = TRANSMISSION_TIME_MAX_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_AVG, description = TRANSMISSION_TIME_AVG_OUTPUT_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESC), }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true, description = FAILURE_DESC), } ) public Map<String, String> execute(@Param(value = TARGET_HOST, required = true, description = TARGET_HOST_INPUT_DESC) String targetHost, @Param(value = PACKET_COUNT, description = PACKETS_COUNT_INPUT_DESC) String packetCount, @Param(value = PACKET_SIZE, description = PACKET_SIZE_INPUT_DESC) String packetSize, @Param(value = TIMEOUT, description = TIMEOUT_INPUT_DESC) String timeout, @Param(value = IP_VERSION, description = IP_VERSION_INPUT_DESC) String ipVersion) { try { String targetIpAddress = getByName(targetHost).getHostAddress(); LocalPingInputs localPingInputs = new LocalPingInputs.LocalPingInputsBuilder() .targetHost(targetIpAddress) .ipVersion(ipVersion) .packetCount(packetCount) .packetSize(packetSize) .timeout(timeout) .build(); return new LocalPingService().executePingCommand(localPingInputs); } catch (Exception e) { Map<String, String> resultsMap = getFailureResultsMap(e); resultsMap.put(PACKETS_SENT, EMPTY_STRING); resultsMap.put(PACKETS_RECEIVED, EMPTY_STRING); resultsMap.put(PERCENTAGE_PACKETS_LOST, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); return resultsMap; } } }
LocalPing { @Action(name = LOCAL_PING_OPERATION_NAME, description = LOCAL_PING_OPERATION_DESC, outputs = { @Output(value = RETURN_RESULT, description = LOCAL_PING_RETURN_RESULT_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = PACKETS_SENT, description = PACKETS_SENT_OUTPUT_DESC), @Output(value = PACKETS_RECEIVED, description = PACKETS_RECEIVED_OUTPUT_DESC), @Output(value = PERCENTAGE_PACKETS_LOST, description = PERCENTAGE_PACKETS_LOST_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MIN, description = TRANSMISSION_TIME_MIN_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MAX, description = TRANSMISSION_TIME_MAX_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_AVG, description = TRANSMISSION_TIME_AVG_OUTPUT_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESC), }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true, description = FAILURE_DESC), } ) public Map<String, String> execute(@Param(value = TARGET_HOST, required = true, description = TARGET_HOST_INPUT_DESC) String targetHost, @Param(value = PACKET_COUNT, description = PACKETS_COUNT_INPUT_DESC) String packetCount, @Param(value = PACKET_SIZE, description = PACKET_SIZE_INPUT_DESC) String packetSize, @Param(value = TIMEOUT, description = TIMEOUT_INPUT_DESC) String timeout, @Param(value = IP_VERSION, description = IP_VERSION_INPUT_DESC) String ipVersion) { try { String targetIpAddress = getByName(targetHost).getHostAddress(); LocalPingInputs localPingInputs = new LocalPingInputs.LocalPingInputsBuilder() .targetHost(targetIpAddress) .ipVersion(ipVersion) .packetCount(packetCount) .packetSize(packetSize) .timeout(timeout) .build(); return new LocalPingService().executePingCommand(localPingInputs); } catch (Exception e) { Map<String, String> resultsMap = getFailureResultsMap(e); resultsMap.put(PACKETS_SENT, EMPTY_STRING); resultsMap.put(PACKETS_RECEIVED, EMPTY_STRING); resultsMap.put(PERCENTAGE_PACKETS_LOST, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); return resultsMap; } }  }
LocalPing { @Action(name = LOCAL_PING_OPERATION_NAME, description = LOCAL_PING_OPERATION_DESC, outputs = { @Output(value = RETURN_RESULT, description = LOCAL_PING_RETURN_RESULT_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = PACKETS_SENT, description = PACKETS_SENT_OUTPUT_DESC), @Output(value = PACKETS_RECEIVED, description = PACKETS_RECEIVED_OUTPUT_DESC), @Output(value = PERCENTAGE_PACKETS_LOST, description = PERCENTAGE_PACKETS_LOST_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MIN, description = TRANSMISSION_TIME_MIN_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MAX, description = TRANSMISSION_TIME_MAX_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_AVG, description = TRANSMISSION_TIME_AVG_OUTPUT_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESC), }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true, description = FAILURE_DESC), } ) public Map<String, String> execute(@Param(value = TARGET_HOST, required = true, description = TARGET_HOST_INPUT_DESC) String targetHost, @Param(value = PACKET_COUNT, description = PACKETS_COUNT_INPUT_DESC) String packetCount, @Param(value = PACKET_SIZE, description = PACKET_SIZE_INPUT_DESC) String packetSize, @Param(value = TIMEOUT, description = TIMEOUT_INPUT_DESC) String timeout, @Param(value = IP_VERSION, description = IP_VERSION_INPUT_DESC) String ipVersion) { try { String targetIpAddress = getByName(targetHost).getHostAddress(); LocalPingInputs localPingInputs = new LocalPingInputs.LocalPingInputsBuilder() .targetHost(targetIpAddress) .ipVersion(ipVersion) .packetCount(packetCount) .packetSize(packetSize) .timeout(timeout) .build(); return new LocalPingService().executePingCommand(localPingInputs); } catch (Exception e) { Map<String, String> resultsMap = getFailureResultsMap(e); resultsMap.put(PACKETS_SENT, EMPTY_STRING); resultsMap.put(PACKETS_RECEIVED, EMPTY_STRING); resultsMap.put(PERCENTAGE_PACKETS_LOST, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); return resultsMap; } }  @Action(name = LOCAL_PING_OPERATION_NAME, description = LOCAL_PING_OPERATION_DESC, outputs = { @Output(value = RETURN_RESULT, description = LOCAL_PING_RETURN_RESULT_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = PACKETS_SENT, description = PACKETS_SENT_OUTPUT_DESC), @Output(value = PACKETS_RECEIVED, description = PACKETS_RECEIVED_OUTPUT_DESC), @Output(value = PERCENTAGE_PACKETS_LOST, description = PERCENTAGE_PACKETS_LOST_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MIN, description = TRANSMISSION_TIME_MIN_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MAX, description = TRANSMISSION_TIME_MAX_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_AVG, description = TRANSMISSION_TIME_AVG_OUTPUT_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESC), }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true, description = FAILURE_DESC), } ) Map<String, String> execute(@Param(value = TARGET_HOST, required = true, description = TARGET_HOST_INPUT_DESC) String targetHost,
                                       @Param(value = PACKET_COUNT, description = PACKETS_COUNT_INPUT_DESC) String packetCount,
                                       @Param(value = PACKET_SIZE, description = PACKET_SIZE_INPUT_DESC) String packetSize,
                                       @Param(value = TIMEOUT, description = TIMEOUT_INPUT_DESC) String timeout,
                                       @Param(value = IP_VERSION, description = IP_VERSION_INPUT_DESC) String ipVersion); }
LocalPing { @Action(name = LOCAL_PING_OPERATION_NAME, description = LOCAL_PING_OPERATION_DESC, outputs = { @Output(value = RETURN_RESULT, description = LOCAL_PING_RETURN_RESULT_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = PACKETS_SENT, description = PACKETS_SENT_OUTPUT_DESC), @Output(value = PACKETS_RECEIVED, description = PACKETS_RECEIVED_OUTPUT_DESC), @Output(value = PERCENTAGE_PACKETS_LOST, description = PERCENTAGE_PACKETS_LOST_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MIN, description = TRANSMISSION_TIME_MIN_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MAX, description = TRANSMISSION_TIME_MAX_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_AVG, description = TRANSMISSION_TIME_AVG_OUTPUT_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESC), }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true, description = FAILURE_DESC), } ) public Map<String, String> execute(@Param(value = TARGET_HOST, required = true, description = TARGET_HOST_INPUT_DESC) String targetHost, @Param(value = PACKET_COUNT, description = PACKETS_COUNT_INPUT_DESC) String packetCount, @Param(value = PACKET_SIZE, description = PACKET_SIZE_INPUT_DESC) String packetSize, @Param(value = TIMEOUT, description = TIMEOUT_INPUT_DESC) String timeout, @Param(value = IP_VERSION, description = IP_VERSION_INPUT_DESC) String ipVersion) { try { String targetIpAddress = getByName(targetHost).getHostAddress(); LocalPingInputs localPingInputs = new LocalPingInputs.LocalPingInputsBuilder() .targetHost(targetIpAddress) .ipVersion(ipVersion) .packetCount(packetCount) .packetSize(packetSize) .timeout(timeout) .build(); return new LocalPingService().executePingCommand(localPingInputs); } catch (Exception e) { Map<String, String> resultsMap = getFailureResultsMap(e); resultsMap.put(PACKETS_SENT, EMPTY_STRING); resultsMap.put(PACKETS_RECEIVED, EMPTY_STRING); resultsMap.put(PERCENTAGE_PACKETS_LOST, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MIN, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_AVG, EMPTY_STRING); resultsMap.put(TRANSMISSION_TIME_MAX, EMPTY_STRING); return resultsMap; } }  @Action(name = LOCAL_PING_OPERATION_NAME, description = LOCAL_PING_OPERATION_DESC, outputs = { @Output(value = RETURN_RESULT, description = LOCAL_PING_RETURN_RESULT_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = PACKETS_SENT, description = PACKETS_SENT_OUTPUT_DESC), @Output(value = PACKETS_RECEIVED, description = PACKETS_RECEIVED_OUTPUT_DESC), @Output(value = PERCENTAGE_PACKETS_LOST, description = PERCENTAGE_PACKETS_LOST_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MIN, description = TRANSMISSION_TIME_MIN_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_MAX, description = TRANSMISSION_TIME_MAX_OUTPUT_DESC), @Output(value = TRANSMISSION_TIME_AVG, description = TRANSMISSION_TIME_AVG_OUTPUT_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESC), }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true, description = FAILURE_DESC), } ) Map<String, String> execute(@Param(value = TARGET_HOST, required = true, description = TARGET_HOST_INPUT_DESC) String targetHost,
                                       @Param(value = PACKET_COUNT, description = PACKETS_COUNT_INPUT_DESC) String packetCount,
                                       @Param(value = PACKET_SIZE, description = PACKET_SIZE_INPUT_DESC) String packetSize,
                                       @Param(value = TIMEOUT, description = TIMEOUT_INPUT_DESC) String timeout,
                                       @Param(value = IP_VERSION, description = IP_VERSION_INPUT_DESC) String ipVersion);  }