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.render.inheritance;
16:
17: import java.util.Map;
18: import java.util.Properties;
19:
20: import junit.framework.TestCase;
21:
22: import org.apache.log4j.Logger;
23: import org.apache.velocity.app.Velocity;
24: import org.ztemplates.classpath.ZClassRepository;
25: import org.ztemplates.classpath.ZIClassRepository;
26: import org.ztemplates.render.ZRenderEngine;
27: import org.ztemplates.render.ZRenderEnvironment;
28:
29: public class InheritanceTest extends TestCase {
30: static Logger log = Logger.getLogger(InheritanceTest.class);
31:
32: private ZIClassRepository classes;
33:
34: protected void setUp() throws Exception {
35: super .setUp();
36: classes = new ZClassRepository(InheritanceTest.class
37: .getPackage().getName());
38:
39: Properties prop = new Properties();
40: prop.put("resource.loader", "classpath");
41: prop
42: .put("classpath.resource.loader.class",
43: "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
44: Velocity.init(prop);
45: }
46:
47: protected void tearDown() throws Exception {
48: super .tearDown();
49: classes = null;
50: }
51:
52: public void testExposed() throws Exception {
53: ZRenderEngine re = new ZRenderEngine(new ZRenderEnvironment(
54: classes));
55: ExtensionClass1 ext1 = new ExtensionClass1();
56: Map<String, Object> exposed = re.getExposed(ext1);
57: assertEquals("val1", exposed.get("prop1"));
58: assertEquals("val2", exposed.get("prop2"));
59: }
60:
61: public void testRenderedExtensionClass() throws Exception {
62: ZRenderEngine re = new ZRenderEngine(new ZRenderEnvironment(
63: classes));
64: ExtensionClass1 ext1 = new ExtensionClass1();
65: String rendered = re.render(ext1);
66: assertTrue(rendered.indexOf("val1") >= 0);
67: assertTrue(rendered.indexOf("val2") >= 0);
68: }
69:
70: public void testRenderedBaseClass() throws Exception {
71: ZRenderEngine re = new ZRenderEngine(new ZRenderEnvironment(
72: classes));
73: BaseClass base = new BaseClass();
74: String rendered = re.render(base);
75: assertTrue(rendered.indexOf("val1") >= 0);
76: }
77: }
|