KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freemarker > testcase > TestNumberLiteral


1 /*
2  * Copyright (c) 2003 The Visigoth Software Society. All rights
3  * reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowledgement:
19  * "This product includes software developed by the
20  * Visigoth Software Society (http://www.visigoths.org/)."
21  * Alternately, this acknowledgement may appear in the software itself,
22  * if and wherever such third-party acknowledgements normally appear.
23  *
24  * 4. Neither the name "FreeMarker", "Visigoth", nor any of the names of the
25  * project contributors may be used to endorse or promote products derived
26  * from this software without prior written permission. For written
27  * permission, please contact visigoths@visigoths.org.
28  *
29  * 5. Products derived from this software may not be called "FreeMarker" or "Visigoth"
30  * nor may "FreeMarker" or "Visigoth" appear in their names
31  * without prior written permission of the Visigoth Software Society.
32  *
33  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36  * DISCLAIMED. IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR
37  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
40  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
43  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44  * SUCH DAMAGE.
45  * ====================================================================
46  *
47  * This software consists of voluntary contributions made by many
48  * individuals on behalf of the Visigoth Software Society. For more
49  * information on the Visigoth Software Society, please see
50  * http://www.visigoths.org/
51  */

52
53 package freemarker.testcase;
54
55 import java.io.IOException JavaDoc;
56 import java.io.StringWriter JavaDoc;
57 import java.util.Locale JavaDoc;
58
59 import freemarker.template.SimpleHash;
60 import freemarker.template.SimpleSequence;
61 import freemarker.template.Template;
62 import freemarker.template.TemplateException;
63 import freemarker.testcase.models.SimpleTestMethod;
64
65 /** Test class for testing FreeMarker's number literal syntax.
66  *
67  * @version $Id: TestNumberLiteral.java,v 1.28 2003/04/02 11:25:54 szegedia Exp $
68  */

69 public class TestNumberLiteral extends AbstractTestCase {
70
71     /** Create a new TestNumberLiteral test case */
72     public TestNumberLiteral( String JavaDoc aTestname ) {
73         super( aTestname );
74     }
75
76     /**
77      * Set up the test case prior to running.
78      */

79     public void setUp() {
80         setUpFiles( "test-numberliteral.html" );
81
82         // Make a template data model.
83
SimpleHash cModel1 = new SimpleHash();
84
85         cModel1.put("1", "one");
86         cModel1.put("12", "twelve");
87         cModel1.put( "2one", "two-one" );
88         cModel1.put( "one2", "one-two" );
89
90         SimpleSequence cModel2 = new SimpleSequence();
91
92         cModel2.add( "zero" );
93         cModel2.add( "one" );
94         cModel2.add( "two" );
95         cModel2.add( "three" );
96         cModel2.add( "four" );
97         cModel2.add( "five" );
98         cModel2.add( "six" );
99         cModel2.add( "seven" );
100         cModel2.add( "eight" );
101         cModel2.add( "nine" );
102         cModel2.add( "tenth" );
103         cModel2.add( "eleven" );
104         cModel2.add( "twelve" );
105
106         root.put("message", "Hello, world!");
107         root.put("foo", "bar");
108         root.put("one", "1");
109         root.put("1", "one");
110         root.put("12", "twelve");
111         root.put("2one", "two-one");
112         root.put("one2", "one-two");
113         root.put("hash", cModel1);
114         root.put("list", cModel2);
115         root.put("call", new SimpleTestMethod() );
116     }
117
118     /**
119      * Abstract method for performing the test. The implementing class should
120      * indicate clearly whether the test has passed. A pass result should be
121      * written to screen. A fail result should also generate information about
122      * the failure.
123      */

124     public void runTest() throws TemplateException, IOException JavaDoc {
125         StringWriter JavaDoc sw = new StringWriter JavaDoc();
126         config.setStrictSyntaxMode(true);
127         Locale JavaDoc prevLocale = config.getLocale();
128         config.setLocale(Locale.FRANCE);
129         try {
130             Template template = config.getTemplate("test-numberliteral.html");
131             template.process(root, sw);
132         }
133         finally {
134             config.setStrictSyntaxMode(false);
135             config.setLocale(prevLocale);
136         }
137         showTestResults( referenceText, sw.toString() );
138     }
139
140     /** Bootstrap for the self-test code.
141      */

142     public static void main( String JavaDoc[] argc ) throws Exception JavaDoc {
143         AbstractTestCase cTest = new TestNumberLiteral( "test-numberliteral.html" );
144         cTest.run();
145     }
146 }
147
Popular Tags