KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > flowcontrol > tests > ForEachTaskTest


1 /**
2  * $Id: ForEachTaskTest.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2004 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.flowcontrol.tests;
30
31 import junit.framework.TestSuite;
32
33 import com.idaremedia.antx.ut.HTCUtils;
34
35 /**
36  * Class test for {@linkplain com.idaremedia.antx.flowcontrol.call.ForEachTask
37  * ForEachTask}.
38  *
39  * @since JWare/AntX 0.1
40  * @author ssmc, &copy;2002-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
41  * @version 0.5
42  * @.safety single
43  * @.group impl,test
44  **/

45
46 public final class ForEachTaskTest extends StepCallerTestSkeleton
47 {
48     /** <i>PET</i> Test Category. **/
49     public static final String JavaDoc TEST_CATEGORY="CLASS";
50
51
52     /**
53      * Create new ForEachTaskTest testcase.
54      **/

55     public ForEachTaskTest(String JavaDoc methodName)
56     {
57         super("ForEachTask::",methodName);
58     }
59
60
61     /**
62      * Creates a test suite with a single test.
63      **/

64     public static TestSuite suiteOfOne(String JavaDoc testName)
65     {
66         TestSuite s = new TestSuite();
67         s.setName("Suite-of-One:"+testName);
68         s.addTest(new ForEachTaskTest(testName));
69         return s;
70     }
71
72     /**
73      * Create full test suite for ProtectedTaskSet.
74      **/

75     public static TestSuite suite()
76     {
77         return new TestSuite(ForEachTaskTest.class);
78 // return suiteOfOne("testItemListLoopControl_AntX03");
79
}
80
81
82     /**
83      * Create baseline test suite for ProtectedTaskSet (same as full).
84      **/

85     public static TestSuite baseline()
86     {
87         return suite();//new BaselineSuite(ForEachTaskTest.class);
88
}
89
90
91     /**
92      * Make this test (standalone) self-running.
93      **/

94     public static void main(String JavaDoc[] argv)
95     {
96         HTCUtils.quickCheck(suite());
97     }
98
99
100 // ---------------------------------------------------------------------------------------------------------
101
// ---------------------------------------- [ Misc Setup Methods ] -----------------------------------------
102
// ---------------------------------------------------------------------------------------------------------
103

104     protected String JavaDoc getDefaultConfigureXMLFileName()
105     {
106         return "foreach.xml";
107     }
108
109     final int verifyTargetsRanInLoop(final String JavaDoc PFX, final int I, final int N, int ilastmatch)
110     {
111         String JavaDoc log= getLog();
112         for (int i=I;i<N;i++) {
113             String JavaDoc match = PS+PFX+AT+i;
114             int imatch = log.indexOf(match,ilastmatch);
115             assertTrue("Expecting Log to contain \""+match+"\" from ["+ilastmatch+
116                        "] but Log was \"" + log + "\"",
117                        imatch>=0);
118             ilastmatch = imatch;
119         }
120         return ilastmatch;
121     }
122
123     final int verifyTargetsRanInLoop(String JavaDoc[] cursors, int ilastmatch)
124     {
125         String JavaDoc log= getLog();
126         String JavaDoc match;
127         int imatch;
128         for (int i=0;i<cursors.length;i++) {
129             match = "(at:"+cursors[i]+")";
130             imatch = log.indexOf(match,ilastmatch);
131             assertTrue("Expecting Log to contain \""+match+"\" from ["+ilastmatch+
132                        "] but Log was \"" + log + "\"",
133                        imatch>=0);
134             ilastmatch = imatch+match.length();
135         }
136         return ilastmatch;
137     }
138
139 // ---------------------------------------------------------------------------------------------------------
140
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
141
// ---------------------------------------------------------------------------------------------------------
142

143     public void testFailEmptyForEachElement()
144     {
145         String JavaDoc log = runTarget("testFailEmptyElement");
146         assertTrue(log.indexOf("phffht: it barfed")>=0,"It barfed");
147     }
148
149     public void testFailBrokenLoopDefinitions()
150     {
151         runTarget("testBrokenLoops");
152     }
153
154     public void testCantNestNonPropertiesInForEach()
155     {
156         verifyCantLoadFile("broken_foreach0.xml", "Invalid nested tasks");
157     }
158
159     public void testInLoopControl()
160     {
161         runTarget("testInLoopControl");
162         int from=0;
163         from= verifyTargetsRanInLoop(new String JavaDoc[]{"0"},from);
164         from= verifyTargetsRanInLoop(new String JavaDoc[]{"0","1","2"},from);
165         from= verifyTargetsRanInLoop(new String JavaDoc[]{"0","2","4"},from);
166         from= verifyTargetsRanInLoop(new String JavaDoc[]{"-1","0"},from);
167     }
168
169     public void testListLoopControl()
170     {
171         runTarget("testListLoopControl");
172         int from=0;
173         from= verifyTargetsRanInLoop(new String JavaDoc[]{"a","b","c"},from);
174         from= verifyTargetsRanInLoop(new String JavaDoc[]{"w","x","y","z"},from);
175         from= verifyTargetsRanInLoop(new String JavaDoc[]{"${p.unknown}"},from);
176     }
177
178     public void testItemListLoopControl_AntX03()
179     {
180         runTarget("testItemListLoopControl_AntX03");
181     }
182
183     public void testInFileLoopControl()
184     {
185         runTarget("testInFileLoopControl");
186     }
187
188     public void testDirsetLoopControl()
189     {
190         runTarget("testDirsetLoopControl");
191     }
192
193     public void testPathLoopControl()
194     {
195         runTarget("testPathLoopControl");
196     }
197
198     public void testFilesetLoopControl()
199     {
200         runTarget("testFilesetLoopControl");
201     }
202
203 // public void testSupportsIfUnless()
204
// {
205
// runTarget("testFailIfUnless");
206
// }
207

208     public void testSupportsTryEach()
209     {
210         runTarget("testSupportsTryEach");
211     }
212
213     /** @since JWare/AntX 0.4 **/
214     public void testNestedPropertySets_AntX04()
215     {
216         runTarget("testNestedPropertySets_AntX04");
217     }
218     
219     /** @since JWare/AntX 0.4 **/
220     public void testLocalMode_AntX04()
221     {
222         runTarget("testLocalMode_AntX04");
223     }
224     
225     public void testCallLocalMacros_AntX05()
226     {
227         runTarget("testCallLocalMacros_AntX05");
228     }
229     
230     public void testListLoopCustomDelimiter_AntX05()
231     {
232         runTarget("testListLoopCustomDelimiter_AntX05");
233     }
234 }
235
236 /* end-of-ForEachTaskTest.java */
237
Popular Tags