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.script;
16:
17: import java.util.Properties;
18:
19: import junit.framework.TestCase;
20:
21: import org.apache.log4j.Logger;
22: import org.apache.velocity.app.Velocity;
23: import org.ztemplates.classpath.ZClassRepository;
24: import org.ztemplates.classpath.ZIClassRepository;
25: import org.ztemplates.render.ZRenderEngine;
26: import org.ztemplates.render.ZRenderEnvironment;
27:
28: public class ScriptTest extends TestCase {
29: static Logger log = Logger.getLogger(ScriptTest.class);
30:
31: private ZIClassRepository classes;
32:
33: protected void setUp() throws Exception {
34: super .setUp();
35: classes = new ZClassRepository(ScriptTest.class.getPackage()
36: .getName());
37:
38: Properties prop = new Properties();
39: prop.put("resource.loader", "classpath");
40: prop
41: .put("classpath.resource.loader.class",
42: "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
43: Velocity.init(prop);
44: }
45:
46: protected void tearDown() throws Exception {
47: super .tearDown();
48: classes = null;
49: }
50:
51: public void testRootExposeRenderTrue() throws Exception {
52: ZRenderEngine re = new ZRenderEngine(new ZRenderEnvironment(
53: classes));
54: RootExposeRenderTrue root = new RootExposeRenderTrue();
55: String s = re.render(root);
56: assertTrue(s, s.indexOf("root.js") >= 0);
57: assertTrue(s, s.indexOf("nested.js") >= 0);
58: assertTrue(s, s.indexOf("invalid values") >= 0);
59: }
60:
61: public void testRootExposeRenderFalse() throws Exception {
62: ZRenderEngine re = new ZRenderEngine(new ZRenderEnvironment(
63: classes));
64: RootExposeRenderFalse root = new RootExposeRenderFalse();
65: String s = re.render(root);
66: assertTrue(s, s.indexOf("$renderService") >= 0);
67: assertTrue(s, s.indexOf("root.js") >= 0);
68: assertTrue(s, s.indexOf("nested.js") < 0);
69: }
70: }
|