01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TemplateTestCase.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.template;
09:
10: import com.uwyn.rife.resources.ResourceFinderClasspath;
11: import com.uwyn.rife.resources.exceptions.ResourceFinderErrorException;
12: import com.uwyn.rife.tools.ExceptionUtils;
13: import com.uwyn.rife.tools.FileUtils;
14: import com.uwyn.rife.tools.InnerClassException;
15: import com.uwyn.rife.tools.InputStreamUser;
16: import com.uwyn.rife.tools.exceptions.FileUtilsErrorException;
17: import java.io.InputStream;
18: import junit.framework.TestCase;
19:
20: public abstract class TemplateTestCase extends TestCase {
21: public TemplateTestCase(String name) {
22: super (name);
23: }
24:
25: String getTemplateContent(final String filename, Parser parser) {
26: ResourceFinderClasspath resource_finder = ResourceFinderClasspath
27: .getInstance();
28: String template_path = filename + parser.getExtension();
29: try {
30: return (String) resource_finder.useStream(template_path,
31: new InputStreamUser() {
32: public String useInputStream(InputStream stream)
33: throws InnerClassException {
34: if (null != stream) {
35: String template_content = null;
36: try {
37: template_content = FileUtils
38: .readString(stream);
39: } catch (FileUtilsErrorException e) {
40: assertTrue(ExceptionUtils
41: .getExceptionStackTrace(e),
42: false);
43: }
44:
45: return template_content;
46: }
47: assertTrue("Could not find file '"
48: + filename + "'.", false);
49:
50: return null;
51: }
52: });
53: } catch (ResourceFinderErrorException e) {
54: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
55: }
56:
57: return null;
58: }
59: }
|