KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: InitUISMTaskTest.java 187 2007-03-25 17:59:16Z ssmc $
3  * Copyright 2002-2004,2007 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://antxtras.sf.net/ EMAIL- jware[at]users[dot]sourceforge[dot]net
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.tests;
30
31 import java.io.File JavaDoc;
32 import java.io.FileWriter JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34
35 import junit.framework.TestSuite;
36 import org.apache.tools.ant.util.FileUtils;
37
38 import com.idaremedia.antx.AntXFixture;
39 import com.idaremedia.antx.ut.HTC;
40 import com.idaremedia.antx.ut.HTCUtils;
41
42 /**
43  * Class test for {@linkplain com.idaremedia.antx.init.UISMBundle UISMBundle} and
44  * {@linkplain com.idaremedia.antx.init.InitUISMTask InitUISMTask}.
45  *
46  * @since JWare/AntX 0.1
47  * @author ssmc, &copy;2002-2004,2007 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
48  * @version 0.5.1
49  * @.safety single
50  * @.group impl,test
51  **/

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

62     public InitUISMTaskTest(String JavaDoc methodName)
63     {
64         super("InitUISMTask::",methodName);
65     }
66
67
68     /**
69      * Create full test suite for InitUISMTask.
70      **/

71     public static TestSuite suite()
72     {
73         return new TestSuite(InitUISMTaskTest.class);
74     }
75
76
77     /**
78      * Create baseline test suite for InitUISMTask (same as full).
79      **/

80     public static TestSuite baseline()
81     {
82         return suite();//new BaselineSuite(InitUISMTaskTest.class);
83
}
84
85
86     /**
87      * Make this test (standalone) self-running.
88      **/

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

99     static final String JavaDoc TMP_TARGET = "theTest";
100     static final String JavaDoc UISTRS_BUNDLE = "com.idaremedia.antx.tests.OtherUIStrings";
101     static final String JavaDoc UISTRS_RESOURCE = "OtherUIStrings.properties";
102
103     static final String JavaDoc BY_URL_DEBUG_MSG = "Copied UISM URL";
104     static final String JavaDoc DBG_MSG_UISTRINGS = "DO NOT REMOVE. Helloworld";
105     static final String JavaDoc DBG_MSG_OTHER_UISTRINGS = "GO AHEAD REMOVE ME. Byeworld";
106
107     static final String JavaDoc _XML_tN="\"/>\n";
108     static final String JavaDoc _XML_tf0=" <initmsgs_ action=\"install\" file=\"";
109     static final String JavaDoc _XML_tu0=" <initmsgs_ action=\"install\" url=\"";
110
111     private void writeBeginXML(PrintWriter JavaDoc w)
112     {
113         w.print("<?xml version=\"1.0\"?>\n<project name=\"UT\" basedir=\".\" default=\"theTest\">\n");
114         w.print(" <taskdef name=\"initmsgs_\" classname=\"com.idaremedia.antx.init.InitUISMTask\"/>\n");
115         w.print(" <target name=\"theTest\">\n");
116     }
117
118     private void writeEndXML(PrintWriter JavaDoc w)
119     {
120         w.print(" <initmsgs_ action=\"uninstall\"/>\n");
121         w.print(" </target>\n");
122         w.print("</project>\n");
123     }
124
125     private void writeByFileXML(PrintWriter JavaDoc w, String JavaDoc filepath)
126     {
127         writeBeginXML(w);
128         w.print(_XML_tf0);
129         w.print(filepath);
130         w.print(_XML_tN);
131         writeEndXML(w);
132     }
133
134     private void writeByURLXML(PrintWriter JavaDoc w, String JavaDoc url)
135     {
136         writeBeginXML(w);
137         w.print(_XML_tu0);
138         w.print(url);
139         w.print(_XML_tN);
140         writeEndXML(w);
141     }
142
143     private void configureTempBuildFileProject(boolean byFile) throws Exception JavaDoc
144     {
145         FileUtils fu= AntXFixture.fileUtils();
146         File JavaDoc from = getFileResource(UISTRS_RESOURCE);
147         File JavaDoc to = File.createTempFile("qatUIStrings-",".properties");
148         fu.copyFile(from, to, null, true);
149         File JavaDoc tempBuildFile = File.createTempFile("qatBuild-",".xml");
150         PrintWriter JavaDoc w = new PrintWriter JavaDoc(new FileWriter JavaDoc(tempBuildFile));
151         if (byFile) {
152             writeByFileXML(w, to.getAbsolutePath());
153         } else {
154             writeByURLXML(w,to.toURL().toString());
155         }
156         w.close();
157         configureProject(tempBuildFile.getPath());
158         to.deleteOnExit();
159         tempBuildFile.deleteOnExit();
160     }
161
162     private void verifyLoadable(String JavaDoc target, String JavaDoc type)
163     {
164         runTargetNoOutput(target);
165         String JavaDoc fullLog = getFullLog();
166         println("FFFFFFFFUUUUUUUUUULLLLL",fullLog);
167         assertTrue(fullLog.indexOf(BY_URL_DEBUG_MSG) != -1,
168                    "Loaded '"+type+"' option to bundle");
169     }
170
171 // ---------------------------------------------------------------------------------------------------------
172

173     protected void setUp() throws Exception JavaDoc
174     {
175         String JavaDoc n = getName();
176         if (!n.endsWith("_Tmp")) {
177             configureProjectFromResource("uism.xml");
178         }
179     }
180
181 // ---------------------------------------------------------------------------------------------------------
182
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
183
// ---------------------------------------------------------------------------------------------------------
184

