com.alibaba.dubbo.registry.common.route.ParseUtils Java Examples

The following examples show how to use com.alibaba.dubbo.registry.common.route.ParseUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParseUtilsTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@Test
public void testInterpolateCollMap_NormalCase() throws Exception {
    List<String> expressions = new ArrayList<String>();
    expressions.add("xx$var1");
    expressions.add("yy${var2}zz");

    Map<String, String> params = new HashMap<String, String>();
    params.put("var1", "CAT");
    params.put("var2", "DOG");

    List<String> interpolate = ParseUtils.interpolate(expressions, params);

    List<String> expected = new ArrayList<String>();
    expected.add("xxCAT");
    expected.add("yyDOGzz");

    assertEquals(expected, interpolate);
}
 
Example #2
Source File: ProviderServiceImpl.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public List<String> findMethodsByService(String service) {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(providerUrls == null || service == null || service.length() == 0) return ret;
    
    Map<Long, URL> providers = providerUrls.get(service);
    if(null == providers || providers.isEmpty()) return ret;
    
    Entry<Long, URL> p = providers.entrySet().iterator().next();
    String value = p.getValue().getParameter("methods");
    if (value == null || value.length() == 0) {
        return ret;
    }
    String[] methods = value.split(ParseUtils.METHOD_SPLIT);
    if (methods == null || methods.length == 0) {
        return ret;
    }
    
    for(String m : methods) {
        ret.add(m);
    }
    return ret;
}
 
