KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > ut > tests > HTCTest


1 /**
2  * $Id: HTCTest.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2003 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 of the License, or (at your option) any later
9  * 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
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.ut.tests;
30
31 import java.io.File JavaDoc;
32 import java.io.InputStream JavaDoc;
33
34 import junit.framework.Assert;
35 import junit.framework.AssertionFailedError;
36 import junit.framework.TestSuite;
37
38 import com.idaremedia.antx.ut.*;
39
40
41 /**
42  * Test for the HTC <i>JWare/AntX</i> test superclasses. Modified from original; removed
43  * all batch-failure tests.
44  *
45  * @since JWare0.6
46  * @author ssmc, &copy;2002-2003 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
47  * @version 0.5
48  * @.safety single
49  * @.group impl,test
50  **/

51
52 public final class HTCTest extends HTC /* We need this for batchFailure and ThreadLocals */
53 {
54     /** <i>PET</i> Test Category. **/
55     public static final String JavaDoc TEST_CATEGORY="CLASS";
56
57
58     /**
59      * Create new HTCTest test case.
60      **/

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

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

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

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

98     /** Exposes some internals of HTC. [modified-from-HMTTest] **/
99     public final static class HTCExposer extends HTC {
100         public HTCExposer() {
101             super();
102         }
103         public HTCExposer(String JavaDoc meth) {
104             super(meth);
105         }
106         public HTCExposer(String JavaDoc grpid, String JavaDoc meth) {
107             super(grpid,meth);
108         }
109     }
110
111     public void testFailRequire()
112     {
113         try { require_(false,"@failRequire"); Assert.fail("require(false)"); }
114         catch(TestError x) { Assert.assertTrue(x.getMessage().indexOf("@failRequire")>=0); }
115     }
116
117     public void testFailEnsure()
118     {
119         try { ensure_(false,"@failEnsure"); Assert.fail("ensure(false)"); }
120         catch(TestError x) { Assert.assertTrue(x.getMessage().indexOf("@failEnsure")>=0); }
121     }
122
123     public void testFailVerify()
124     {
125         try { verify_(false,"@failVerify"); Assert.fail("verify(false)"); }
126         catch(TestError x) { Assert.assertTrue(x.getMessage().indexOf("@failVerify")>=0); }
127     }
128
129     public void testFailASAP()
130     {
131         try
132         { HTC.failASAP("@failASAP_"); }
133         catch(AssertionFailedError x)
134         { Assert.assertTrue(x.getMessage().indexOf("@failASAP_")>=0);
135         return; }
136         Assert.fail("failASAP broken");
137     }
138
139     public void testFailEqualASAP()
140     {
141         try
142         { HTC.failEqualASAP("foo",new String JavaDoc("foo"),"@failEqualASAP_"); }
143         catch(AssertionFailedError x)
144         { Assert.assertTrue(x.getMessage().indexOf("@failEqualASAP_")>=0);
145         return; }
146         Assert.fail("failEqualASAP broken");
147     }
148
149     public void testFailNotEqualASAP()
150     {
151         try
152         { HTC.failEqualASAP("foo","bar","@failNotEqualASAP_"); }
153         catch(AssertionFailedError x)
154         { Assert.assertTrue(x.getMessage().indexOf("@failNotEqualASAP_")>=0);
155         return; }
156         Assert.fail("failNotEqualASAP broken");
157     }
158
159
160 // ---------------------------------------------------------------------------------------------------------
161
// Verify batch processing from a single thread (first) Note tests should not affect each other!
162
// [ R E M O V E D -- ssmc ]
163
// ---------------------------------------------------------------------------------------------------------
164
// ...
165

166
167 // ---------------------------------------------------------------------------------------------------------
168
// Test the (Not)Equal that all others depend on
169
// ---------------------------------------------------------------------------------------------------------
170

171     public void testPassAssertEqual()
172     {
173         HTC.assertEqual("foo", new String JavaDoc("foo"));
174     }
175
176     public void testPassAssertNotEqual()
177     {
178         HTC.assertNotEqual("foo","bar");
179     }
180
181     public void testPassIdent()
182     {
183         Object JavaDoc o= new Double JavaDoc(Math.PI);
184         HTC.assertIdent(o,o);
185     }
186
187     public void testPassNotIdent()
188     {
189         Object JavaDoc o1= new Double JavaDoc(Math.PI);
190         Object JavaDoc o2= new Double JavaDoc(Math.PI);
191         HTC.assertNotIdent(o1,o2);
192         HTC.assertEqual(o1,o2);
193     }
194
195 // ---------------------------------------------------------------------------------------------------------
196
// Test the Throwable-matching that all others depend on
197
// ---------------------------------------------------------------------------------------------------------
198

199     public void testFindExpected()
200     {
201         Throwable JavaDoc t= new Throwable JavaDoc("Oh goody time to wreak havoc");
202         assertExpected(t,"goody");
203     }
204
205     public void testNotFindExpected()
206     {
207         Throwable JavaDoc t= new Throwable JavaDoc("Peanut and Jelly");
208         boolean happy=true;
209         try { assertExpected(t,"Bologna"); happy=false; }
210         catch(AssertionFailedError x) { assertExpected(x,"Barfage"); }
211         HTC.assertTrue("Didn't find missing token",happy);
212     }
213
214     public void testFindExpectedOfKind()
215     {
216         Throwable JavaDoc t= new NullPointerException JavaDoc("Oh goody time to wreak havoc");
217         assertExpected(t,RuntimeException JavaDoc.class,"havoc");
218     }
219
220     public void testNotFindExpectedOfKind()
221     {
222         Throwable JavaDoc t= new NullPointerException JavaDoc("Fish and Chips");
223         boolean happy=true;
224         try { assertExpected(t,ClassNotFoundException JavaDoc.class,"Chips"); happy=false; }
225         catch(AssertionFailedError x) { assertExpected(x,"Barfage"); }
226         HTC.assertTrue("Didn't match throwable class",happy);
227     }
228
229 // ---------------------------------------------------------------------------------------------------------
230
// Test the Load of test class resources
231
// ---------------------------------------------------------------------------------------------------------
232

233     public void testCanLoadClassResourcesAsStreams()
234         throws Exception JavaDoc
235     {
236         InputStream JavaDoc ins = getFileResourceAsStream("HTCTest.xml");
237         int Nc=0;
238         while (ins.read() != -1) {
239             m_stdout.print(".");
240             Nc++;
241         }
242         ins.close();
243         assertNotEqual(Nc,0,"Number HTCTest.xml bytes read");
244     }
245
246
247     public void testCanLoadClassResourcesAsFiles()
248         throws Exception JavaDoc
249     {
250         File JavaDoc f = getFileResource("HTCTest.xml");
251         java.io.FileReader JavaDoc fr = new java.io.FileReader JavaDoc(f);
252         assertTrue(fr.ready(),"HTCTest reader ready");
253         int Nc=0;
254         while (fr.read() != -1) {
255             m_stdout.print(".");
256             Nc++;
257         }
258         fr.close();
259         assertNotEqual(Nc,0,"Number HTCTest.xml bytes read");
260     }
261
262 // ---------------------------------------------------------------------------------------------------------
263
// Test the Ant Build File bits work!
264
// ---------------------------------------------------------------------------------------------------------
265

266
267     public void testCanLoadBuildFileResources()
268         throws Exception JavaDoc
269     {
270         File JavaDoc f = getFileResource("HTCTest.xml");
271         configureProject(f.getPath());
272     }
273
274
275     public void testCanExecuteTargetInBuildFile()
276         throws Exception JavaDoc
277     {
278         configureProject(getFileResource("HTCTest.xml").getPath());
279         executeTarget("geeksalute");
280         assertNotEqual(getLog().indexOf("helloworld"),-1,"'geeksalute' target output");
281     }
282 }
283
284 /* end-of-HTCTest.java */
285
Popular Tags