@Test public void testProcessOutputForNoResult() { OperatingSystemDetails actualOsDetails = osDetectorHelperService.processOutput(new OperatingSystemDetails(), new HashMap<String, String>() {{put("returnResult", "msg");}}, "det option"); assertEquals("", actualOsDetails.getName()); assertEquals("", actualOsDetails.getVersion()); assertEquals("", actualOsDetails.getFamily()); assertEquals("", actualOsDetails.getArchitecture()); assertEquals(singletonList("msg"), actualOsDetails.getCommandsOutput().get("det option")); }
public OperatingSystemDetails processOutput(OperatingSystemDetails operatingSystemDetails, Map<String, String> execute, String detectOption) { String resultString = execute.get(RETURN_RESULT); operatingSystemDetails.addCommandOutput(detectOption, singletonList(resultString)); String lineSeparator = contains(resultString, WINDOWS_LINE_SEPARATOR) ? WINDOWS_LINE_SEPARATOR : contains(resultString, UNIX_LINE_SEPARATOR) ? UNIX_LINE_SEPARATOR : EARLY_MAC_LINE_SEPARATOR; if (isWindows(execute)) { operatingSystemDetails.setFamily(WINDOWS); operatingSystemDetails.setName(strip(cropValue(resultString, WINDOWS_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, WINDOWS_OS_VERSION_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, WINDOWS_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); return operatingSystemDetails; } else if (isUnix(execute)){ String osFamily = strip(cropValue(resultString, UNIX_OS_FAMILY_KEY, lineSeparator), QUOTES); operatingSystemDetails.setFamily(osFamily); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, LINUX_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); if (equalsIgnoreCase(osFamily, "darwin")) { operatingSystemDetails.setName(strip(cropValue(resultString, MAC_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, MAC_OS_VERSION_KEY, lineSeparator), QUOTES)); } else { operatingSystemDetails.setName(strip(cropValue(resultString, LINUX_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, LINUX_OS_VERSION_KEY, lineSeparator), QUOTES)); } return operatingSystemDetails; } return operatingSystemDetails; }
OsDetectorHelperService { public OperatingSystemDetails processOutput(OperatingSystemDetails operatingSystemDetails, Map<String, String> execute, String detectOption) { String resultString = execute.get(RETURN_RESULT); operatingSystemDetails.addCommandOutput(detectOption, singletonList(resultString)); String lineSeparator = contains(resultString, WINDOWS_LINE_SEPARATOR) ? WINDOWS_LINE_SEPARATOR : contains(resultString, UNIX_LINE_SEPARATOR) ? UNIX_LINE_SEPARATOR : EARLY_MAC_LINE_SEPARATOR; if (isWindows(execute)) { operatingSystemDetails.setFamily(WINDOWS); operatingSystemDetails.setName(strip(cropValue(resultString, WINDOWS_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, WINDOWS_OS_VERSION_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, WINDOWS_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); return operatingSystemDetails; } else if (isUnix(execute)){ String osFamily = strip(cropValue(resultString, UNIX_OS_FAMILY_KEY, lineSeparator), QUOTES); operatingSystemDetails.setFamily(osFamily); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, LINUX_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); if (equalsIgnoreCase(osFamily, "darwin")) { operatingSystemDetails.setName(strip(cropValue(resultString, MAC_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, MAC_OS_VERSION_KEY, lineSeparator), QUOTES)); } else { operatingSystemDetails.setName(strip(cropValue(resultString, LINUX_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, LINUX_OS_VERSION_KEY, lineSeparator), QUOTES)); } return operatingSystemDetails; } return operatingSystemDetails; } }
OsDetectorHelperService { public OperatingSystemDetails processOutput(OperatingSystemDetails operatingSystemDetails, Map<String, String> execute, String detectOption) { String resultString = execute.get(RETURN_RESULT); operatingSystemDetails.addCommandOutput(detectOption, singletonList(resultString)); String lineSeparator = contains(resultString, WINDOWS_LINE_SEPARATOR) ? WINDOWS_LINE_SEPARATOR : contains(resultString, UNIX_LINE_SEPARATOR) ? UNIX_LINE_SEPARATOR : EARLY_MAC_LINE_SEPARATOR; if (isWindows(execute)) { operatingSystemDetails.setFamily(WINDOWS); operatingSystemDetails.setName(strip(cropValue(resultString, WINDOWS_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, WINDOWS_OS_VERSION_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, WINDOWS_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); return operatingSystemDetails; } else if (isUnix(execute)){ String osFamily = strip(cropValue(resultString, UNIX_OS_FAMILY_KEY, lineSeparator), QUOTES); operatingSystemDetails.setFamily(osFamily); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, LINUX_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); if (equalsIgnoreCase(osFamily, "darwin")) { operatingSystemDetails.setName(strip(cropValue(resultString, MAC_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, MAC_OS_VERSION_KEY, lineSeparator), QUOTES)); } else { operatingSystemDetails.setName(strip(cropValue(resultString, LINUX_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, LINUX_OS_VERSION_KEY, lineSeparator), QUOTES)); } return operatingSystemDetails; } return operatingSystemDetails; }  }
OsDetectorHelperService { public OperatingSystemDetails processOutput(OperatingSystemDetails operatingSystemDetails, Map<String, String> execute, String detectOption) { String resultString = execute.get(RETURN_RESULT); operatingSystemDetails.addCommandOutput(detectOption, singletonList(resultString)); String lineSeparator = contains(resultString, WINDOWS_LINE_SEPARATOR) ? WINDOWS_LINE_SEPARATOR : contains(resultString, UNIX_LINE_SEPARATOR) ? UNIX_LINE_SEPARATOR : EARLY_MAC_LINE_SEPARATOR; if (isWindows(execute)) { operatingSystemDetails.setFamily(WINDOWS); operatingSystemDetails.setName(strip(cropValue(resultString, WINDOWS_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, WINDOWS_OS_VERSION_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, WINDOWS_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); return operatingSystemDetails; } else if (isUnix(execute)){ String osFamily = strip(cropValue(resultString, UNIX_OS_FAMILY_KEY, lineSeparator), QUOTES); operatingSystemDetails.setFamily(osFamily); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, LINUX_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); if (equalsIgnoreCase(osFamily, "darwin")) { operatingSystemDetails.setName(strip(cropValue(resultString, MAC_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, MAC_OS_VERSION_KEY, lineSeparator), QUOTES)); } else { operatingSystemDetails.setName(strip(cropValue(resultString, LINUX_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, LINUX_OS_VERSION_KEY, lineSeparator), QUOTES)); } return operatingSystemDetails; } return operatingSystemDetails; }  String formatOsCommandsOutput(Map<String, List<String>> commandsOutput); void validateNmapInputs(OsDetectorInputs osDetectorInputs, NmapOsDetectorService nmapOsDetectorService); String cropValue(String stdOut, String begin, String end); boolean foundOperatingSystem(OperatingSystemDetails os); OperatingSystemDetails processOutput(OperatingSystemDetails operatingSystemDetails, Map<String, String> execute, String detectOption); String resolveOsFamily(String osName); }
OsDetectorHelperService { public OperatingSystemDetails processOutput(OperatingSystemDetails operatingSystemDetails, Map<String, String> execute, String detectOption) { String resultString = execute.get(RETURN_RESULT); operatingSystemDetails.addCommandOutput(detectOption, singletonList(resultString)); String lineSeparator = contains(resultString, WINDOWS_LINE_SEPARATOR) ? WINDOWS_LINE_SEPARATOR : contains(resultString, UNIX_LINE_SEPARATOR) ? UNIX_LINE_SEPARATOR : EARLY_MAC_LINE_SEPARATOR; if (isWindows(execute)) { operatingSystemDetails.setFamily(WINDOWS); operatingSystemDetails.setName(strip(cropValue(resultString, WINDOWS_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, WINDOWS_OS_VERSION_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, WINDOWS_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); return operatingSystemDetails; } else if (isUnix(execute)){ String osFamily = strip(cropValue(resultString, UNIX_OS_FAMILY_KEY, lineSeparator), QUOTES); operatingSystemDetails.setFamily(osFamily); operatingSystemDetails.setArchitecture(strip(cropValue(resultString, LINUX_OS_ARCHITECTURE_KEY, lineSeparator), QUOTES)); if (equalsIgnoreCase(osFamily, "darwin")) { operatingSystemDetails.setName(strip(cropValue(resultString, MAC_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, MAC_OS_VERSION_KEY, lineSeparator), QUOTES)); } else { operatingSystemDetails.setName(strip(cropValue(resultString, LINUX_OS_NAME_KEY, lineSeparator), QUOTES)); operatingSystemDetails.setVersion(strip(cropValue(resultString, LINUX_OS_VERSION_KEY, lineSeparator), QUOTES)); } return operatingSystemDetails; } return operatingSystemDetails; }  String formatOsCommandsOutput(Map<String, List<String>> commandsOutput); void validateNmapInputs(OsDetectorInputs osDetectorInputs, NmapOsDetectorService nmapOsDetectorService); String cropValue(String stdOut, String begin, String end); boolean foundOperatingSystem(OperatingSystemDetails os); OperatingSystemDetails processOutput(OperatingSystemDetails operatingSystemDetails, Map<String, String> execute, String detectOption); String resolveOsFamily(String osName);  }