01: package org.mortbay.cometd;
02:
03: import junit.framework.TestCase;
04:
05: public class ChannelPatternTest extends TestCase {
06:
07: public void testChannelPattern() {
08: ChannelPattern pattern;
09:
10: pattern = new ChannelPattern("/test/abc");
11: assertTrue(pattern.matches("/test/abc"));
12: assertFalse(pattern.matches("/test/abc/more"));
13: assertFalse(pattern.matches("/test/ab"));
14: assertFalse(pattern.matches("/abc"));
15: assertFalse(pattern.matches(""));
16:
17: pattern = new ChannelPattern("/test/*");
18: assertTrue(pattern.matches("/test/a"));
19: assertTrue(pattern.matches("/test/abc"));
20: assertFalse(pattern.matches("/test/abc/foo"));
21: assertFalse(pattern.matches("/tost/abc"));
22: assertFalse(pattern.matches("/test"));
23:
24: pattern = new ChannelPattern("/test/a*");
25: assertTrue(pattern.matches("/test/ac"));
26: assertTrue(pattern.matches("/test/abc"));
27: assertTrue(pattern.matches("/test/abbbbc"));
28: assertFalse(pattern.matches("/test/a/c"));
29: assertFalse(pattern.matches("/test/abc/def"));
30: assertFalse(pattern.matches("/tost/abc"));
31: assertFalse(pattern.matches("/test"));
32:
33: pattern = new ChannelPattern("/test/a*c");
34: assertTrue(pattern.matches("/test/ac"));
35: assertTrue(pattern.matches("/test/abc"));
36: assertTrue(pattern.matches("/test/abbbbc"));
37: assertFalse(pattern.matches("/test/a/c"));
38: assertFalse(pattern.matches("/test/abc/def"));
39: assertFalse(pattern.matches("/tost/abc"));
40: assertFalse(pattern.matches("/test"));
41:
42: pattern = new ChannelPattern("/test/*/foo");
43: assertTrue(pattern.matches("/test/abc/foo"));
44: assertFalse(pattern.matches("/test/foo"));
45: assertFalse(pattern.matches("/test/abc/def/foo"));
46:
47: pattern = new ChannelPattern("/test/**/foo");
48: assertTrue(pattern.matches("/test/foo"));
49: assertTrue(pattern.matches("/test/abc/foo"));
50: assertTrue(pattern.matches("/test/abc/def/foo"));
51:
52: pattern = new ChannelPattern("/test/a**c/foo");
53: assertTrue(pattern.matches("/test/ac/foo"));
54: assertTrue(pattern.matches("/test/abc/foo"));
55: assertTrue(pattern.matches("/test/ab/bc/foo"));
56:
57: pattern = new ChannelPattern("/abc,/test/*,/other/**/foo");
58: assertTrue(pattern.matches("/abc"));
59: assertTrue(pattern.matches("/test/xxx"));
60: assertTrue(pattern.matches("/other/xxx/foo"));
61: assertFalse(pattern.matches("/abcd"));
62: assertFalse(pattern.matches("/test"));
63: assertFalse(pattern.matches("/other/abc"));
64:
65: }
66: }
|