185     public void checkBaseline()
186     {
187         //--Ensures setUp() works and can find our xml file!
188
}
189
190     public void testBaseline()
191     {
192         checkBaseline();
193     }
194
195     public void testFailEmptyElement()
196     {
197         runExpecting("testEmptyElement","is empty task definition");
198         println("BARFAGE:", getBuildException().getMessage());
199     }
200
201     public void testFailEmptyElementWithPropertyDefined()
202     {
203         runExpecting("testEmptyElementWithPropertyDefined", "is empty task definition w/ PPs");
204         println("BARFAGE:", getBuildException().getMessage());
205     }
206
207     public void testFailBadFile()
208     {
209         runExpecting("testFailBadFile", "is nonexistent file");
210         println("BARFAGE:", getBuildException().getMessage());
211     }
212
213     public void testFailBadResource()
214     {
215         runExpecting("testFailBadFile", "is nonexistent resource");
216         println("BARFAGE:", getBuildException().getMessage());
217     }
218
219     public void testFailBadURL()
220     {
221         runExpecting("testFailBadFile", "is nonexistent URL");
222         println("BARFAGE:", getBuildException().getMessage());
223     }
224
225     public void testPassByURL() throws Exception JavaDoc
226     {
227         verifyLoadable("testByLocalURL","url");
228     }
229
230     public void testPassByResource()
231     {
232         verifyLoadable("testByResource","resource");
233     }
234
235     public void testPassByResourceInProperty()
236     {
237         verifyLoadable("testByBundleInProperty","default-resource");
238     }
239
240     public void testPassByResourceWithClassPath()
241     {
242         verifyLoadable("testByResourceWithClassPath","resource");
243     }
244
245     public void testPassByFile_Tmp() throws Exception JavaDoc
246     {
247         configureTempBuildFileProject(true);
248         verifyLoadable(TMP_TARGET,"file");
249     }
250
251     public void testPassByFileURL_Tmp() throws Exception JavaDoc
252     {
253         configureTempBuildFileProject(false);
254         verifyLoadable(TMP_TARGET,"file");
255     }
256
257     public void testDefaultPassthruYesInherited()
258     {
259         String JavaDoc log = runTarget("testDefaultPassthruYesInherit");
260         verifyOccurances(log,"Helloworld",1);
261     }
262
263     public void testDefaultPassthruNoInherited()
264     {
265         String JavaDoc log = runTarget("testDefaultPassthruNoInherit");
266         assertTrue(log.indexOf("Helloworld")>=0, "Output contains 'Helloworld' from msg.0");
267         assertTrue(log.indexOf("Byeworld")>=0, "Output contains 'Byeworld' from msg.1");
268     }
269
270     public void testDefaultPassthruManyJumpsYesInherited()
271     {
272         String JavaDoc log = runTarget("testDefaultPassthruManyJumpsYesInherit");
273         verifyOccurances(log,"Helloworld",1);
274     }
275
276     public void testDefaultPassthruCallOtherAntProcess()
277     {
278         String JavaDoc log = runTarget("testDefaultPassthruCallOtherAntProcess");
279         verifyOccurances(log,"Helloworld",1);
280     }
281
282     public void testPassthruStickyLikeVelcro()
283     {
284         String JavaDoc log = runTarget("testPassthruStickyLikeVelcro");
285         verifyOccurances(log,DBG_MSG_UISTRINGS,1);
286         assertFalse(log.indexOf(DBG_MSG_OTHER_UISTRINGS)>=0,"Other-UIStrings used as bundle");
287     }
288
289     public void testCantLoadBrokenBundleDeclarations()
290     {
291         verifyCantLoadFile("broken_uism0.xml", "Specified url and resource locations");
292         verifyCantLoadFile("broken_uism1.xml", "Specified refid and other locations");
293         verifyCantLoadFile("broken_uism2.xml", "Specified refid and nested elements");
294     }
295
296     public void testUsingMsgBundleReferences()
297     {
298         String JavaDoc log = runTarget("testUsingMsgBundleRef");
299         verifyOccurances(log,"Byeworld",1);
300     }
301
302     public void testUsingMsgBundleReferencesByURL()
303     {
304         String JavaDoc log = runTarget("testUsingMsgBundleRefByURL");
305         verifyOccurances(log,"Byeworld",1);
306     }
307
308
309     public void testNoOpsUnknownManageInstructions()
310     {
311         String JavaDoc log = runTarget("testUnknownManageDirective");
312         String JavaDoc fullLog = getFullLog();
313         println("FFFFFFFFUUUUUUUUUULLLLL",fullLog);
314         verifyOccurances(log,"Unrecognized operation",1);
315     }
316
317     public void testCloningMsgBundlesToChildProject()
318     {
319         runTarget("testCloningMsgBundlesToChildProject");
320     }
321
322
323     public void testCustomClasspath_AntX04()
324     {
325         String JavaDoc log = runTarget("testCustomClasspath_AntX04");
326         verifyOccurances(log,DBG_MSG_OTHER_UISTRINGS,1);
327         assertFalse(log.indexOf(DBG_MSG_UISTRINGS)>=0,"UIStrings used as bundle");
328     }
329
330 }
331
332 /* end-of-InitUISMTaskTest.java */
333
Popular Tags