01: package org.apache.velocity.test;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: import java.io.StringWriter;
23:
24: import junit.framework.Test;
25: import junit.framework.TestSuite;
26:
27: import org.apache.velocity.VelocityContext;
28: import org.apache.velocity.app.Velocity;
29: import org.apache.velocity.runtime.log.NullLogChute;
30:
31: /**
32: * This class is intended to test the app.Velocity.java class.
33: *
34: * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
35: * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
36: * @version $Id: VelocityAppTestCase.java 477002 2006-11-20 01:07:43Z henning $
37: */
38: public class VelocityAppTestCase extends BaseTestCase implements
39: TemplateTestBase {
40: private StringWriter compare1 = new StringWriter();
41: private String input1 = "My name is $name -> $Floog";
42: private String result1 = "My name is jason -> floogie woogie";
43:
44: public VelocityAppTestCase(String name) {
45: super (name);
46: }
47:
48: public void setUp() throws Exception {
49: Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,
50: FILE_RESOURCE_LOADER_PATH);
51:
52: Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS,
53: NullLogChute.class.getName());
54:
55: Velocity.init();
56: }
57:
58: public static Test suite() {
59: return new TestSuite(VelocityAppTestCase.class);
60: }
61:
62: /**
63: * Runs the test.
64: */
65: public void testVelocityApp() throws Exception {
66: VelocityContext context = new VelocityContext();
67: context.put("name", "jason");
68: context.put("Floog", "floogie woogie");
69:
70: Velocity.evaluate(context, compare1, "evaltest", input1);
71:
72: /*
73: * @todo FIXME: Not tested right now.
74: *
75: * StringWriter result2 = new StringWriter();
76: * Velocity.mergeTemplate("mergethis.vm", context, result2);
77: *
78: * StringWriter result3 = new StringWriter();
79: * Velocity.invokeVelocimacro("floog", "test", new String[2],
80: * context, result3);
81: */
82: if (!result1.equals(compare1.toString())) {
83: fail("Output incorrect.");
84: }
85: }
86: }
|