KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: AssertionRuleTest.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2005 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.tests;
30
31 import junit.framework.TestSuite;
32 import org.apache.tools.ant.BuildException;
33
34 import com.idaremedia.antx.ut.HTC;
35 import com.idaremedia.antx.ut.HTCUtils;
36
37 import com.idaremedia.antx.apis.BuildAssertionException;
38
39 /**
40  * Class test for {@linkplain com.idaremedia.antx.condition.AssertTask AssertTask}.
41  *
42  * @since JWare/AntX 0.1
43  * @author ssmc, &copy;2002-2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
44  * @version 0.5
45  * @.safety single
46  * @.group impl,test
47  **/

48
49 public class AssertionRuleTest extends HTC
50 {
51     /** <i>PET</i> Test Category. **/
52     public static final String JavaDoc TEST_CATEGORY="CLASS";
53
54
55     /**
56      * Create new AssertionRuleTest testcase.
57      **/

58     public AssertionRuleTest(String JavaDoc methodName)
59     {
60         super("AssertTask::",methodName);
61     }
62
63
64     /**
65      * Create full test suite for AssertTask.
66      **/

67     public static TestSuite suite()
68     {
69         return new TestSuite(AssertionRuleTest.class);
70     }
71
72
73     /**
74      * Create baseline test suite for AssertTask (same as full).
75      **/

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

85     public static void main(String JavaDoc[] argv)
86     {
87         HTCUtils.quickCheck(suite());
88     }
89
90
91 // ---------------------------------------------------------------------------------------------------------
92
// ---------------------------------------- [ Misc Setup Methods ] -----------------------------------------
93
// ---------------------------------------------------------------------------------------------------------
94

95     protected void setUp() throws Exception JavaDoc
96     {
97         configureProjectFromResource("assert.xml");
98     }
99
100     protected void expectViolation(String JavaDoc target, String JavaDoc cause, String JavaDoc msg)
101         throws Exception JavaDoc
102     {
103         try {
104             executeTarget(target);
105         } catch (BuildException ex) {
106             Throwable JavaDoc t = ex.getException();
107             println("*** THROWN: "+ex.getMessage());
108             if (t!=null) {
109                 assertTrue((t instanceof BuildAssertionException), "Is Assertion Exception");
110             }
111             if ((null != msg) && (!ex.getMessage().equals(msg))) {
112                 fail("Should throw AssertionException because '" + cause
113                         + "' with message '" + msg
114                         + "' (actual message '" + ex.getMessage() + "' instead)");
115             }
116             return;
117         }
118         fail("Should throw AssertionException because: " + cause);
119     }
120
121     protected void expectViolation(String JavaDoc target, String JavaDoc cause, String JavaDoc msg, String JavaDoc pn, String JavaDoc pv)
122          throws Exception JavaDoc
123     {
124         expectViolation(target,cause,msg);
125         assertPropertyEquals(pn,pv);
126     }
127
128
129 // ---------------------------------------------------------------------------------------------------------
130
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
131
// ---------------------------------------------------------------------------------------------------------
132

133     public void checkBaseline()
134     {
135         //--Ensures setUp() works and can find our xml file!
136
}
137
138     public void testBaseline()
139     {
140         checkBaseline();
141     }
142
143     public void testFailEmptyElement()
144     {
145         expectBuildExceptionContaining("undefined","Empty Assertion","At least one condition");
146     }
147
148     public void testPassNoFailProperty()
149     {
150         runTargetNoOutput("testNoFailProperty");
151     }
152
153
154     public void testSimpleTruths()
155     {
156         runTargetNoOutput("simple.truths");
157         assertPropertyEquals("truth.istrue",null);
158         assertPropertyEquals("truth.isfalse",null);
159         assertPropertyEquals("truth.isset",null);
160         assertPropertyEquals("truth.welcome",null);
161         assertPropertyEquals("truth.isnotset",null);
162         assertPropertyEquals("truth.varnotset",null);
163         assertPropertyEquals("truth.notwhitespace",null);
164         assertPropertyEquals("truth.antfile",null);
165         assertPropertyEquals("truth.isnumeric",null);
166         assertPropertyEquals("truth.ishexnumeric",null);
167         assertPropertyEquals("truth.file",null);
168         assertPropertyEquals("truth.dir",null);
169         assertPropertyEquals("truth.resource",null);
170         assertPropertyEquals("truth.class",null);
171         assertPropertyEquals("truth.isref",null);
172         assertPropertyEquals("truth.isnotref",null);
173         assertPropertyEquals("broken.filenotempty",null);
174     }
175
176     public void testSimpleFalsehoods() throws Exception JavaDoc
177     {
178         expectViolation("not.istrue","false!=true",null,"falsehood.istrue","true");
179         expectViolation("not.isfalse","true!=false",null,"falsehood.isfalse","true");
180         expectViolation("not.isset","property-not-set",null,"falsehood.isset","true");
181         expectViolation("not.isnotset","property-is-set",null,"falsehood.isnotset","true");
182         expectViolation("not.isnotwhitespace","is-whitespace",null,"falsehood.isnotwhitespace","true");
183         expectViolation("not.isnumeric","is-not-number",null,"falsehood.isnumeric","true");
184         expectViolation("not.isnumeric2nd","empty-is-not-number",null,"falsehood.isnumeric2nd","true");
185         expectViolation("not.isfile","is-not-file",null,"falsehood.isfile","fs.dink");
186         expectViolation("not.isfile2","is-not-file2",null,"falsehood.isfile2","true");
187         expectViolation("not.isdir","is-not-directory",null,"falsehood.isdir","fs.doink");
188         expectViolation("not.isresource","is-not-resource",null,"falsehood.isrez","true");
189         expectViolation("not.startswith","not-startswith",null,"falsehood.startswith","true");
190         expectViolation("not.endswith","not-endswith",null,"falsehood.endswith","true");
191         expectViolation("not.contains","not-contains",null,"falsehood.contains","true");
192         expectViolation("not.equals","not-equals",null,"falsehood.equals","true");
193         expectViolation("not.notequals","not-not-equals",null,"falsehood.notequals","true");
194         expectViolation("not.isclass","not-isclass",null,"falsehood.isclass","true");
195         expectViolation("not.isref","not-isref",null,"falsehood.isref","true");
196         expectViolation("not.isnotref","not-isnotref",null,"falsehood.isnotref","true");
197         expectViolation("not.filenotempty","not-filenotempty",null,"falsehood.filenotempty","true");
198     }
199
200     public void testSetsOfTruths()
201     {
202         runTargetNoOutput("testTruthsBySets");
203         assertPropertyEquals("broken.allset",null);
204         assertPropertyEquals("broken.noneset",null);
205         assertPropertyEquals("broken.anyset",null);
206     }
207
208     public void testSetsOfFalsehoods() throws Exception JavaDoc
209     {
210         expectViolation("not.allset","not-allset",null,"falsehood.allset","true");
211         expectViolation("not.noneset","not-noneset(mid)",null,"falsehood.noneset","true");
212         expectViolation("not.noneset2","not-noneset(end)",null,"falsehood.noneset2","true");
213         expectViolation("not.anyset","not-anyset",null,"falsehood.anyset","ack");
214     }
215
216     public void testFailIfInlineAndNestedConditions()
217     {
218         runExpecting("testFailInlineAndNested","Cannot have inline and nested conditions");
219     }
220
221     public void testFailIfIncompleteInlineEquals()
222     {
223         runExpecting("testIncompleteInlineEqualsCaught","Inline 'equals' must have two args");
224     }
225
226     public void testFailMixingInlineConditions()
227     {
228         runExpecting("testFailMixingInlineConditions","Inline 'equals' and 'isref' is boo-boo");
229     }
230
231     public void testUsingMsgId()
232     {
233         expectBuildExceptionContaining("fail.with.msgid","Wanted-To","Teensy Weensy Spider");
234     }
235
236     public void testCompoundTruthsInAttributeLogicAND()
237     {
238         runTargetNoOutput("compound.truths.and");
239     }
240
241     public void testCompoundTruthsInAttributeLogicOR()
242     {
243         runTargetNoOutput("compound.truths.or");
244     }
245
246     public void testCompoundTruthsInNestedLogicAND()
247     {
248         runTargetNoOutput("compound.truths.nested.logic.and");
249         assertPropertyEquals("truth.nested.logic",null);
250     }
251
252     public void testCompoundFalsehoodsLogicInAttributeAND() throws Exception JavaDoc
253     {
254         expectViolation("compound.falsehoods.and","'Fail-here' not numeric",null,"falsehood.and","true");
255         String JavaDoc ordering = getProject().getProperty("expected.condition.ordering");
256         assertNotNil(ordering,"Expected condition ordering documented");
257         String JavaDoc realLog= getLog();
258         println("LOG:",realLog);
259         assertTrue(realLog.indexOf(ordering)>=0,"Ordering is "+ordering);
260     }
261     public void testCompoundFalsehoodsLogicInAttributeOR() throws Exception JavaDoc
262     {
263         expectViolation("compound.falsehoods.or","None were true",null,"falsehood.or","true");
264         String JavaDoc ordering = getProject().getProperty("expected.condition.ordering");
265         assertNotNil(ordering,"Expected condition ordering documented");
266         String JavaDoc realLog= getLog();
267         println("LOG:",realLog);
268         assertTrue(realLog.indexOf(ordering)>=0,"Ordering is "+ordering);
269     }
270
271     public void testEiffelisqueAliasesTrue()
272     {
273         runTargetNoOutput("eiffel.like.truths");
274     }
275
276     public void testGoodReferrals()
277     {
278         runTargetNoOutput("testReferrals");
279         assertPropertyEquals("broken.referral0",null);
280     }
281
282     public void testCircularReferrals()
283     {
284         String JavaDoc log= runExpecting("testCircularReferrals","CircularReferral");
285         assertTrue(log.indexOf("rule chain contains a circular dependency")>-1,"Circular problem found");
286     }
287
288     public void testIncompatibleReferrals()
289     {
290         String JavaDoc log= runExpecting("testIncompatibleReferrals","IncompatibleReferral");
291         assertTrue(log.indexOf("must be compatible with effect")>-1,"Incompatibility found");
292     }
293
294     public void testMatchesCondition()
295     {
296         runTargetNoOutput("testMatches");
297     }
298
299     public void testIsNumericCondition()
300     {
301         runTarget("testIsNumeric");
302     }
303
304     public void testOutOfOrderParameters_AntX04()
305     {
306         runTarget("testOutOfOrderParameters_AntX04");
307     }
308
309     public void testCustomConditions_AntX04()
310     {
311         runTarget("testCustomConditions_AntX04");
312     }
313
314     public void testWhitespaceItems_AntX04()
315     {
316         runTarget("testWhitespaceItems_AntX04");
317     }
318
319     public void testMalformedSingleChecks_AntX04()
320     {
321         runTarget("testMalformedSingleChecks_AntX04");
322     }
323
324     public void testMalformedGroupChecks_AntX04()
325     {
326         runTarget("testMalformedGroupChecks_AntX04");
327     }
328
329     public void testMalformedAnySetChecks_AntX04()
330     {
331         runTarget("testMalformedAnySetChecks_AntX04");
332     }
333
334     public void testAntVersionChecks_AntX04()
335     {
336         runTarget("testAntVersionChecks_AntX04");
337     }
338
339     public void testGroupedPropertySets_AntX04()
340     {
341         runTarget("testGroupedPropertySets_AntX04");
342     }
343
344     public void testAntXAssertionHasJUnitAssertion_AntX04()
345     {
346         BuildAssertionException aX = new BuildAssertionException("I died");
347         Throwable JavaDoc juthr = aX.getJUnitLink();
348         assertNotNil(juthr,"JUnit-linked assertion error");
349         println("JUNIT ERROR: ",juthr);
350     }
351
352     public void testLimitedUnknownMessageDisplay_AntX05()
353     {
354         expectBuildExceptionContaining("testLimitedUnknownMessageDisplay_AntX05",
355             "Wanted-To","False.Is.Not.True...Shocking");
356     }
357     
358     public void testCanShorthandClientConditions_AntX05()
359     {
360         runTarget("testCanShorthandClientConditions_AntX05");
361     }
362
363     public void testFailUnknownShorthandClientCondition_AntX05()
364     {
365         runExpecting("testFailUnknownShorthandClientCondition_AntX05",
366             "The 'Xisset' condition should be unrecognized");
367     }
368 }
369
370
371 /* end-of-AssertionRuleTest.java */
372
Popular Tags