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