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 import java.io.Writer;
24
25 import junit.framework.Test;
26 import junit.framework.TestSuite;
27
28 import org.apache.velocity.Template;
29 import org.apache.velocity.VelocityContext;
30 import org.apache.velocity.app.VelocityEngine;
31 import org.apache.velocity.test.TemplateTestBase;
32
33 /**
34 * Test resource caching related issues.
35 *
36 * @author <a href="mailto:wglass@apache.org">Will Glass-Husain</a>
37 * @version $Id: ResourceCachingTestCase.java 957852 2010-06-25 08:53:22Z apetrelli $
38 */
39 public class ResourceCachingTestCase extends BaseTestCase
40 {
41 /**
42 * Path for templates. This property will override the
43 * value in the default velocity properties file.
44 */
45 private final static String FILE_RESOURCE_LOADER_PATH = "/resourcecaching";
46
47
48 /**
49 * Default constructor.
50 */
51 public ResourceCachingTestCase(String name)
52 {
53 super(name);
54 }
55
56 public void setUp()
57 throws Exception
58 {
59
60 }
61
62 public static Test suite ()
63 {
64 return new TestSuite(ResourceCachingTestCase.class);
65 }
66
67 /**
68 * Tests for fix of bug VELOCITY-98 where a #include followed by #parse
69 * of the same file throws ClassCastException when caching is on.
70 * @throws Exception
71 */
72 public void testIncludeParseCaching ()
73 throws Exception
74 {
75
76 VelocityEngine ve = new VelocityEngine();
77
78 ve.setProperty("file.resource.loader.cache", "true");
79 ve.setProperty("file.resource.loader.path", TemplateTestBase.TEST_COMPARE_DIR + FILE_RESOURCE_LOADER_PATH);
80 ve.init();
81
82 Template template = ve.getTemplate("testincludeparse.vm");
83
84 Writer writer = new StringWriter();
85
86 VelocityContext context = new VelocityContext();
87
88 // will produce a ClassCastException if Velocity-98 is not solved
89 template.merge(context, writer);
90 writer.flush();
91 writer.close();
92 }
93
94
95 }