KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > feedback > tests > EmitTaskTest


1 /**
2  * $Id: EmitTaskTest.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2004 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 of the License, or (at your option) any later
9  * 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.feedback.tests;
30
31 import java.util.List JavaDoc;
32
33 import junit.framework.TestSuite;
34
35 import com.idaremedia.antx.helpers.Tk;
36 import com.idaremedia.antx.ut.HTCUtils;
37
38 /**
39  * Class test for {@linkplain com.idaremedia.antx.feedback.EmitTask EmitTask}.
40  *
41  * @since JWare/AntX 0.1
42  * @author ssmc, &copy;2002-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
43  * @version 0.5
44  * @.safety single
45  * @.group impl,test
46  **/

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

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

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

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

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

94     protected String JavaDoc getDefaultConfigureXMLFileName()
95     {
96         return "emit.xml";
97     }
98
99 // ---------------------------------------------------------------------------------------------------------
100
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
101
// ---------------------------------------------------------------------------------------------------------
102

103     public void testEmptyOK()
104     {
105         runTarget("testEmptyOK");
106     }
107
108     public void testDefaultEchoesToAnt()
109     {
110         String JavaDoc log= runTarget("testDefaultEchoesToAnt");
111         assertTrue(log.indexOf("log4j")>=0, "Log4j-message echoed to Ant");
112     }
113
114     public void testDefaultFroms()
115     {
116         String JavaDoc log = runTarget("testDefaultFroms");
117         verifyOccurances(log,"From: ",getIntegerProperty("EmitCount"));
118     }
119
120     public void testDefaultFromsNoEcho()
121     {
122         String JavaDoc log = runEchoedTarget("testDefaultFromsNoEcho");
123         verifyOccurances(log,"From: ",0);
124         verifyOccurances(testAppender().getLog(),"From: ",getIntegerProperty("EmitCount"));
125     }
126
127     public void testFatalLevelIsPinnedInAnt()
128     {
129         String JavaDoc 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 JavaDoc log = runEchoedTarget("testEmitAllMsgLevels");
138         int N= getIntegerProperty("EmitCount");
139         verifyOccurances(log,"Helloworld",4);//FATAL+ERR+WARN+INFO
140
String JavaDoc 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 JavaDoc today = getTodayString();
150         println("TODAY = ("+today+")");
151
152         String JavaDoc log = runEchoedTarget("testTimestamping");
153         String JavaDoc fullLog = getFullLog();
154         String JavaDoc 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 JavaDoc today = getTodayString();
170         println("TODAY = ("+today+")");
171
172         String JavaDoc log = runEchoedTarget("testTimestampAndArgSubstitution");
173         String JavaDoc 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 JavaDoc log = runEchoedTarget("testEmitThrownExceptions",null);
195         assertTrue(log.indexOf("Something went BoINk")>=0, "Emitted Exception Info");
196         String JavaDoc 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         //NB: we can't verify ordering since it's arbitrary from
204
// the snapshot's underlying captured properties map...
205
String JavaDoc log4jLog= testAppender().getLog();
206         List JavaDoc 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 JavaDoc)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     /** @since JWare/AntX 0.4 **/
233     public void testEmitFromPrinterRegistry_AntX04()
234     {
235         String JavaDoc log= runEchoedTarget("testEmitFromPrinterRegistry_AntX04");
236         assertTrue(log.indexOf("HelloFromPrinterRegistryEnabledWorld")>=0,"Emitted comment bits");
237         String JavaDoc log4jLog = testAppender().getLog();
238         assertTrue(log4jLog.indexOf("ThroatWobblerMangrove")>=0,"Emitted TWMangrove bits to Log4J");
239     }
240 }
241
242 /* end-of-EmitTaskTest.java */
243
Popular Tags