01: package org.mvel.tests.main;
02:
03: import org.mvel.TemplateInterpreter;
04:
05: import java.io.IOException;
06: import java.io.ByteArrayOutputStream;
07: import java.io.InputStream;
08: import java.util.Map;
09: import java.util.HashMap;
10:
11: import junit.framework.TestCase;
12:
13: public class TemplateTest2 extends TestCase {
14:
15: public static final String OK_TEMPLATE = "DELIVERY: 5 Sheath Street <br />\n"
16: + "EMAIL: nicola at realimage.co.nz</p>\n"
17: + " <div id=\"contactCheckBoxes\">Where did you hear about Nicola?\n"
18: + " <p class=\"contactInput\">@{someval} Bride and Groom Magazine</p>";
19:
20: public static final String BAD_TEMPLATE = "DELIVERY: 5 Sheath Street <br />\n"
21: + "EMAIL: nicola@@realimage.co.nz</p>\n"
22: + " <div id=\"contactCheckBoxes\">Where did you hear about Nicola?\n"
23: + " <p class=\"contactInput\">@{someval} Bride and Groom Magazine</p>";
24:
25: /**
26: * This fails because there is an @ symbol in the template which is
27: * interpreted as denoting an expression, when in fact its just part
28: * of content. It is not connected to curly braces
29: *
30: * @throws java.io.IOException
31: */
32: public void test_fails() throws IOException {
33: runTemplate(BAD_TEMPLATE);
34: }
35:
36: /**
37: * This template is the same as above except that the @ symbol has been replaced
38: * with ' at '. It succeeds.
39: *
40: * @throws java.io.IOException
41: */
42: public void test_works() throws IOException {
43: runTemplate(OK_TEMPLATE);
44: }
45:
46: private void runTemplate(String template) throws IOException {
47: Map map = new HashMap();
48: map.put("someval", "some value goes here");
49: String r = TemplateInterpreter.evalToString(template, map);
50: System.out.println("r: " + r);
51: }
52: }
|