001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.util;
018:
019: import java.util.Map;
020:
021: import junit.framework.TestCase;
022:
023: /**
024: * @version $Id: WildcardMatcherHelperTestCase.java 448573 2006-09-21 14:52:23Z anathaniel $
025: */
026: public class WildcardMatcherHelperTestCase extends TestCase {
027:
028: //~ Methods ------------------------------------------------------------------------------------
029:
030: public void test01WildcardURIMatch() throws Exception {
031: Map result = WildcardMatcherHelper.match("test", "test");
032: assertNotNull(result);
033: assertEquals("test", result.get("0"));
034: assertNull(result.get("1"));
035: }
036:
037: public void test02WildcardURIMatch() throws Exception {
038: Map result = WildcardMatcherHelper.match("end", "enp");
039: assertNull(result);
040: }
041:
042: public void test03WildcardURIMatch() throws Exception {
043: Map result = WildcardMatcherHelper.match("/t\\*d", "/t*d");
044: assertNotNull(result);
045: assertEquals("/t*d", result.get("0"));
046: }
047:
048: public void test04WildcardURIMatch() throws Exception {
049: Map result = WildcardMatcherHelper.match("\\*d", "*d");
050: assertNotNull(result);
051: assertEquals("*d", result.get("0"));
052: }
053:
054: public void test05WildcardURIMatch() throws Exception {
055: Map result = WildcardMatcherHelper.match("**", "*d");
056: assertNotNull(result);
057: assertEquals("*d", result.get("0"));
058: assertEquals("*d", result.get("1"));
059: }
060:
061: public void test06WildcardURIMatch() throws Exception {
062: Map result = WildcardMatcherHelper.match("foo**", "foo*d");
063: assertNotNull(result);
064: assertEquals("foo*d", result.get("0"));
065: assertEquals("*d", result.get("1"));
066: }
067:
068: public void test07WildcardURIMatch() throws Exception {
069: Map result = WildcardMatcherHelper.match("end", "en");
070: assertNull(result);
071: }
072:
073: public void test08WildcardURIMatch() throws Exception {
074: Map result = WildcardMatcherHelper.match("en", "end");
075: assertNull(result);
076: }
077:
078: public void test09WildcardURIMatch() throws Exception {
079: Map result = WildcardMatcherHelper.match("end**", "end");
080: assertNotNull(result);
081: assertEquals("", result.get("1"));
082: }
083:
084: public void test10WildcardURIMatch() throws Exception {
085: Map result = WildcardMatcherHelper.match("end**end",
086: "endendend");
087: assertNotNull(result);
088: assertEquals("end", result.get("1"));
089: }
090:
091: public void test11WildcardURIMatch() throws Exception {
092: Map result = WildcardMatcherHelper
093: .match("end**end", "endxxend");
094: assertNotNull(result);
095: assertEquals("xx", result.get("1"));
096: }
097:
098: public void test12WildcardURIMatch() throws Exception {
099: Map result = WildcardMatcherHelper.match("*/end", "xx/end");
100: assertNotNull(result);
101: assertEquals("xx", result.get("1"));
102: }
103:
104: public void test13WildcardURIMatch() throws Exception {
105: Map result = WildcardMatcherHelper.match("ab/cd*/end",
106: "ab/cdxx/end");
107: assertNotNull(result);
108: assertEquals("xx", result.get("1"));
109: }
110:
111: public void test14WildcardURIMatch() throws Exception {
112: Map result = WildcardMatcherHelper.match("a*/cd*/end",
113: "ab/cdxx/end");
114: assertNotNull(result);
115: assertEquals("b", result.get("1"));
116: assertEquals("xx", result.get("2"));
117: }
118:
119: public void test15WildcardURIMatch() throws Exception {
120: Map result = WildcardMatcherHelper.match("a**/cd*/end",
121: "ab/yy/cdxx/end");
122: assertNotNull(result);
123: assertEquals("b/yy", result.get("1"));
124: assertEquals("xx", result.get("2"));
125: }
126:
127: public void test16WildcardURIMatch() throws Exception {
128: Map result = WildcardMatcherHelper.match("a**/cd*/end/*",
129: "ab/yy/cdxx/end/foobar/ii");
130: assertNull(result);
131: }
132:
133: public void test17WildcardURIMatch() throws Exception {
134: Map result = WildcardMatcherHelper.match("a**/cd*/end/**",
135: "ab/yy/cdxx/end/foobar/ii");
136: assertNotNull(result);
137: assertEquals("b/yy", result.get("1"));
138: assertEquals("xx", result.get("2"));
139: assertEquals("foobar/ii", result.get("3"));
140: }
141:
142: public void test18WildcardURIMatch() throws Exception {
143: Map result = WildcardMatcherHelper.match("a**cd*/end/**",
144: "ab/yy/cdxx/end/foobar/ii");
145: assertNotNull(result);
146: assertEquals("b/yy/", result.get("1"));
147: assertEquals("xx", result.get("2"));
148: assertEquals("foobar/ii", result.get("3"));
149: }
150:
151: public void test19WildcardURIMatch() throws Exception {
152: Map result = WildcardMatcherHelper.match("*/*.xml",
153: "test/something.xmlbla.xml");
154: assertNotNull(result);
155: assertEquals("test", result.get("1"));
156: assertEquals("something.xmlbla", result.get("2"));
157: }
158:
159: public void test20WildcardURIMatch() throws Exception {
160: Map result = WildcardMatcherHelper.match("ab/cd*/end",
161: "ab/cd/end");
162: assertNotNull(result);
163: assertEquals("", result.get("1"));
164: }
165:
166: public void test21WildcardURIMatch() throws Exception {
167: Map result = WildcardMatcherHelper.match("*/**",
168: "samples/blocks/");
169: assertNotNull(result);
170: assertEquals("samples", result.get("1"));
171: assertEquals("blocks/", result.get("2"));
172: }
173:
174: public void test22WildcardURIMatch() throws Exception {
175: Map result = WildcardMatcherHelper.match("*/**", "samples/");
176: assertNotNull(result);
177: assertEquals("samples", result.get("1"));
178: assertEquals("", result.get("2"));
179: }
180:
181: public void test23WildcardURIMatch() throws Exception {
182: Map result = WildcardMatcherHelper.match("**favicon.ico",
183: "samples/");
184: assertNull(result);
185: }
186:
187: public void test24WildcardURIMatch() throws Exception {
188: Map result = WildcardMatcherHelper.match("**favicon.ico",
189: "samples1234/");
190: assertNull(result);
191: }
192:
193: public void test25WildcardURIMatch() throws Exception {
194: Map result = WildcardMatcherHelper.match("**favicon.ico",
195: "samples123/");
196: assertNull(result);
197: }
198:
199: public void test26WildcardURIMatch() throws Exception {
200: Map result = WildcardMatcherHelper.match("**/*/**",
201: "foo/bar/baz/bug");
202: assertNotNull(result);
203: assertEquals("foo/bar", result.get("1"));
204: assertEquals("baz", result.get("2"));
205: assertEquals("bug", result.get("3"));
206: }
207:
208: public void test27WildcardURIMatch() throws Exception {
209: Map result = WildcardMatcherHelper.match("end*end*end*end",
210: "endXXendYendend");
211: assertNotNull(result);
212: assertEquals("XX", result.get("1"));
213: assertEquals("Y", result.get("2"));
214: assertEquals("", result.get("3"));
215: }
216:
217: public void test28WildcardURIMatch() throws Exception {
218: Map result = WildcardMatcherHelper.match("end*end*end*end",
219: "endendendend");
220: assertNotNull(result);
221: assertEquals("", result.get("1"));
222: assertEquals("", result.get("2"));
223: assertEquals("", result.get("3"));
224: }
225:
226: public void test29WildcardURIMatch() throws Exception {
227: Map result = WildcardMatcherHelper.match("end**end**end**end",
228: "endXXendYendend");
229: assertNotNull(result);
230: assertEquals("XX", result.get("1"));
231: assertEquals("Y", result.get("2"));
232: assertEquals("", result.get("3"));
233: }
234:
235: public void test30WildcardURIMatch() throws Exception {
236: Map result = WildcardMatcherHelper.match("end**end**end**end",
237: "endendendend");
238: assertNotNull(result);
239: assertEquals("", result.get("1"));
240: assertEquals("", result.get("2"));
241: assertEquals("", result.get("3"));
242: }
243:
244: public void test31WildcardURIMatch() throws Exception {
245: Map result = WildcardMatcherHelper.match("*/", "test/foo/bar");
246: assertNull(result);
247: }
248:
249: public void test32WildcardURIMatch() throws Exception {
250: Map result = WildcardMatcherHelper.match("**/*.html",
251: "foo/bar/baz.html");
252: assertNotNull(result);
253: assertEquals("baz", result.get("2"));
254: assertEquals("foo/bar", result.get("1"));
255: }
256:
257: public void test33WildcardURIMatch() throws Exception {
258: Map result = WildcardMatcherHelper.match("*.html",
259: "menu/baz.html");
260: assertNull(result);
261: }
262:
263: public void test34WildcardURIMatch() throws Exception {
264: Map result = WildcardMatcherHelper.match("*.html", "baz.html");
265: assertNotNull(result);
266: assertEquals("baz", result.get("1"));
267: }
268:
269: public void test35WildcardURIMatch() throws Exception {
270: Map result = WildcardMatcherHelper.match("menu/**/foo_*_bar.*",
271: "menu//foo_baz_bar.html");
272: assertNotNull(result);
273: assertEquals("", result.get("1"));
274: assertEquals("baz", result.get("2"));
275: assertEquals("html", result.get("3"));
276: }
277:
278: public void test36WildcardURIMatch() throws Exception {
279: Map result = WildcardMatcherHelper.match("menu/**/foo/*",
280: "menu/bar/baz.xml");
281: assertNull(result);
282: }
283:
284: public void test37WildcardURIMatch() throws Exception {
285: Map result = WildcardMatcherHelper.match("menu/*.xml",
286: "menu/foo/bar.xml");
287: assertNull(result);
288: }
289:
290: public void test38WildcardURIMatch() throws Exception {
291: Map result = WildcardMatcherHelper.match("\\\\foo\\*\\n\\0\\",
292: "\\foo*\\n\\0\\");
293: assertNotNull(result);
294: }
295:
296: public void testEmptyPattern() throws Exception {
297: assertNotNull(WildcardMatcherHelper.match("", ""));
298: assertNull(WildcardMatcherHelper.match("", "foo"));
299: assertNull(WildcardMatcherHelper.match("", "foo/bar"));
300: }
301:
302: public void testEndPattern() throws Exception {
303: assertNotNull(WildcardMatcherHelper.match("*/", "foo/"));
304: assertNull(WildcardMatcherHelper.match("*/", "foo/bar/"));
305: assertNull(WildcardMatcherHelper.match("*/", "test/foo/bar/"));
306: }
307: }
|