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: 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: * Path for templates. This property will override the
41: * value in the default velocity properties file.
42: */
43: private final static String FILE_RESOURCE_LOADER_PATH = "test/resourcecaching";
44:
45: /**
46: * Default constructor.
47: */
48: public ResourceCachingTestCase(String name) {
49: super (name);
50: }
51:
52: public void setUp() throws Exception {
53:
54: }
55:
56: public static Test suite() {
57: return new TestSuite(ResourceCachingTestCase.class);
58: }
59:
60: /**
61: * Tests for fix of bug VELOCITY-98 where a #include followed by #parse
62: * of the same file throws ClassCastException when caching is on.
63: * @throws Exception
64: */
65: public void testIncludeParseCaching() throws Exception {
66:
67: VelocityEngine ve = new VelocityEngine();
68:
69: ve.setProperty("file.resource.loader.cache", "true");
70: ve.setProperty("file.resource.loader.path",
71: FILE_RESOURCE_LOADER_PATH);
72: ve.init();
73:
74: Template template = ve.getTemplate("testincludeparse.vm");
75:
76: Writer writer = new StringWriter();
77:
78: VelocityContext context = new VelocityContext();
79:
80: // will produce a ClassCastException if Velocity-98 is not solved
81: template.merge(context, writer);
82: writer.flush();
83: writer.close();
84: }
85:
86: }
|