Example #3
Source File: ParseUtilsTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplaceMethods() throws Exception {
	assertEquals(
            "methods=aaa,bbb",
            ParseUtils.replaceParameter(null, "methods", "aaa,bbb"));
	assertEquals(
            "methods=aaa,bbb",
            ParseUtils.replaceParameter("", "methods", "aaa,bbb"));
	assertEquals(
            "version=1.0.0&application=morgan&weight=10&methods=aaa,bbb",
            ParseUtils.replaceParameter("version=1.0.0&application=morgan&weight=10", "methods", "aaa,bbb"));
	assertEquals(
            "version=1.0.0&methods=ccc,ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("version=1.0.0&methods=aaa,bbb&application=morgan&weight=10", "methods", "ccc,ddd"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=10&methods=aaa,bbb",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=10", "methods", "aaa,bbb"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=ccc,ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=aaa,bbb&application=morgan&weight=10", "methods", "ccc,ddd"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=$ccc,$ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=$aaa,$bbb&application=morgan&weight=10", "methods", "$ccc,$ddd"));
}
 
Example #4
Source File: ParseUtilsTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplaceMethods() throws Exception {
	assertEquals(
            "methods=aaa,bbb",
            ParseUtils.replaceParameter(null, "methods", "aaa,bbb"));
	assertEquals(
            "methods=aaa,bbb",
            ParseUtils.replaceParameter("", "methods", "aaa,bbb"));
	assertEquals(
            "version=1.0.0&application=morgan&weight=10&methods=aaa,bbb",
            ParseUtils.replaceParameter("version=1.0.0&application=morgan&weight=10", "methods", "aaa,bbb"));
	assertEquals(
            "version=1.0.0&methods=ccc,ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("version=1.0.0&methods=aaa,bbb&application=morgan&weight=10", "methods", "ccc,ddd"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=10&methods=aaa,bbb",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=10", "methods", "aaa,bbb"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=ccc,ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=aaa,bbb&application=morgan&weight=10", "methods", "ccc,ddd"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=$ccc,$ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=$aaa,$bbb&application=morgan&weight=10", "methods", "$ccc,$ddd"));
}
 
Example #5
Source File: User.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public boolean hasServicePrivilege(String service) {
	if (service == null || service.length() == 0)
		return false;
	if (role == null || GUEST.equalsIgnoreCase(role)) {
		return false;
	}
	if(ROOT.equalsIgnoreCase(role)) {
	    return true;
	}
	
	if (servicePrivileges != null && servicePrivileges.size() > 0) {
   		for (String privilege : servicePrivileges) {
               boolean ok = ParseUtils.isMatchGlobPattern(privilege,service);
               if (ok) {
               	return true;
               }
   		}
	}
	return false;
}
 
Example #6
Source File: ParseUtilsTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testInterpolateCollMap_NormalCase() throws Exception {
    List<String> expressions = new ArrayList<String>();
    expressions.add("xx$var1");
    expressions.add("yy${var2}zz");

    Map<String, String> params = new HashMap<String, String>();
    params.put("var1", "CAT");
    params.put("var2", "DOG");

    List<String> interpolate = ParseUtils.interpolate(expressions, params);

    List<String> expected = new ArrayList<String>();
    expected.add("xxCAT");
    expected.add("yyDOGzz");

    assertEquals(expected, interpolate);
}
 
Example #7
Source File: ParseUtilsTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplaceMethods() throws Exception {
	assertEquals(
            "methods=aaa,bbb",
            ParseUtils.replaceParameter(null, "methods", "aaa,bbb"));
	assertEquals(
            "methods=aaa,bbb",
            ParseUtils.replaceParameter("", "methods", "aaa,bbb"));
	assertEquals(
            "version=1.0.0&application=morgan&weight=10&methods=aaa,bbb",
            ParseUtils.replaceParameter("version=1.0.0&application=morgan&weight=10", "methods", "aaa,bbb"));
	assertEquals(
            "version=1.0.0&methods=ccc,ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("version=1.0.0&methods=aaa,bbb&application=morgan&weight=10", "methods", "ccc,ddd"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=10&methods=aaa,bbb",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=10", "methods", "aaa,bbb"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=ccc,ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=aaa,bbb&application=morgan&weight=10", "methods", "ccc,ddd"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=$ccc,$ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=$aaa,$bbb&application=morgan&weight=10", "methods", "$ccc,$ddd"));
}
 
Example #8
Source File: User.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public boolean hasServicePrivilege(String service) {
	if (service == null || service.length() == 0)
		return false;
	if (role == null || GUEST.equalsIgnoreCase(role)) {
		return false;
	}
	if(ROOT.equalsIgnoreCase(role)) {
	    return true;
	}
	
	if (servicePrivileges != null && servicePrivileges.size() > 0) {
   		for (String privilege : servicePrivileges) {
               boolean ok = ParseUtils.isMatchGlobPattern(privilege,service);
               if (ok) {
               	return true;
               }
   		}
	}
	return false;
}
 
Example #9
Source File: ProviderServiceImpl.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public List<String> findMethodsByService(String service) {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(providerUrls == null || service == null || service.length() == 0) return ret;
    
    Map<Long, URL> providers = providerUrls.get(service);
    if(null == providers || providers.isEmpty()) return ret;
    
    Entry<Long, URL> p = providers.entrySet().iterator().next();
    String value = p.getValue().getParameter("methods");
    if (value == null || value.length() == 0) {
        return ret;
    }
    String[] methods = value.split(ParseUtils.METHOD_SPLIT);
    if (methods == null || methods.length == 0) {
        return ret;
    }
    
    for(String m : methods) {
        ret.add(m);
    }
    return ret;
}
 
Example #10
Source File: ProviderServiceImpl.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public List<String> findMethodsByService(String service) {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(providerUrls == null || service == null || service.length() == 0) return ret;
    
    Map<Long, URL> providers = providerUrls.get(service);
    if(null == providers || providers.isEmpty()) return ret;
    
    Entry<Long, URL> p = providers.entrySet().iterator().next();
    String value = p.getValue().getParameter("methods");
    if (value == null || value.length() == 0) {
        return ret;
    }
    String[] methods = value.split(ParseUtils.METHOD_SPLIT);
    if (methods == null || methods.length == 0) {
        return ret;
    }
    
    for(String m : methods) {
        ret.add(m);
    }
    return ret;
}
 
Example #11
Source File: ParseUtilsTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplaceMethods() throws Exception {
	assertEquals(
            "methods=aaa,bbb",
            ParseUtils.replaceParameter(null, "methods", "aaa,bbb"));
	assertEquals(
            "methods=aaa,bbb",
            ParseUtils.replaceParameter("", "methods", "aaa,bbb"));
	assertEquals(
            "version=1.0.0&application=morgan&weight=10&methods=aaa,bbb",
            ParseUtils.replaceParameter("version=1.0.0&application=morgan&weight=10", "methods", "aaa,bbb"));
	assertEquals(
            "version=1.0.0&methods=ccc,ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("version=1.0.0&methods=aaa,bbb&application=morgan&weight=10", "methods", "ccc,ddd"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=10&methods=aaa,bbb",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=10", "methods", "aaa,bbb"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=ccc,ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=aaa,bbb&application=morgan&weight=10", "methods", "ccc,ddd"));
	assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=$ccc,$ddd&application=morgan&weight=10",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&methods=$aaa,$bbb&application=morgan&weight=10", "methods", "$ccc,$ddd"));
}
 
