UrlUtils { public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(ANY_VALUE.equals(consumerInterface) || ANY_VALUE.equals(providerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) { return false; } if (!isMatchCategory(providerUrl.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY), consumerUrl.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(ENABLED_KEY, true) && !ANY_VALUE.equals(consumerUrl.getParameter(ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(GROUP_KEY); String consumerVersion = consumerUrl.getParameter(VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(CLASSIFIER_KEY, ANY_VALUE); String providerGroup = providerUrl.getParameter(GROUP_KEY); String providerVersion = providerUrl.getParameter(VERSION_KEY); String providerClassifier = providerUrl.getParameter(CLASSIFIER_KEY, ANY_VALUE); return (ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); }  static URL parseURL(String address, Map<String, String> defaults); static List<URL> parseURLs(String address, Map<String, String> defaults); static Map<String, Map<String, String>> convertRegister(Map<String, Map<String, String>> register); static Map<String, String> convertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertRegister(Map<String, Map<String, String>> register); static Map<String, String> revertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertNotify(Map<String, Map<String, String>> notify); static List<String> revertForbid(List<String> forbid, Set<URL> subscribed); static URL getEmptyUrl(String service, String category); static boolean isMatchCategory(String category, String categories); static boolean isMatch(URL consumerUrl, URL providerUrl); static boolean isMatchGlobPattern(String pattern, String value, URL param); static boolean isMatchGlobPattern(String pattern, String value); static boolean isServiceKeyMatch(URL pattern, URL value); static List<URL> classifyUrls(List<URL> urls, Predicate<URL> predicate); static boolean isConfigurator(URL url); static boolean isRoute(URL url); static boolean isProvider(URL url); static boolean isRegistry(URL url); static boolean isServiceDiscoveryRegistryType(URL url); static boolean isServiceDiscoveryRegistryType(Map<String, String> parameters); static String[] parseServiceKey(String serviceKey);  }
@Test public void testIsMatch() { URL consumerUrl = URL.valueOf("dubbo: URL providerUrl = URL.valueOf("http: assertTrue(UrlUtils.isMatch(consumerUrl, providerUrl)); }
@Test public void testIsMatch2() { URL consumerUrl = URL.valueOf("dubbo: URL providerUrl = URL.valueOf("http: assertFalse(UrlUtils.isMatch(consumerUrl, providerUrl)); }
@Test public void testIsMatch3() { URL consumerUrl = URL.valueOf("dubbo: URL providerUrl = URL.valueOf("http: assertFalse(UrlUtils.isMatch(consumerUrl, providerUrl)); }
@Test public void testIsMatch4() { URL consumerUrl = URL.valueOf("dubbo: URL providerUrl = URL.valueOf("http: assertTrue(UrlUtils.isMatch(consumerUrl, providerUrl)); }
@Test public void testIsMatch5() { URL consumerUrl = URL.valueOf("dubbo: URL providerUrl = URL.valueOf("http: assertTrue(UrlUtils.isMatch(consumerUrl, providerUrl)); }
@Test public void testIsMatchUrlWithDefaultPrefix() { URL url = URL.valueOf("dubbo: assertEquals("1.0.0", url.getParameter("version")); assertEquals("1.0.0", url.getParameter("default.version")); URL consumerUrl = URL.valueOf("consumer: assertTrue(UrlUtils.isMatch(consumerUrl, url)); URL consumerUrl1 = URL.valueOf("consumer: assertTrue(UrlUtils.isMatch(consumerUrl, url)); }