| 1 28 29 package com.idaremedia.antx.tests; 30 31 import java.io.File ; 32 import java.io.FileWriter ; 33 import java.io.PrintWriter ; 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 52 53 public final class InitUISMTaskTest extends HTC 54 { 55 56 public static final String TEST_CATEGORY="CLASS"; 57 58 59 62 public InitUISMTaskTest(String methodName) 63 { 64 super("InitUISMTask::",methodName); 65 } 66 67 68 71 public static TestSuite suite() 72 { 73 return new TestSuite(InitUISMTaskTest.class); 74 } 75 76 77 80 public static TestSuite baseline() 81 { 82 return suite(); } 84 85 86 89 public static void main(String [] argv) 90 { 91 HTCUtils.quickCheck(suite()); 92 } 93 94 95 99 static final String TMP_TARGET = "theTest"; 100 static final String UISTRS_BUNDLE = "com.idaremedia.antx.tests.OtherUIStrings"; 101 static final String UISTRS_RESOURCE = "OtherUIStrings.properties"; 102 103 static final String BY_URL_DEBUG_MSG = "Copied UISM URL"; 104 static final String DBG_MSG_UISTRINGS = "DO NOT REMOVE. Helloworld"; 105 static final String DBG_MSG_OTHER_UISTRINGS = "GO AHEAD REMOVE ME. Byeworld"; 106 107 static final String _XML_tN="\"/>\n"; 108 static final String _XML_tf0=" <initmsgs_ action=\"install\" file=\""; 109 static final String _XML_tu0=" <initmsgs_ action=\"install\" url=\""; 110 111 private void writeBeginXML(PrintWriter 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 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 w, String 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 w, String 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  144 { 145 FileUtils fu= AntXFixture.fileUtils(); 146 File from = getFileResource(UISTRS_RESOURCE); 147 File to = File.createTempFile("qatUIStrings-",".properties"); 148 fu.copyFile(from, to, null, true); 149 File tempBuildFile = File.createTempFile("qatBuild-",".xml"); 150 PrintWriter w = new PrintWriter (new FileWriter (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 target, String type) 163 { 164 runTargetNoOutput(target); 165 String fullLog = getFullLog(); 166 println("FFFFFFFFUUUUUUUUUULLLLL",fullLog); 167 assertTrue(fullLog.indexOf(BY_URL_DEBUG_MSG) != -1, 168 "Loaded '"+type+"' option to bundle"); 169 } 170 171 173 protected void setUp() throws Exception  174 { 175 String n = getName(); 176 if (!n.endsWith("_Tmp")) { 177 configureProjectFromResource("uism.xml"); 178 } 179 } 180 181 185 public void checkBaseline() 186 { 187 } 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  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  246 { 247 configureTempBuildFileProject(true); 248 verifyLoadable(TMP_TARGET,"file"); 249 } 250 251 public void testPassByFileURL_Tmp() throws Exception  252 { 253 configureTempBuildFileProject(false); 254 verifyLoadable(TMP_TARGET,"file"); 255 } 256 257 public void testDefaultPassthruYesInherited() 258 { 259 String log = runTarget("testDefaultPassthruYesInherit"); 260 verifyOccurances(log,"Helloworld",1); 261 } 262 263 public void testDefaultPassthruNoInherited() 264 { 265 String 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 log = runTarget("testDefaultPassthruManyJumpsYesInherit"); 273 verifyOccurances(log,"Helloworld",1); 274 } 275 276 public void testDefaultPassthruCallOtherAntProcess() 277 { 278 String log = runTarget("testDefaultPassthruCallOtherAntProcess"); 279 verifyOccurances(log,"Helloworld",1); 280 } 281 282 public void testPassthruStickyLikeVelcro() 283 { 284 String 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 log = runTarget("testUsingMsgBundleRef"); 299 verifyOccurances(log,"Byeworld",1); 300 } 301 302 public void testUsingMsgBundleReferencesByURL() 303 { 304 String log = runTarget("testUsingMsgBundleRefByURL"); 305 verifyOccurances(log,"Byeworld",1); 306 } 307 308 309 public void testNoOpsUnknownManageInstructions() 310 { 311 String log = runTarget("testUnknownManageDirective"); 312 String 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 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 333 | Popular Tags |