1 28 29 package com.idaremedia.antx.tests; 30 31 import java.util.Map ; 32 33 import org.apache.tools.ant.Project; 34 35 import junit.framework.TestSuite; 36 37 import com.idaremedia.antx.FixtureExaminer; 38 import com.idaremedia.antx.Iteration; 39 import com.idaremedia.antx.helpers.SIDs; 40 import com.idaremedia.antx.ut.HTC; 41 import com.idaremedia.antx.ut.HTCUtils; 42 43 52 53 public final class IterationTest extends HTC 54 { 55 58 public IterationTest(String methodName) 59 { 60 super("(Plain)Iteration::",methodName); 61 } 62 63 64 67 public static TestSuite suite() 68 { 69 return new TestSuite(IterationTest.class); 70 } 71 72 73 76 public static void main(String [] argv) 77 { 78 HTCUtils.quickCheck(suite()); 79 } 80 81 82 86 protected void setUp() throws Exception 87 { 88 if ("testBaseline".equals(getName())) { 89 Iteration.set(new FakeIteration()); 90 configureProjectFromResource("fakeiteration.xml"); 91 } else { 92 Iteration.reset(); 93 94 configureProjectFromResource("standardblank.xml"); 95 } 96 } 97 98 99 103 public void checkBaseline() 104 { 105 } 107 108 public void testBaseline() 109 { 110 checkBaseline(); 111 runTarget("AllTests"); 112 } 113 114 115 public void testSetTopLevelFlatProperty_AntX05() 116 { 117 String key0 = SIDs.next(); 118 String key1 = key0+".b"; 119 120 assertNull(Iteration.getProperty(key0)); 121 Iteration.setProperty(key0,"helloworld"); 122 assertEquals(new String ("h"+"elloworld"),Iteration.getProperty(key0)); 123 String val0 = String.valueOf(Iteration.getProperty(key0)); 124 125 Iteration.setProperty(key1,new Integer (111)); 126 assertEquals(val0,Iteration.getProperty(key0)); 127 assertTrue(Iteration.getProperty(key1) instanceof Integer ); 128 assertEquals("111",String.valueOf(Iteration.getProperty(key1))); 129 130 Iteration.removeProperty(key0); 131 assertNil(Iteration.getProperty(key0)); 132 assertNotNil(Iteration.getProperty(key1)); 133 134 Iteration.setProperty(key1, new RuntimeException ("imbroken")); 135 assertTrue(Iteration.getProperty(key1) instanceof RuntimeException ); 136 assertNil(Iteration.getProperty(key0)); 137 138 Iteration.removeProperty(key1); 139 assertNil(Iteration.getProperty(key1)); 140 } 141 142 143 private void verifyFixture00(String category0, String category1, String key0) 144 { 145 assertNil(Iteration.getProperty(category0)); 146 assertNil(Iteration.getProperty(category0,key0)); 147 assertNil(Iteration.getProperty(key0)); 148 assertNil(Iteration.getProperty(category1)); 149 } 150 151 152 public void testSetTopLevelNestedProperty_AntX05() 153 { 154 String category0 = SIDs.next("ITCAT"); 155 String key0 = SIDs.next(); 156 String category1 = key0+".ITCAT"; 157 158 verifyFixture00(category0,category1,key0); 159 160 Iteration.setProperty(category0,key0,"Hola Mundo"); 161 assertTrue(Iteration.getProperty(category0) instanceof Map ); 162 assertEquals(new String ("Hola "+"Mundo"),Iteration.getProperty(category0,key0)); 163 assertNil(Iteration.getProperty(key0)); 164 165 Iteration.setProperty(category1,"flat"); 166 Iteration.setProperty(category1,key0,"ERROR"); 167 assertEquals("flat",Iteration.getProperty(category1)); 168 assertNil(Iteration.getProperty(key0)); 169 assertNil(Iteration.getProperty(category0,category1)); 170 171 Iteration.removeProperty(category1); 172 Iteration.setProperty(category1,key0,"OK!"); 173 assertTrue(Iteration.getProperty(category1) instanceof Map ); 174 assertIdent("OK!",Iteration.getProperty(category1,key0)); 175 176 Iteration.removeProperty(category1,key0); 177 Object o = Iteration.getProperty(category1); 178 assertTrue(o instanceof Map ); 179 assertEqual(0,((Map )o).size(),"map size"); 180 181 Iteration.setProperty(category1,category0); assertIdent(Iteration.getProperty(category1),category0); 183 Iteration.removeProperty(category0); 184 Iteration.removeProperty(category1); 185 186 verifyFixture00(category0,category1,key0); 187 } 188 189 190 public void testTopLevelValueURIBuiltin_AntX05() 191 { 192 final Project P = new Project(); 193 Object itid = Iteration.getProperty("Iteration.ITID"); 194 assertNotNil(itid,"Iteration.ITID property"); 195 assertIdent(itid,FixtureExaminer.findValue(P,"$itprop:Iteration.ITID","")); 196 197 String category0 = SIDs.next("ITCAT"); 198 String key0 = SIDs.next(); 199 String refkey0 = "$itproperty:"+category0+"->"+key0; 200 201 assertNil(FixtureExaminer.findValue(P,refkey0,""),refkey0); 202 Iteration.setProperty(key0,"HelloWorld"); 203 Iteration.setProperty(category0,key0,"ByeWorld"); 204 assertEqual("HelloWorld",FixtureExaminer.findValue(P,"$itproperty:"+key0,"")); 205 assertEqual("ByeWorld",FixtureExaminer.findValue(P,refkey0,"")); 206 207 Iteration.removeProperty(category0); 208 Iteration.removeProperty(key0); 209 } 210 211 212 public void testFailGetNullProperties_AntX05() 213 { 214 try { 215 Iteration.getProperty(null); 216 fail("Should not be able to get NULL property name"); 217 } catch(IllegalArgumentException Xpected) { 218 assertExpected(Xpected,"property name"); 219 } 220 try { 221 Iteration.getProperty(null,"item0"); 222 fail("Should not be able to get NULL category name"); 223 } catch(IllegalArgumentException Xpected) { 224 assertExpected(Xpected,"category"); 225 } 226 try { 227 Iteration.getProperty("category0",null); 228 fail("Should not be able to get NULL category property"); 229 } catch(IllegalArgumentException Xpected) { 230 assertExpected(Xpected,"property name"); 231 } 232 } 233 234 235 public void testFailPutNullProperties_AntX05() 236 { 237 try { 238 Iteration.setProperty(null,"value0"); 239 fail("Should not be able to set NULL property name"); 240 } catch(IllegalArgumentException Xpected) { 241 assertExpected(Xpected,"property name"); 242 } 243 try { 244 Iteration.setProperty(null,"item0","value0"); 245 fail("Should not be able to set NULL category name"); 246 } catch(IllegalArgumentException Xpected) { 247 assertExpected(Xpected,"category"); 248 } 249 try { 250 Iteration.setProperty("category0",null,"value0"); 251 fail("Should not be able to set NULL category property"); 252 } catch(IllegalArgumentException Xpected) { 253 assertExpected(Xpected,"property name"); 254 } 255 } 256 257 258 public void testFailRemoveNullProperties_AntX05() 259 { 260 try { 261 Iteration.removeProperty(null); 262 fail("Should not be able to remove NULL property name"); 263 } catch(IllegalArgumentException Xpected) { 264 assertExpected(Xpected,"property name"); 265 } 266 try { 267 Iteration.removeProperty(null,"item0"); 268 fail("Should not be able to remove NULL category name"); 269 } catch(IllegalArgumentException Xpected) { 270 assertExpected(Xpected,"category"); 271 } 272 try { 273 Iteration.removeProperty("category0",null); 274 fail("Should not be able to remove NULL category property"); 275 } catch(IllegalArgumentException Xpected) { 276 assertExpected(Xpected,"property name"); 277 } 278 } 279 280 281 public void testHaveAccessToInheritedIterationFields_AntX05() 282 throws Exception 283 { 284 FakeIteration out = new FakeIteration(); 285 String value = out.getInheritedField("m_itid"); 286 assertEqual("java.lang.String",value,"inherited 'm_itid' field"); 287 value = out.getInheritedField("m_defaultsINSTANCE"); 288 assertEqual("com.idaremedia.antx.Defaults",value,"inherited 'm_defaultsINSTANCE' field"); 289 } 290 } 291 292 | Popular Tags |