KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > JBossTestSetup


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test;
23
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26
27 import javax.management.MBeanServerConnection JavaDoc;
28 import javax.management.MalformedObjectNameException JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31
32 import junit.extensions.TestSetup;
33 import junit.framework.Test;
34
35 import org.jboss.logging.Logger;
36
37 /**
38  * This is a TestSetup class for jboss junit test cases that provides the
39  * jboss test services. It supplies
40  * access to jboss logging, the jboss jmx server, jndi, and a method for
41  * deploying ejb packages. You may supply the name of the machine the jboss
42  * server is on with the system property jbosstest.server.name (default
43  * getInetAddress().getLocalHost().getHostName()) and the directory for
44  * deployable packages with the system property jbosstest.deploy.dir (default
45  * ../lib).
46  *
47  * Should be sublassed to derive junit support for specific services integrated
48  * into JBoss.
49  *
50  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
51  * @author <a HREF="mailto:christoph.jung@jboss.org">Christoph G. Jung</a>
52  * @version $Revision: 58481 $
53  */

54 public class JBossTestSetup
55    extends AbstractTestSetup
56 {
57    protected JBossTestServices delegate;
58
59    /**
60     * Constructor for the JBossTestCase object
61     *
62     * @param test the test
63     * @throws Exception for any error
64     */

65    public JBossTestSetup(final Class JavaDoc clazz, Test test) throws Exception JavaDoc
66    {
67       super(clazz, test);
68    }
69    public JBossTestSetup(Test test) throws Exception JavaDoc
70    {
71       super(JBossTestCase.class, test);
72    }
73
74    @Override JavaDoc
75    protected void setUp() throws Exception JavaDoc
76    {
77       super.setUp();
78       this.delegate = (JBossTestServices) AbstractTestSetup.delegate;
79    }
80
81    @Override JavaDoc
82    protected void tearDown() throws Exception JavaDoc
83    {
84       // TODO Auto-generated method stub
85
super.tearDown();
86    }
87
88
89    /**
90     * Gets the InitialContext attribute of the JBossTestCase object
91     *
92     * @return The InitialContext value
93     * @throws Exception for any error
94     */

95    protected InitialContext JavaDoc getInitialContext() throws Exception JavaDoc
96    {
97       return delegate.getInitialContext();
98    }
99
100    /**
101     * Gets the Server attribute of the JBossTestCase object
102     *
103     * @return The Server value
104     * @throws Exception for any error
105     */

106    protected MBeanServerConnection JavaDoc getServer() throws Exception JavaDoc
107    {
108       return delegate.getServer();
109    }
110
111    /**
112     * Gets the Log attribute of the JBossTestCase object
113     *
114     * @return The Log value
115     */

116    protected Logger getLog()
117    {
118       return delegate.getLog();
119    }
120
121    /**
122     * Gets the DeployerName attribute of the JBossTestCase object
123     *
124     * @return The DeployerName value
125     * @exception MalformedObjectNameException Description of Exception
126     */

127    protected ObjectName JavaDoc getDeployerName() throws MalformedObjectNameException JavaDoc
128    {
129       return delegate.getDeployerName();
130    }
131
132    /**
133     * Returns the deployment directory to use. This does it's best to figure out
134     * where you are looking. If you supply a complete url, it returns it.
135     * Otherwise, it looks for jbosstest.deploy.dir or if missing ../lib. Then it
136     * tries to construct a file url or a url.
137     *
138     * @param filename name of the file/url you want
139     * @return A more or less canonical string for the url.
140     * @exception MalformedURLException Description of Exception
141     */

142    protected URL JavaDoc getDeployURL(final String JavaDoc filename) throws MalformedURLException JavaDoc
143    {
144       return delegate.getDeployURL(filename);
145    }
146
147    protected String JavaDoc getResourceURL(final String JavaDoc path)
148    {
149       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
150       URL JavaDoc resURL = loader.getResource(path);
151       String JavaDoc resPath = resURL != null ? resURL.toString() : null;
152       return resPath;
153    }
154
155    /**
156     * invoke wraps an invoke call to the mbean server in a lot of exception
157     * unwrapping.
158     *
159     * @param name ObjectName of the mbean to be called
160     * @param method mbean method to be called
161     * @param args Object[] of arguments for the mbean method.
162     * @param sig String[] of types for the mbean methods parameters.
163     * @return Object returned by mbean method invocation.
164     * @exception Exception Description of Exception
165     */

166    protected Object JavaDoc invoke(ObjectName JavaDoc name, String JavaDoc method, Object JavaDoc[] args, String JavaDoc[] sig) throws Exception JavaDoc
167    {
168       return delegate.invoke(name, method, args, sig);
169    }
170
171    /**
172     * Deploy a package with the main deployer. The supplied name is
173     * interpreted as a url, or as a filename in jbosstest.deploy.lib or ../lib.
174     *
175     * @param name filename/url of package to deploy.
176     * @exception Exception Description of Exception
177     */

178    protected void deploy(String JavaDoc name) throws Exception JavaDoc
179    {
180       delegate.deploy(name);
181    }
182
183    protected void redeploy(String JavaDoc name) throws Exception JavaDoc
184    {
185       delegate.redeploy(name);
186    }
187
188    /**
189     * Undeploy a package with the main deployer. The supplied name is
190     * interpreted as a url, or as a filename in jbosstest.deploy.lib or ../lib.
191     *
192     * @param name filename/url of package to undeploy.
193     * @exception Exception Description of Exception
194     */

195    protected void undeploy(String JavaDoc name) throws Exception JavaDoc
196    {
197       delegate.undeploy(name);
198    }
199
200
201    protected void flushAuthCache() throws Exception JavaDoc
202    {
203       flushAuthCache("other");
204    }
205
206    protected void flushAuthCache(String JavaDoc domain) throws Exception JavaDoc
207    {
208       delegate.flushAuthCache(domain);
209    }
210
211    /** Restart the connection pool associated with the DefaultDS
212     * @throws Exception on failure
213     */

214    protected void restartDBPool() throws Exception JavaDoc
215    {
216       delegate.restartDBPool();
217    }
218
219    protected String JavaDoc getJndiURL()
220    {
221       return delegate.getJndiURL();
222    }
223
224    protected String JavaDoc getJndiInitFactory()
225    {
226       return delegate.getJndiInitFactory();
227    }
228
229    protected int getThreadCount()
230    {
231       return delegate.getThreadCount();
232    }
233
234    protected int getIterationCount()
235    {
236       return delegate.getIterationCount();
237    }
238
239    protected int getBeanCount()
240    {
241       return delegate.getBeanCount();
242    }
243
244    /**
245     * Get the JBoss server host from system property "jbosstest.host.name"
246     * This defaults to "localhost"
247     *
248     * @return the host name
249     */

250    public String JavaDoc getServerHost()
251    {
252       return delegate.getServerHost();
253    }
254 }
255
Popular Tags