1 16 17 package org.springframework.util; 18 19 import junit.framework.TestCase; 20 21 24 public class PathMatcherTests extends TestCase { 25 26 public void testAntPathMatcher() { 27 PathMatcher pathMatcher = new AntPathMatcher(); 28 29 assertTrue(pathMatcher.match("test", "test")); 31 assertTrue(pathMatcher.match("/test", "/test")); 32 assertFalse(pathMatcher.match("/test.jpg", "test.jpg")); 33 assertFalse(pathMatcher.match("test", "/test")); 34 assertFalse(pathMatcher.match("/test", "test")); 35 36 assertTrue(pathMatcher.match("t?st", "test")); 38 assertTrue(pathMatcher.match("??st", "test")); 39 assertTrue(pathMatcher.match("tes?", "test")); 40 assertTrue(pathMatcher.match("te??", "test")); 41 assertTrue(pathMatcher.match("?es?", "test")); 42 assertFalse(pathMatcher.match("tes?", "tes")); 43 assertFalse(pathMatcher.match("tes?", "testt")); 44 assertFalse(pathMatcher.match("tes?", "tsst")); 45 46 assertTrue(pathMatcher.match("*", "test")); 48 assertTrue(pathMatcher.match("test*", "test")); 49 assertTrue(pathMatcher.match("test*", "testTest")); 50 assertTrue(pathMatcher.match("*test*", "AnothertestTest")); 51 assertTrue(pathMatcher.match("*test", "Anothertest")); 52 assertTrue(pathMatcher.match("*.*", "test.")); 53 assertTrue(pathMatcher.match("*.*", "test.test")); 54 assertTrue(pathMatcher.match("*.*", "test.test.test")); 55 assertTrue(pathMatcher.match("test*aaa", "testblaaaa")); 56 assertFalse(pathMatcher.match("test*", "tst")); 57 assertFalse(pathMatcher.match("test*", "tsttest")); 58 assertFalse(pathMatcher.match("*test*", "tsttst")); 59 assertFalse(pathMatcher.match("*test", "tsttst")); 60 assertFalse(pathMatcher.match("*.*", "tsttst")); 61 assertFalse(pathMatcher.match("test*aaa", "test")); 62 assertFalse(pathMatcher.match("test*aaa", "testblaaab")); 63 64 assertTrue(pathMatcher.match("/?", "/a")); 66 assertTrue(pathMatcher.match("/?/a", "/a/a")); 67 assertTrue(pathMatcher.match("/a/?", "/a/b")); 68 assertTrue(pathMatcher.match("/??/a", "/aa/a")); 69 assertTrue(pathMatcher.match("/a/??", "/a/bb")); 70 assertTrue(pathMatcher.match("/?", "/a")); 71 72 assertTrue(pathMatcher.match("/**", "/testing/testing")); 74 assertTrue(pathMatcher.match("/*/**", "/testing/testing")); 75 assertTrue(pathMatcher.match("/**/*", "/testing/testing")); 76 assertTrue(pathMatcher.match("/bla/**/bla", "/bla/testing/testing/bla")); 77 assertTrue(pathMatcher.match("/bla/**/bla", "/bla/testing/testing/bla/bla")); 78 assertTrue(pathMatcher.match("/**/test", "/bla/bla/test")); 79 assertTrue(pathMatcher.match("/bla/**/**/bla", "/bla/bla/bla/bla/bla/bla")); 80 assertTrue(pathMatcher.match("/bla*bla/test", "/blaXXXbla/test")); 81 assertTrue(pathMatcher.match("/*bla/test", "/XXXbla/test")); 82 assertFalse(pathMatcher.match("/bla*bla/test", "/blaXXXbl/test")); 83 assertFalse(pathMatcher.match("/*bla/test", "XXXblab/test")); 84 assertFalse(pathMatcher.match("/*bla/test", "XXXbl/test")); 85 86 assertFalse(pathMatcher.match("/????", "/bala/bla")); 87 assertFalse(pathMatcher.match("/**/*bla", "/bla/bla/bla/bbb")); 88 89 assertTrue(pathMatcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing/")); 90 assertTrue(pathMatcher.match("/*bla*/**/bla/*", "/XXXblaXXXX/testing/testing/bla/testing")); 91 assertTrue(pathMatcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing")); 92 assertTrue(pathMatcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing.jpg")); 93 94 assertTrue(pathMatcher.match("*bla*/**/bla/**", "XXXblaXXXX/testing/testing/bla/testing/testing/")); 95 assertTrue(pathMatcher.match("*bla*/**/bla/*", "XXXblaXXXX/testing/testing/bla/testing")); 96 assertTrue(pathMatcher.match("*bla*/**/bla/**", "XXXblaXXXX/testing/testing/bla/testing/testing")); 97 assertFalse(pathMatcher.match("*bla*/**/bla/*", "XXXblaXXXX/testing/testing/bla/testing/testing")); 98 99 assertFalse(pathMatcher.match("/x/x/x/", "/x/x/**/bla")); 100 101 assertTrue(pathMatcher.match("", "")); 102 assertTrue(pathMatcher.match("", "")); 103 assertTrue(pathMatcher.match("", "")); 104 assertTrue(pathMatcher.match("", "")); 105 assertTrue(pathMatcher.match("", "")); 106 assertTrue(pathMatcher.match("", "")); 107 } 108 109 } 110 | Popular Tags |