1   package org.apache.velocity.test;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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.test.misc.TestLogChute;
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 704299 2008-10-14 03:13:16Z nbubna $
37   */
38  public class VelocityAppTestCase extends BaseTestCase implements TemplateTestBase
39  {
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      {
46          super(name);
47      }
48  
49      public void setUp()
50              throws Exception
51      {
52          Velocity.setProperty(
53                  Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
54  
55          Velocity.setProperty(
56                  Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, TestLogChute.class.getName());
57  
58          Velocity.init();
59      }
60  
61      public static Test suite()
62      {
63          return new TestSuite(VelocityAppTestCase.class);
64      }
65  
66      /**
67       * Runs the test.
68       */
69      public void testVelocityApp ()
70              throws Exception
71      {
72          VelocityContext context = new VelocityContext();
73          context.put("name", "jason");
74          context.put("Floog", "floogie woogie");
75  
76              Velocity.evaluate(context, compare1, "evaltest", input1);
77  
78  /*
79   *            @todo FIXME: Not tested right now.
80   *
81   *            StringWriter result2 = new StringWriter();
82   *            Velocity.mergeTemplate("mergethis.vm",  context, result2);
83   *
84   *            StringWriter result3 = new StringWriter();
85   *            Velocity.invokeVelocimacro("floog", "test", new String[2],
86   *                                        context, result3);
87   */
88              if (!result1.equals(compare1.toString()))
89              {
90                  fail("Output incorrect.");
91              }
92      }
93  }