KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: EmitTestSkeleton.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2003 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.text.DateFormat JavaDoc;
32
33 import org.apache.log4j.Logger;
34 import org.apache.log4j.LogManager;
35 import org.apache.log4j.spi.RendererSupport;
36
37 import com.idaremedia.antx.ErrorSnapshot;
38 import com.idaremedia.antx.feedback.ErrorSnapshotRenderer;
39 import com.idaremedia.antx.helpers.DateTimeFormat;
40 import com.idaremedia.antx.ut.HTC;
41
42
43 /**
44  * Helper class for EmitTask and EmitConfigureTask tests.
45  *
46  * @since JWare/AntX 0.1
47  * @author ssmc, &copy;2002-2003 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
48  * @version 0.5
49  * @.safety single
50  * @.group impl,test
51  **/

52
53 public abstract class EmitTestSkeleton extends HTC
54 {
55     /**
56      * Create new EmitTestSkeleton testcase.
57      **/

58     public EmitTestSkeleton(String JavaDoc grpId,String JavaDoc methodName)
59     {
60         super(grpId,methodName);
61     }
62
63
64 // ---------------------------------------------------------------------------------------------------------
65
// ---------------------------------------- [ Misc Setup Methods ] -----------------------------------------
66
// ---------------------------------------------------------------------------------------------------------
67

68     protected DateFormat JavaDoc m_dateFormatter;
69     protected EchoAppender m_testAppender=null;
70     protected String JavaDoc m_testLoggerCategory=null;
71
72
73     protected final Logger whichLogger(String JavaDoc grpId)
74     {
75         return (grpId==null) ? Logger.getRootLogger() : Logger.getLogger(grpId);
76     }
77
78     protected final EchoAppender testAppender()
79     {
80         assertNotNil(m_testAppender,"Attached Test Appender");
81         return m_testAppender;
82     }
83
84     protected final int getIntegerProperty(String JavaDoc pn)
85     {
86         String JavaDoc s = getProject().getProperty(pn);
87         try {
88             return Integer.parseInt(s);
89         } catch(Exception JavaDoc anyX) {
90             fail("Unable to parse number-property("+pn+" = "+s+")");
91         }
92         return 0;//4-compiler
93
}
94
95     protected final String JavaDoc getTodayString()
96     {
97         return m_dateFormatter.format(new java.util.Date JavaDoc());
98     }
99
100     protected void attachTestAppender(String JavaDoc grpId)
101     {
102         Logger l = whichLogger(grpId);
103         EchoAppender echo = new EchoAppender();
104         l.addAppender(echo);
105         m_testAppender = echo;
106         m_testLoggerCategory = grpId;
107     }
108
109     protected String JavaDoc runEchoedTarget(String JavaDoc target)
110     {
111         attachTestAppender("jware");
112         String JavaDoc antLog= runTarget(target);
113         println("\nLog4J's Appender LLLOOOGGG: ----",testAppender().getLog());
114         return antLog;
115     }
116
117     protected String JavaDoc runEchoedTarget(String JavaDoc target, String JavaDoc grpId)
118     {
119         attachTestAppender(grpId);
120         String JavaDoc antLog= runTarget(target);
121         println("\nLog4J's Appender LLLOOOGGG: ----",testAppender().getLog());
122         return antLog;
123     }
124
125     protected final void ensureErrorSnapshotRendererInstalled()
126     {
127         // *** THIS DOES NOT WORK THROUGH TO ANT SINCE JUNIT \\
128
// LOADS TESTS WITH OWN CLASSLOADER AND ANT LOADS \\
129
// TASKS/PROJECTS WITH DIFFERENT CLASSLOADER(S) *** \\
130

131         Logger lgr= LogManager.getRootLogger();
132         if (lgr.getLoggerRepository() instanceof RendererSupport) {
133             RendererSupport api = (RendererSupport)lgr.getLoggerRepository();
134             Object JavaDoc r = api.getRendererMap().get(ErrorSnapshot.class);
135             if (!(r instanceof ErrorSnapshotRenderer)) {
136                 println("[***] Installing ErrorSnapshot ObjectRenderer!");
137                 api.setRenderer(ErrorSnapshot.class, new ErrorSnapshotRenderer());
138             }
139         }
140     }
141
142     protected void setUp() throws Exception JavaDoc
143     {
144         super.setUp();
145         ensureErrorSnapshotRendererInstalled();
146         configureProjectFromResource(getDefaultConfigureXMLFileName());
147         m_dateFormatter = (DateFormat JavaDoc)DateTimeFormat.ABBREV_DATE.clone();
148     }
149
150     protected void tearDown() throws Exception JavaDoc
151     {
152         if (m_testAppender!=null) {
153             Logger l= whichLogger(m_testLoggerCategory);
154             l.removeAppender(m_testAppender);
155         }
156         super.tearDown();
157     }
158
159     protected abstract String JavaDoc getDefaultConfigureXMLFileName();
160
161 // ---------------------------------------------------------------------------------------------------------
162
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
163
// ---------------------------------------------------------------------------------------------------------
164

165     public void checkBaseline()
166     {
167         //--Ensures setUp() works and can find our xml file!
168
}
169
170     public void testBaseline()
171     {
172         checkBaseline();
173     }
174 }
175
176 /* end-of-EmitTestSkeleton.java */
177
Popular Tags