1 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 48 49 public class AssertionRuleTest extends HTC 50 { 51 52 public static final String TEST_CATEGORY="CLASS"; 53 54 55 58 public AssertionRuleTest(String methodName) 59 { 60 super("AssertTask::",methodName); 61 } 62 63 64 67 public static TestSuite suite() 68 { 69 return new TestSuite(AssertionRuleTest.class); 70 } 71 72 73 76 public static TestSuite baseline() 77 { 78 return suite(); 79 } 80 81 82 85 public static void main(String [] argv) 86 { 87 HTCUtils.quickCheck(suite()); 88 } 89 90 91 95 protected void setUp() throws Exception 96 { 97 configureProjectFromResource("assert.xml"); 98 } 99 100 protected void expectViolation(String target, String cause, String msg) 101 throws Exception 102 { 103 try { 104 executeTarget(target); 105 } catch (BuildException ex) { 106 Throwable 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 target, String cause, String msg, String pn, String pv) 122 throws Exception 123 { 124 expectViolation(target,cause,msg); 125 assertPropertyEquals(pn,pv); 126 } 127 128 129 133 public void checkBaseline() 134 { 135 } 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 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 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 253 { 254 expectViolation("compound.falsehoods.and","'Fail-here' not numeric",null,"falsehood.and","true"); 255 String ordering = getProject().getProperty("expected.condition.ordering"); 256 assertNotNil(ordering,"Expected condition ordering documented"); 257 String realLog= getLog(); 258 println("LOG:",realLog); 259 assertTrue(realLog.indexOf(ordering)>=0,"Ordering is "+ordering); 260 } 261 public void testCompoundFalsehoodsLogicInAttributeOR() throws Exception 262 { 263 expectViolation("compound.falsehoods.or","None were true",null,"falsehood.or","true"); 264 String ordering = getProject().getProperty("expected.condition.ordering"); 265 assertNotNil(ordering,"Expected condition ordering documented"); 266 String 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 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 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 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 372 | Popular Tags |