1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.core;
17
18 import junit.framework.TestSuite;
19
20 import org.apache.commons.jelly.Script;
21 import org.apache.commons.jelly.test.BaseJellyTest;
22 import org.apache.commons.lang.StringUtils;
23
24 /***
25 * @author <a href="mailto:benanderson@benanderson.us">Ben Anderson</a>
26 * @version $Revision: 155420 $
27 */
28 public class TestForEachTag extends BaseJellyTest
29 {
30
31 public TestForEachTag(String name)
32 {
33 super(name);
34 }
35
36 public static TestSuite suite() throws Exception
37 {
38 return new TestSuite(TestForEachTag.class);
39 }
40
41 public void testForEachTag() throws Exception
42 {
43 setUpScript("testForEachTag.jelly");
44 Script script = getJelly().compileScript();
45
46 getJellyContext().setVariable("myList",
47 new Object[] {"0", "VOID", "1", "VOID", "2", "VOID",
48 "3", "VOID", "4", "VOID", "5"});
49 getJellyContext().setVariable("testMyList", Boolean.TRUE);
50 script.run(getJellyContext(), getXMLOutput());
51
52 String resultOrdered =
53 (String) getJellyContext().getVariable("result.ordered");
54 System.err.println("raw result is '" + resultOrdered + "'");
55 resultOrdered = StringUtils.replace(resultOrdered, " ", "");
56 resultOrdered = StringUtils.replace(resultOrdered, "\n", "");
57
58 assertEquals("result.ordered",
59 "FIRST_262_121/MIDDLE_242/LAST_363/",
60 resultOrdered);
61 }
62
63 public void testForEachTagNumList() throws Exception
64 {
65 setUpScript("testForEachTag.jelly");
66 Script script = getJelly().compileScript();
67
68 getJellyContext().setVariable("testNumList", Boolean.TRUE);
69 script.run(getJellyContext(), getXMLOutput());
70
71 String resultOrdered =
72 (String) getJellyContext().getVariable("result.ordered");
73 System.err.println("raw result is '" + resultOrdered + "'");
74 resultOrdered = StringUtils.replace(resultOrdered, " ", "");
75 resultOrdered = StringUtils.replace(resultOrdered, "\n", "");
76
77 assertEquals("result.ordered",
78 "FIRST_262_122/MIDDLE_244/LAST_366/",
79 resultOrdered);
80 }
81 }