01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.matching;
18:
19: import java.util.Map;
20:
21: import org.apache.avalon.framework.parameters.Parameters;
22: import org.apache.cocoon.SitemapComponentTestCase;
23:
24: public class WildcardURIMatcherTestCase extends
25: SitemapComponentTestCase {
26:
27: public void testWildcardURIMatch() throws Exception {
28: getRequest().setRequestURI("/test/foo/bla/end");
29:
30: Parameters parameters = new Parameters();
31:
32: Map result = match("wildcard-uri", "**", parameters);
33: assertNotNull("Test if resource exists", result);
34: assertEquals("Test for **", "test/foo/bla/end", result.get("1"));
35:
36: result = match("wildcard-uri", "**/bla/*", parameters);
37: assertNotNull("Test if resource exists", result);
38: assertEquals("Test for **/bla/* {1}", "test/foo", result
39: .get("1"));
40: assertEquals("Test for **/bla/* {2}", "end", result.get("2"));
41: }
42:
43: public void testWildcardURIMatchSimplePattern() throws Exception {
44: getRequest().setRequestURI("/test");
45:
46: final Parameters parameters = new Parameters();
47:
48: Map result = match("wildcard-uri", "*", parameters);
49: assertNotNull("Test if resource exists", result);
50: assertEquals("Test for *", "test", result.get("1"));
51: }
52:
53: public void testWildcardURIMatchDoublePattern() throws Exception {
54: getRequest().setRequestURI("/test/something.xmlbla.xml");
55:
56: final Parameters parameters = new Parameters();
57:
58: Map result = match("wildcard-uri", "*/*.xml", parameters);
59: assertNotNull("Test if resource exists", result);
60: assertEquals("Test for */*.xml", "test", result.get("1"));
61: assertEquals("Test for */*.xml", "something.xmlbla", result
62: .get("2"));
63: }
64:
65: public void testWildcardURIMatchMultiSinglePattern()
66: throws Exception {
67: getRequest().setRequestURI("foo/bar/baz.html");
68:
69: final Parameters parameters = new Parameters();
70:
71: Map result = match("wildcard-uri", "**/*.html", parameters);
72: assertNotNull("Test if resource exists", result);
73: assertEquals("Test for {1} in **/*.html", "foo/bar", result
74: .get("1"));
75: assertEquals("Test for {2} in **/*.html", "baz", result
76: .get("2"));
77: }
78:
79: }
|