Example #12
Source File: ParseUtilsTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsMatchGlobPatternsNeedInterpolate() throws Exception {
    Collection<String> patternsNeedInterpolate = new HashSet<String>();
    Map<String, String> interpolateParams = new HashMap<String, String>();
    
    boolean match = ParseUtils.isMatchGlobPatternsNeedInterpolate(patternsNeedInterpolate, interpolateParams, "abc");
    assertFalse(match);
    
    patternsNeedInterpolate.add("abc*$var1");
    patternsNeedInterpolate.add("123${var2}*");
    
    interpolateParams.put("var1", "CAT");
    interpolateParams.put("var2", "DOG");
    
    match = ParseUtils.isMatchGlobPatternsNeedInterpolate(patternsNeedInterpolate, interpolateParams, "abc");
    assertFalse(match);
    
    match = ParseUtils.isMatchGlobPatternsNeedInterpolate(patternsNeedInterpolate, interpolateParams, "abcXXXCAT");
    assertTrue(match);
    match = ParseUtils.isMatchGlobPatternsNeedInterpolate(patternsNeedInterpolate, interpolateParams, "123DOGYYY");
    assertTrue(match);
}
 
Example #13
Source File: ParseUtilsTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void test_appendParamToUri() throws Exception {
    String append = ParseUtils.appendParamToUri("dubbo://11.22.33.44/serviceName?k1=v1&k2=v2", "k3", "v3");
    assertEquals("dubbo://11.22.33.44/serviceName?k1=v1&k2=v2&k3=v3", append);

    Map<String, String> params = new LinkedHashMap<String, String>();
    params.put("k3", "v3");
    params.put("k4", "v4");
    append = ParseUtils.appendParamsToUri("dubbo://11.22.33.44/serviceName?k1=v1&k2=v2", params);
    assertEquals("dubbo://11.22.33.44/serviceName?k1=v1&k2=v2&k3=v3&k4=v4", append);
}
 
Example #14
Source File: ParseUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseQueryPrefixMultiKeyValue() throws Exception {
    Map<String, String> result = new HashMap<String, String>();
    result.put("consumer.verion", "1.0.0");
    result.put("consumer.cluster", "china");
    assertEquals(result, ParseUtils.parseQuery("consumer.", "verion=1.0.0&cluster=china"));
}
 
Example #15
Source File: RelateUserUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 添加与服务相关的Owner
 * 
 * @param usernames 用于添加的用户名
 * @param serviceName 不含通配符
 */
public static void addOwnersOfService(Set<String> usernames, String serviceName,
                                      OwnerService ownerDAO) {
    List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
    for (String p : serviceNamePatterns) {
        if (ParseUtils.isMatchGlobPattern(p, serviceName)) {
            List<String> list = ownerDAO.findUsernamesByServiceName(p);
            usernames.addAll(list);
        }
    }
}
 
