1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }