KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > tests > UtilitiesTest


1 /**
2  * $Id: UtilitiesTest.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 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 (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any 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 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 GNU 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.tests;
30
31 import java.util.Collections JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34
35 import junit.framework.TestSuite;
36
37 import org.apache.tools.ant.Project;
38
39 import com.idaremedia.antx.ut.HTC;
40 import com.idaremedia.antx.ut.HTCUtils;
41
42 import com.idaremedia.antx.AntX;
43 import com.idaremedia.antx.AntXFixture;
44 import com.idaremedia.antx.helpers.Tk;
45
46 /**
47  * Tests to ensure the various AntX helper utility classes work as expected.
48  *
49  * @since JWare/AntX 0.4
50  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
51  * @version 0.5
52  * @.safety single
53  * @.group impl,test
54  **/

55
56 public final class UtilitiesTest extends HTC
57 {
58     /** <i>PET</i> Test Category. **/
59     public static final String JavaDoc TEST_CATEGORY="CLASS";
60
61
62     /**
63      * Create new testcase.
64      **/

65     public UtilitiesTest(String JavaDoc methodName)
66     {
67         super("Utilities::",methodName);
68     }
69
70
71     /**
72      * Create full test suite.
73      **/

74     public static TestSuite suite()
75     {
76         return new TestSuite(UtilitiesTest.class);
77     }
78
79
80     /**
81      * Create baseline test suite.
82      **/

83     public static TestSuite baseline()
84     {
85         return suite();
86     }
87
88
89     /**
90      * Make this test (standalone) self-running.
91      **/

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

101     protected void setUp() throws Exception JavaDoc
102     {
103         configureProjectFromResource("empty.xml");
104         Project P = getProject();
105         assertNotNil(P,"test's project");
106     }
107
108 // ---------------------------------------------------------------------------------------------------------
109
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
110
// ---------------------------------------------------------------------------------------------------------
111

112     public void checkBaseline()
113     {
114         //--Ensures setUp() works and can find our xml file!
115
}
116
117
118     public void testBaseline()
119     {
120         checkBaseline();
121     }
122
123
124     /**
125      * Verifies we can access internal AntX ui strings as expected.
126      **/

127     public void testAntXStringsAccessible_AntX04()
128     {
129         String JavaDoc s1 = AntX.uistrs().get("antx_.debug.helloworld");
130         assertNotWhitespace(s1,"AntX debug UIString");
131         assertTrue(s1.indexOf("DO NOT REMOVE")>=0,"Expected AntX debug string");
132
133         //Commonly used...verify something there
134
assertNotWhitespace(AntX.uistrs().get(AntX.CLONE_BROKEN_MSGID));
135         assertNotWhitespace(AntX.uistrs().get("cv.require"));
136         assertNotWhitespace(AntX.uistrs().get("task.warn.property.exists"));
137         assertNotWhitespace(AntX.uistrs().get("task.cant.flip.unknown"));
138     }
139
140
141     /**
142      * Verifies we can avoid overhead for readonly maps as expected.
143      **/

144     public void testReadonlyMapWrapperUtil_AntX04()
145     {
146         Map JavaDoc mp;
147         Map JavaDoc mutableMap = AntXFixture.newMap();
148
149         assertNil(Tk.readonlyFrom(null,false));
150         mp = Tk.readonlyFrom(null,true);
151         assertNotNil(mp);
152         assertIdent(mp,Tk.readonlyFrom(mp,false));
153
154         mp= Collections.EMPTY_MAP;
155         assertIdent(mp,Tk.readonlyFrom(mp,false));
156
157         mp= Collections.unmodifiableMap(mutableMap);
158         assertIdent(mp,Tk.readonlyFrom(mp,false));
159         assertNotIdent(mp,Tk.readonlyFrom(mutableMap,false));
160     }
161
162
163     /**
164      * Verifies we can avoid overhead for strings with no variables.
165      **/

166     public void testResolveStringOverheadUtil_AntX04()
167     {
168         Project P= getProject();
169
170         assertNil(Tk.resolveString(P,null));
171
172         String JavaDoc s = "no variables here";
173         assertIdent(s,Tk.resolveString(P,s),"no variables in string");
174
175         assertNotNil(P.getProperty("p.true"),"p.true definition");
176         s = "This is a test: ${p.true}";
177         assertNotEqual(s,Tk.resolveString(P,s),"variables in string");
178     }
179
180
181
182     /**
183      * Verifies we can switch from macro-isque attributes to
184      * standard project properties.
185      **/

186     public void testResolveLocalVariables_AntX04()
187     {
188         Project P= getProject();
189
190         assertNil(Tk.resolveString(P,null));
191
192         String JavaDoc s = "no variables here";
193         assertIdent(s,Tk.resolveString(P,s,true),"no variables in string");
194
195         assertNotNil(P.getProperty("p.true"),"p.true definition");
196
197         s = "This is a test: @{p.true}. Happy ? @{p.false}";
198         String JavaDoc xpected = "This is a test: true. Happy ? false";
199         String JavaDoc out = Tk.resolveString(P,s,true);
200
201         assertEqual(out,xpected,"local variables in string(a)");
202
203         s = "This is a test: ${p.true}. Happy ? @{p.false}";
204         out = Tk.resolveString(P,s,true);
205         assertEqual(out,xpected,"local variables in string(b)");
206     }
207
208
209     /**
210      * Verifies we can switch from value-URI-friendly attributes
211      * to standard project attributes.
212      * @since JWare/AntX 0.5
213      */

214     public void testResolveValueURIFriendlyRefs_AntX05()
215     {
216         Project P= getProject();
217         String JavaDoc s;
218
219         s = "This is a test: @(p.true). Happy ? @(p.false)";
220         String JavaDoc xpected = "This is a test: true. Happy ? false";
221         String JavaDoc out = Tk.resolveString(P,s,true);
222
223         assertEqual(out,xpected,"local variables in string(a)");
224
225         s = "This is a test: ${p.true}. Happy ? @(p.false)";
226         out = Tk.resolveString(P,s,true);
227         assertEqual(out,xpected,"local variables in string(b)");
228     }
229
230
231     /**
232      * Verifies that an empty string is interpreted as an empty
233      * list by Tk.splitList.
234      * @since JWare/AntX 0.5
235      **/

236     public void testSplitListEmptyStringIsZeroLengthList_AntX05()
237     {
238         List JavaDoc l = Tk.splitList("");
239         assertNotNil(l,"empty string's list");
240         assertEqual(0,l.size(),"list's size");
241     }
242 }
243
244 /* end-of-UtilitiesTest.java */
245
Popular Tags