1 28 29 package com.idaremedia.antx.feedback.tests; 30 31 import java.util.List ; 32 33 import junit.framework.TestSuite; 34 35 import com.idaremedia.antx.helpers.Tk; 36 import com.idaremedia.antx.ut.HTCUtils; 37 38 47 48 public final class EmitTaskTest extends EmitTestSkeleton 49 { 50 51 public static final String TEST_CATEGORY="CLASS"; 52 53 54 57 public EmitTaskTest(String methodName) 58 { 59 super("EmitTask::",methodName); 60 } 61 62 63 66 public static TestSuite suite() 67 { 68 return new TestSuite(EmitTaskTest.class); 69 } 70 71 72 75 public static TestSuite baseline() 76 { 77 return suite(); } 79 80 81 84 public static void main(String [] argv) 85 { 86 HTCUtils.quickCheck(suite()); 87 } 88 89 90 94 protected String getDefaultConfigureXMLFileName() 95 { 96 return "emit.xml"; 97 } 98 99 103 public void testEmptyOK() 104 { 105 runTarget("testEmptyOK"); 106 } 107 108 public void testDefaultEchoesToAnt() 109 { 110 String log= runTarget("testDefaultEchoesToAnt"); 111 assertTrue(log.indexOf("log4j")>=0, "Log4j-message echoed to Ant"); 112 } 113 114 public void testDefaultFroms() 115 { 116 String log = runTarget("testDefaultFroms"); 117 verifyOccurances(log,"From: ",getIntegerProperty("EmitCount")); 118 } 119 120 public void testDefaultFromsNoEcho() 121 { 122 String log = runEchoedTarget("testDefaultFromsNoEcho"); 123 verifyOccurances(log,"From: ",0); 124 verifyOccurances(testAppender().getLog(),"From: ",getIntegerProperty("EmitCount")); 125 } 126 127 public void testFatalLevelIsPinnedInAnt() 128 { 129 String log = runEchoedTarget("testFatalLevelIsPinnedAnt",null); 130 int N= getIntegerProperty("EmitCount"); 131 verifyOccurances(log,"From: Dead",N); 132 verifyOccurances(testAppender().getLog(),"FATAL",N); 133 } 134 135 public void testEmitAllMsgLevels() 136 { 137 String log = runEchoedTarget("testEmitAllMsgLevels"); 138 int N= getIntegerProperty("EmitCount"); 139 verifyOccurances(log,"Helloworld",4); String log4jLog= testAppender().getLog(); 141 verifyOccurances(log4jLog,"Helloworld",N); 142 verifyOccurances(log4jLog,"FATAL",1); 143 verifyOccurances(log4jLog,"DEBUG",1); 144 verifyOccurances(getFullLog(),"Helloworld",N); 145 } 146 147 public void testTimestamping() 148 { 149 String today = getTodayString(); 150 println("TODAY = ("+today+")"); 151 152 String log = runEchoedTarget("testTimestamping"); 153 String fullLog = getFullLog(); 154 String log4jLog= testAppender().getLog(); 155 156 int N= getIntegerProperty("EmitCount"); 157 158 verifyOccurances(fullLog,"Helloworld from task (",N); 159 verifyOccurances(fullLog,"{2}", 0); 160 verifyOccurances(log,"Helloworld from task (",1); 161 verifyOccurances(log,today,1); 162 verifyOccurances(log4jLog,"Helloworld from task (",N); 163 verifyOccurances(log4jLog,today,N); 164 verifyOccurances(log4jLog,"{2}", 0); 165 } 166 167 public void testTimestampingWithArgSubstitution() 168 { 169 String today = getTodayString(); 170 println("TODAY = ("+today+")"); 171 172 String log = runEchoedTarget("testTimestampAndArgSubstitution"); 173 String log4jLog= testAppender().getLog(); 174 175 int N= getIntegerProperty("EmitCount"); 176 177 verifyOccurances(log,"Timeworld from task (emit_) on the",N); 178 verifyOccurances(log,today,N); 179 180 verifyOccurances(log4jLog,"Timeworld from task (emit_) on the",N); 181 verifyOccurances(log4jLog,today,N); 182 183 verifyOccurances(log4jLog,"{2}", 0); 184 verifyOccurances(log4jLog,"Felix",1); 185 verifyOccurances(log4jLog,"Murphy",1); 186 verifyOccurances(log4jLog,"Bob",1); 187 verifyOccurances(log4jLog,"Janet",1); 188 verifyOccurances(log4jLog,"1starg=()",1); 189 verifyOccurances(log4jLog,"2ndarg=({4})",1); 190 } 191 192 public void testEmitThrownExceptions() 193 { 194 String log = runEchoedTarget("testEmitThrownExceptions",null); 195 assertTrue(log.indexOf("Something went BoINk")>=0, "Emitted Exception Info"); 196 String log4jLog= testAppender().getLog(); 197 assertTrue(log4jLog.indexOf("Something went BoINk")>=0, "Emitted Exception Info to Log4J"); 198 } 199 200 201 private void verifyPropertiesEmitted() 202 { 203 String log4jLog= testAppender().getLog(); 206 List namelist = Tk.splitList(getProject().getProperty("echo.props"),","); 207 int N= getIntegerProperty("EmitCount"); 208 for (int i=0,M=namelist.size();i<M;i++) { 209 verifyOccurances(log4jLog,(String )namelist.get(i),N); 210 } 211 } 212 213 public void testEmitSelectProperties() 214 { 215 runEchoedTarget("testEmitSelectProperties"); 216 verifyPropertiesEmitted(); 217 } 218 219 public void testEmitNestedProperties() 220 { 221 runEchoedTarget("testEmitNestedProperties"); 222 verifyPropertiesEmitted(); 223 } 224 225 public void testEmitCombinationProperties() 226 { 227 runEchoedTarget("testEmitComboProperties"); 228 verifyPropertiesEmitted(); 229 verifyOccurances(testAppender().getLog(),"exportedVariable=phffht",1); 230 } 231 232 233 public void testEmitFromPrinterRegistry_AntX04() 234 { 235 String log= runEchoedTarget("testEmitFromPrinterRegistry_AntX04"); 236 assertTrue(log.indexOf("HelloFromPrinterRegistryEnabledWorld")>=0,"Emitted comment bits"); 237 String log4jLog = testAppender().getLog(); 238 assertTrue(log4jLog.indexOf("ThroatWobblerMangrove")>=0,"Emitted TWMangrove bits to Log4J"); 239 } 240 } 241 242 243 | Popular Tags |