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: * 22.09.2007
13: * @author www.gerdziegler.de
14: */
15: package org.ztemplates.test.actions.urlhandler.repository.nested;
16:
17: import junit.framework.TestCase;
18:
19: import org.apache.log4j.Logger;
20: import org.ztemplates.actions.urlhandler.ZIUrlHandler;
21: import org.ztemplates.actions.urlhandler.tree.ZUrlHandlerFactory;
22:
23: public class NestedHandlerTest extends TestCase {
24: static Logger log = Logger.getLogger(NestedHandlerTest.class);
25:
26: protected void setUp() throws Exception {
27: super .setUp();
28: }
29:
30: protected void tearDown() throws Exception {
31: super .tearDown();
32: }
33:
34: // public void test1() throws Exception
35: // {
36: // ZIUrlHandler up =
37: // ZUrlHandlerFactory.create(NestedHandlerTest.class.getPackage().getName());
38: // NestedHandler obj = (NestedHandler) up.process("nested/katzeklo");
39: // assertNotNull(obj);
40: // assertEquals("katzeklo", obj.getValue());
41: // assertEquals(1, obj.getBeforeCalled());
42: // assertEquals(1, obj.getAfterCalled());
43: // }
44:
45: public void test2() throws Exception {
46: ZIUrlHandler up = ZUrlHandlerFactory.create(
47: NestedHandlerTest.class.getPackage().getName(),
48: ZUrlHandlerFactory.defaultSecurityService);
49: Handler obj = (Handler) up
50: .process("/audiobooks/nested/katzeklo");
51: assertNotNull(obj);
52: assertEquals("katzeklo", obj.getNested().getValue());
53: assertEquals(1, obj.getBeforeCalled());
54: assertEquals(1, obj.getAfterCalled());
55: assertEquals(1, obj.getBeforeNestedCalled());
56: assertEquals(1, obj.getAfterNestedCalled());
57:
58: obj.getNested().setValue("froh");
59: String s = up.createUrl(obj);
60: log.debug(s);
61:
62: Handler obj2 = (Handler) up.process(s);
63: assertEquals("froh", obj2.getNested().getValue());
64: assertEquals(1, obj2.getBeforeCalled());
65: assertEquals(1, obj2.getAfterCalled());
66: assertEquals(1, obj2.getNested().getBeforeCalled());
67: assertEquals(1, obj2.getNested().getAfterCalled());
68: assertEquals(1, obj2.getNested().getBeforeValueCalled());
69: assertEquals(1, obj2.getNested().getAfterValueCalled());
70: }
71: }
|