CommonUtil { public static boolean validateUrl(String url, List<String> errorMsgs) { if (errorMsgs == null) { errorMsgs = new ArrayList<String>(); } boolean result = true; try { URI uri = new URI(url); String schema = uri.getScheme(); if (!"https".equalsIgnoreCase(schema) && !"http".equalsIgnoreCase(schema)) { errorMsgs.add("URL should starts with http or https"); result = false; } if ("https".equalsIgnoreCase(schema) && uri.getHost().matches(Constants.IP_PATTERN)) { errorMsgs.add("You should use FQDN instead of ip address when using https protocol"); result = false; } } catch (URISyntaxException e) { logger.error("invalid URL syntax ", e); errorMsgs.add("invalid URL syntax"); return false; } return result; }  static void setOwnerOnlyReadWrite(String filename); static String getConfDir(); static File getConfigurationFile(final String filename, final String typeName); static String readJsonFile(URL fileURL); static String readJsonFile(final String fileName); static String dataFromFile(String filePath); static void gracefulRackTopologyOutput(
         Map<String, String> racksTopology, String filename, String delimeter); static void prettyOutputStrings(List<Object> objs, String fileName, String delimeter); static List<String> inputsConvert(String inputs); static Set<String> inputsConvertSet(String inputs); static String inputsConvert(Set<String> words); static String inputsConvert(Map<K, V> wordsMap); static boolean isBlank(final String str); static String notNull(final String str, final String desStr); static boolean validateVcResourceName(final String input); static boolean validateResourceName(final String input); static boolean validateDistroName(final String input); static boolean validateClusterName(final String input); static boolean validateNodeGroupName(final String input); static boolean validataPathInfo(final String input); static boolean validateVcDataStoreNames(List<String> names); static boolean matchDatastorePattern(Set<String> patterns, Set<String> datastores); static String escapePattern(String pattern); static String getDatastoreJavaPattern(String pattern); static String getUUID(); static long makeVmMemoryDivisibleBy4(long memory); static boolean validateClusterPassword(String password); static boolean passwordContainInvalidCharacter(String password); static String randomString(int count); static String getClusterName(String vmName); static long getVmIndex(String vmName); static Process execCommand(String cmd); static String decode(final String paramName); static String encode(final String paramName); static String getCurrentTimestamp(); static String toHexString(byte[] bytes); static KeyStore loadAppMgrKeyStore(String keystorePath); static boolean validateUrl(String url, List<String> errorMsgs); static String mergeErrorMsgList(List<String> errorMsgs); static String formatWarningMsg(String warningMsg); static boolean checkServerConnection(final String host, final int port, int waitTime); static Object waitForThreadResult(Future<?> result, int waitTime); static boolean validateDnsType(NetworkDnsType dnsType); static void writeFile(File file, String content); static void writeFile(File file, String content, boolean append); static boolean getBooleanFromString(String booleanString, boolean defaultValue); static String getCustomizedSudoCmd(); static StorageRead.DiskScsiControllerType getSystemAndSwapControllerType(); static StorageRead.DiskScsiControllerType getDataDiskControllerType(); static char[] allChars; }
@Test public void testValidateUrl() throws ParseException { List<String> errorMsgs = new ArrayList<String>(); boolean valid = CommonUtil.validateUrl("http: Assert.assertTrue(valid); errorMsgs.clear(); valid = CommonUtil.validateUrl("ftp: Assert.assertFalse(valid); Assert.assertEquals(errorMsgs.get(0), "URL should starts with http or https"); }