Example #16
Source File: ParseUtilsTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterByGlobPattern() throws Exception {
    Collection<String> values = new ArrayList<String>();
    values.add("abc123");
    values.add("JQKxyz");
    values.add("abc123");
    values.add("abcLLL");
    
    Set<String> filter = ParseUtils.filterByGlobPattern("abc*", values);
    Set<String> expected = new HashSet<String>();
    expected.add("abc123");
    expected.add("abcLLL");
    
    assertEquals(expected, filter);

    filter = ParseUtils.filterByGlobPattern((Collection<String>)null, values);
    assertTrue(filter.isEmpty()); 
    
    Collection<String> patterns = new ArrayList<String>();
    patterns.add("000000000");
    patterns.add("abc*");
    patterns.add("*xyz");

    filter = ParseUtils.filterByGlobPattern(patterns, values);
    
    expected.add("JQKxyz");
    assertEquals(expected, filter);
}
 
Example #17
Source File: ParseUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_hasIntersection() throws Exception {
    assertFalse(ParseUtils.hasIntersection(null, null));
    assertFalse(ParseUtils.hasIntersection("dog", null));
    assertFalse(ParseUtils.hasIntersection(null, "god"));

    assertTrue(ParseUtils.hasIntersection("hello", "hello*"));
    assertTrue(ParseUtils.hasIntersection("helloxxx", "hello*"));
    assertTrue(ParseUtils.hasIntersection("world", "*world"));
    assertTrue(ParseUtils.hasIntersection("xxxworld", "*world"));
    assertTrue(ParseUtils.hasIntersection("helloworld", "hello*world"));
    assertTrue(ParseUtils.hasIntersection("helloxxxworld", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("Yhelloxxxworld", "hello*world"));

    assertTrue(ParseUtils.hasIntersection("hello*", "hello"));
    assertTrue(ParseUtils.hasIntersection("hello*", "helloxxx"));
    assertTrue(ParseUtils.hasIntersection("*world", "world"));
    assertTrue(ParseUtils.hasIntersection("*world", "xxxworld"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "helloworld"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "helloxxxworld"));
    assertFalse(ParseUtils.hasIntersection("hello*world", "Yhelloxxxworld"));

    assertTrue(ParseUtils.hasIntersection("*world", "hello*world"));
    assertTrue(ParseUtils.hasIntersection("*world", "hello*Zworld"));
    assertTrue(ParseUtils.hasIntersection("helloZ*", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("Zhello*", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "hello*world"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "hello*Zworld"));
    assertTrue(ParseUtils.hasIntersection("helloZ*world", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("Zhello*world", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ"));
}
 
Example #18
Source File: ParseUtilsTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_hasIntersection() throws Exception {
    assertFalse(ParseUtils.hasIntersection(null, null));
    assertFalse(ParseUtils.hasIntersection("dog", null));
    assertFalse(ParseUtils.hasIntersection(null, "god"));

    assertTrue(ParseUtils.hasIntersection("hello", "hello*"));
    assertTrue(ParseUtils.hasIntersection("helloxxx", "hello*"));
    assertTrue(ParseUtils.hasIntersection("world", "*world"));
    assertTrue(ParseUtils.hasIntersection("xxxworld", "*world"));
    assertTrue(ParseUtils.hasIntersection("helloworld", "hello*world"));
    assertTrue(ParseUtils.hasIntersection("helloxxxworld", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("Yhelloxxxworld", "hello*world"));

    assertTrue(ParseUtils.hasIntersection("hello*", "hello"));
    assertTrue(ParseUtils.hasIntersection("hello*", "helloxxx"));
    assertTrue(ParseUtils.hasIntersection("*world", "world"));
    assertTrue(ParseUtils.hasIntersection("*world", "xxxworld"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "helloworld"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "helloxxxworld"));
    assertFalse(ParseUtils.hasIntersection("hello*world", "Yhelloxxxworld"));

    assertTrue(ParseUtils.hasIntersection("*world", "hello*world"));
    assertTrue(ParseUtils.hasIntersection("*world", "hello*Zworld"));
    assertTrue(ParseUtils.hasIntersection("helloZ*", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("Zhello*", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "hello*world"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "hello*Zworld"));
    assertTrue(ParseUtils.hasIntersection("helloZ*world", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("Zhello*world", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ"));
}
 
Example #19
Source File: ParseUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testInterpolateVariableWithParentheses() throws Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("consumer.address", "10.20.130.230");
    String regexp = ParseUtils.interpolate("xx${consumer.address}yy", params);
    assertEquals("xx10.20.130.230yy", regexp);
}
 
Example #20
Source File: RelateUserUtils.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
/**
 * 添加与服务相关的Owner
 * 
 * @param usernames 用于添加的用户名
 * @param serviceName 不含通配符
 */
public static void addOwnersOfService(Set<String> usernames, String serviceName,
                                      OwnerService ownerDAO) {
    List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
    for (String p : serviceNamePatterns) {
        if (ParseUtils.isMatchGlobPattern(p, serviceName)) {
            List<String> list = ownerDAO.findUsernamesByServiceName(p);
            usernames.addAll(list);
        }
    }
}
 
Example #21
Source File: Routes.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
/**
 * 添加与服务相关的Owner
 * 
 * @param usernames 用于添加的用户名
 * @param serviceName 不含通配符
 */
public static void addOwnersOfService(Set<String> usernames, String serviceName,
                                      OwnerService ownerDAO) {
    List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
    for (String p : serviceNamePatterns) {
        if (ParseUtils.isMatchGlobPattern(p, serviceName)) {
            List<String> list = ownerDAO.findUsernamesByServiceName(p);
            usernames.addAll(list);
        }
    }
}
 
Example #22
Source File: ParseUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsMatchGlobPattern() throws Exception {
    // Null Case
    assertTrue(ParseUtils.isMatchGlobPattern(null, null));
    assertFalse(ParseUtils.isMatchGlobPattern("abc", null));
    assertFalse(ParseUtils.isMatchGlobPattern(null, "xxx"));
    
    // empty string
    assertTrue(ParseUtils.isMatchGlobPattern("", ""));
    assertFalse(ParseUtils.isMatchGlobPattern("", "xxx"));
    assertFalse(ParseUtils.isMatchGlobPattern("abc", ""));
    assertFalse(ParseUtils.isMatchGlobPattern("a*bc", ""));
    assertFalse(ParseUtils.isMatchGlobPattern("*abc", ""));
    assertFalse(ParseUtils.isMatchGlobPattern("abc*", ""));

    // Star Case
    assertTrue(ParseUtils.isMatchGlobPattern("*", ""));
    assertTrue(ParseUtils.isMatchGlobPattern("*", "xxx"));

    // Normal Case
    assertTrue(ParseUtils.isMatchGlobPattern("abc*123", "abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("abc*123", "abcXXX123"));
    assertFalse(ParseUtils.isMatchGlobPattern("abc*123", "abcXXX333"));

    assertTrue(ParseUtils.isMatchGlobPattern("*abc123", "abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("*abc123", "XXXabc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("*abc123", "abc123abc123"));
    assertFalse(ParseUtils.isMatchGlobPattern("*abc123", "abc123abc333"));
    
    assertTrue(ParseUtils.isMatchGlobPattern("abc123*", "abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("abc123*", "abc123YYY"));
    assertTrue(ParseUtils.isMatchGlobPattern("abc123*", "abc123abc123"));
    assertFalse(ParseUtils.isMatchGlobPattern("abc123*", "abc333abc123"));
    
    // 有两个星号,不支持,行为未定义
    assertFalse(ParseUtils.isMatchGlobPattern("*abc123*", "abc123abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("*abc123*", "*abc123abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("*abc123*", "*abc123XXX"));
}
 
Example #23
Source File: RelateUserUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 添加与服务模式相关的Owner
 * 
 * @param usernames 用于添加的用户名
 * @param serviceNamePattern 服务模式,Glob模式
 */
public static void addOwnersOfServicePattern(Set<String> usernames, String serviceNamePattern,
                                            OwnerService ownerDAO) {
    List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
    for (String p : serviceNamePatterns) {
        if (ParseUtils.hasIntersection(p, serviceNamePattern)) {
            List<String> list = ownerDAO.findUsernamesByServiceName(p);
            usernames.addAll(list);
        }
    }
}
 
Example #24
Source File: ParseUtilsTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void test_hasIntersection() throws Exception {
    assertFalse(ParseUtils.hasIntersection(null, null));
    assertFalse(ParseUtils.hasIntersection("dog", null));
    assertFalse(ParseUtils.hasIntersection(null, "god"));

    assertTrue(ParseUtils.hasIntersection("hello", "hello*"));
    assertTrue(ParseUtils.hasIntersection("helloxxx", "hello*"));
    assertTrue(ParseUtils.hasIntersection("world", "*world"));
    assertTrue(ParseUtils.hasIntersection("xxxworld", "*world"));
    assertTrue(ParseUtils.hasIntersection("helloworld", "hello*world"));
    assertTrue(ParseUtils.hasIntersection("helloxxxworld", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("Yhelloxxxworld", "hello*world"));

    assertTrue(ParseUtils.hasIntersection("hello*", "hello"));
    assertTrue(ParseUtils.hasIntersection("hello*", "helloxxx"));
    assertTrue(ParseUtils.hasIntersection("*world", "world"));
    assertTrue(ParseUtils.hasIntersection("*world", "xxxworld"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "helloworld"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "helloxxxworld"));
    assertFalse(ParseUtils.hasIntersection("hello*world", "Yhelloxxxworld"));

    assertTrue(ParseUtils.hasIntersection("*world", "hello*world"));
    assertTrue(ParseUtils.hasIntersection("*world", "hello*Zworld"));
    assertTrue(ParseUtils.hasIntersection("helloZ*", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("Zhello*", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "hello*world"));
    assertTrue(ParseUtils.hasIntersection("hello*world", "hello*Zworld"));
    assertTrue(ParseUtils.hasIntersection("helloZ*world", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("Zhello*world", "hello*world"));
    assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ"));
}
 
Example #25
Source File: ParseUtilsTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceWeight() throws Exception {
    assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=12",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&application=morgan&weight=10", "weight", "12"));
    assertEquals(
            "dubbo://172.22.3.91:20880/memberService?version=1.0.0&weight=12&application=morgan",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?version=1.0.0&weight=10&application=morgan", "weight", "12"));
    assertEquals(
            "dubbo://172.22.3.91:20880/memberService?weight=12&version=1.0.0&application=morgan",
            ParseUtils.replaceParameter("dubbo://172.22.3.91:20880/memberService?weight=10&version=1.0.0&application=morgan", "weight", "12"));
}
 
Example #26
Source File: ParseUtilsTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_appendParamToUri() throws Exception {
    String append = ParseUtils.appendParamToUri("dubbo://11.22.33.44/serviceName?k1=v1&k2=v2", "k3", "v3");
    assertEquals("dubbo://11.22.33.44/serviceName?k1=v1&k2=v2&k3=v3", append);

    Map<String, String> params = new LinkedHashMap<String, String>();
    params.put("k3", "v3");
    params.put("k4", "v4");
    append = ParseUtils.appendParamsToUri("dubbo://11.22.33.44/serviceName?k1=v1&k2=v2", params);
    assertEquals("dubbo://11.22.33.44/serviceName?k1=v1&k2=v2&k3=v3&k4=v4", append);
}
 
Example #27
Source File: ParseUtilsTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsMatchGlobPattern() throws Exception {
    // Null Case
    assertTrue(ParseUtils.isMatchGlobPattern(null, null));
    assertFalse(ParseUtils.isMatchGlobPattern("abc", null));
    assertFalse(ParseUtils.isMatchGlobPattern(null, "xxx"));
    
    // empty string
    assertTrue(ParseUtils.isMatchGlobPattern("", ""));
    assertFalse(ParseUtils.isMatchGlobPattern("", "xxx"));
    assertFalse(ParseUtils.isMatchGlobPattern("abc", ""));
    assertFalse(ParseUtils.isMatchGlobPattern("a*bc", ""));
    assertFalse(ParseUtils.isMatchGlobPattern("*abc", ""));
    assertFalse(ParseUtils.isMatchGlobPattern("abc*", ""));

    // Star Case
    assertTrue(ParseUtils.isMatchGlobPattern("*", ""));
    assertTrue(ParseUtils.isMatchGlobPattern("*", "xxx"));

    // Normal Case
    assertTrue(ParseUtils.isMatchGlobPattern("abc*123", "abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("abc*123", "abcXXX123"));
    assertFalse(ParseUtils.isMatchGlobPattern("abc*123", "abcXXX333"));

    assertTrue(ParseUtils.isMatchGlobPattern("*abc123", "abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("*abc123", "XXXabc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("*abc123", "abc123abc123"));
    assertFalse(ParseUtils.isMatchGlobPattern("*abc123", "abc123abc333"));
    
    assertTrue(ParseUtils.isMatchGlobPattern("abc123*", "abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("abc123*", "abc123YYY"));
    assertTrue(ParseUtils.isMatchGlobPattern("abc123*", "abc123abc123"));
    assertFalse(ParseUtils.isMatchGlobPattern("abc123*", "abc333abc123"));
    
    // 有两个星号,不支持,行为未定义
    assertFalse(ParseUtils.isMatchGlobPattern("*abc123*", "abc123abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("*abc123*", "*abc123abc123"));
    assertTrue(ParseUtils.isMatchGlobPattern("*abc123*", "*abc123XXX"));
}
 
Example #28
Source File: ParseUtilsTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseQueryMultiKeyValue() throws Exception {
    Map<String, String> result = new HashMap<String, String>();
    result.put("verion", "1.0.0");
    result.put("cluster", "china");
    assertEquals(result, ParseUtils.parseQuery("", "verion=1.0.0&cluster=china"));
}
 
Example #29
Source File: ParseUtilsTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterByGlobPattern() throws Exception {
    Collection<String> values = new ArrayList<String>();
    values.add("abc123");
    values.add("JQKxyz");
    values.add("abc123");
    values.add("abcLLL");
    
    Set<String> filter = ParseUtils.filterByGlobPattern("abc*", values);
    Set<String> expected = new HashSet<String>();
    expected.add("abc123");
    expected.add("abcLLL");
    
    assertEquals(expected, filter);

    filter = ParseUtils.filterByGlobPattern((Collection<String>)null, values);
    assertTrue(filter.isEmpty()); 
    
    Collection<String> patterns = new ArrayList<String>();
    patterns.add("000000000");
    patterns.add("abc*");
    patterns.add("*xyz");

    filter = ParseUtils.filterByGlobPattern(patterns, values);
    
    expected.add("JQKxyz");
    assertEquals(expected, filter);
}
 
Example #30
Source File: Routes.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 添加与服务相关的Owner
 * 
 * @param usernames 用于添加的用户名
 * @param serviceName 不含通配符
 */
public static void addOwnersOfService(Set<String> usernames, String serviceName,
                                      OwnerService ownerDAO) {
    List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
    for (String p : serviceNamePatterns) {
        if (ParseUtils.isMatchGlobPattern(p, serviceName)) {
            List<String> list = ownerDAO.findUsernamesByServiceName(p);
            usernames.addAll(list);
        }
    }
}