01: /*
02: * Copyright 2007 Gerd Ziegler (www.gerdziegler.de)
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: * http://www.apache.org/licenses/LICENSE-2.0
07: * Unless required by applicable law or agreed to in writing,
08: * software distributed under the License is distributed on an
09: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10: * either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: * 20.09.2007
13: * @author www.gerdziegler.de
14: */
15: package org.ztemplates.test.actions.urlhandler.match.handler;
16:
17: import junit.framework.TestCase;
18:
19: import org.apache.log4j.Logger;
20: import org.ztemplates.actions.urlhandler.tree.match.ZMatchTree;
21: import org.ztemplates.actions.urlhandler.tree.match.ZMatchedUrl;
22: import org.ztemplates.classpath.ZClassRepository;
23: import org.ztemplates.classpath.ZIClassRepository;
24:
25: public class ParseTreeTest extends TestCase {
26: static Logger log = Logger.getLogger(ParseTreeTest.class);
27:
28: ZIClassRepository classRepo;
29:
30: ZMatchTree han;
31:
32: protected void setUp() throws Exception {
33: super .setUp();
34: classRepo = new ZClassRepository(ParseTreeTest.class
35: .getPackage().getName());
36: han = new ZMatchTree(classRepo);
37: }
38:
39: protected void tearDown() throws Exception {
40: classRepo = null;
41: han = null;
42: super .tearDown();
43: }
44:
45: public void testParseTree() throws Exception {
46: ZMatchedUrl proc = han.match("/path1/path2");
47: assertNotNull(proc);
48: }
49:
50: public void testParseTree2() throws Exception {
51: ZMatchedUrl proc = han.match("/path2/path2");
52: assertNull(proc);
53: }
54:
55: public void testParseTree3() throws Exception {
56: ZMatchedUrl proc = han.match("/path1/path3");
57: assertNull(proc);
58: }
59:
60: public void testParseTree4() throws Exception {
61: ZMatchedUrl proc = han.match("/path3/v3-id");
62: assertNotNull(proc);
63: assertEquals("v3", proc.getValues().get(0));
64: }
65:
66: public void testParseTree5() throws Exception {
67: ZMatchedUrl proc = han.match("/path4/klo-x-id-a-klo/katze");
68: assertNotNull(proc);
69: assertEquals("x", proc.getValues().get(0));
70: assertEquals("a", proc.getValues().get(1));
71: }
72:
73: public void testParseTree6EmptyVariable() throws Exception {
74: ZMatchedUrl proc = han.match("/path4/klo--id-a-klo/katze");
75: assertNull(proc);
76: }
77:
78: public void testParseTree7() throws Exception {
79: ZMatchedUrl proc = han.match("/path5/klo-x");
80: assertNotNull(proc);
81: assertEquals("x", proc.getValues().get(0));
82: }
83:
84: public void testParseTree8() throws Exception {
85: ZMatchedUrl proc = han.match("/path5/klo-");
86: assertNull(proc);
87: }
88: }
|