KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > CustomJNDIJBossTestCase


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.ejb3.test;
23
24 import java.util.StringTokenizer JavaDoc;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.jboss.test.AbstractTestDelegate;
30 import org.jboss.test.JBossTestCase;
31
32 /**
33  * This test case will use custom.jndi.properties to find the deployer.
34  *
35  * @author <a HREF="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
36  * @version $Revision: $
37  */

38 public class CustomJNDIJBossTestCase extends JBossTestCase
39 {
40
41    public CustomJNDIJBossTestCase(String JavaDoc name)
42    {
43       super(name);
44    }
45
46    /**
47     * Overriden to return CustomJNDIJBossTestServices as the test delegate.
48     */

49    public static AbstractTestDelegate getDelegate(Class JavaDoc clazz) throws Exception JavaDoc
50    {
51       AbstractTestDelegate delegate = new CustomJNDIJBossTestServices(clazz);
52       return delegate;
53    }
54
55    /**
56     * Get a JBossTestSetup that does login and deployment in setUp/tearDown
57     *
58     * @param test a Test
59     * @param jarNames is a comma seperated list of deployments
60     */

61    public static Test getDeploySetup(final Test test, final String JavaDoc jarNames)
62       throws Exception JavaDoc
63    {
64       CustomJNDIJBossTestSetup wrapper = new CustomJNDIJBossTestSetup(test)
65       {
66          protected void setUp() throws Exception JavaDoc
67          {
68             deploymentException = null;
69             try
70             {
71                this.delegate.init();
72
73                if (this.getDelegate().isSecureTest())
74                   this.delegate.login();
75
76                if (jarNames == null) return;
77
78                // deploy the comma seperated list of jars
79
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(jarNames, ", ");
80                while (st != null && st.hasMoreTokens())
81                {
82                   String JavaDoc jarName = st.nextToken();
83                   this.redeploy(jarName);
84                   this.getLog().debug("deployed package: " + jarName);
85                }
86             }
87             catch (Exception JavaDoc ex)
88             {
89                // Throw this in testServerFound() instead.
90
deploymentException = ex;
91             }
92          }
93
94          protected void tearDown() throws Exception JavaDoc
95          {
96             if (jarNames == null) return; //Nothing to Undeploy
97

98             // undeploy the comma seperated list of jars
99
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(jarNames, ", ");
100             String JavaDoc[] depoyments = new String JavaDoc[st.countTokens()];
101             for (int i = depoyments.length - 1; i >= 0; i--)
102                depoyments[i] = st.nextToken();
103             for (int i = 0; i < depoyments.length; i++)
104             {
105                String JavaDoc jarName = depoyments[i];
106                this.undeploy(jarName);
107                this.getLog().debug("undeployed package: " + jarName);
108             }
109
110             if (this.getDelegate().isSecureTest())
111                this.delegate.logout();
112          }
113       };
114       return wrapper;
115    }
116
117    public static Test getDeploySetup(final Class JavaDoc clazz, final String JavaDoc jarName)
118       throws Exception JavaDoc
119    {
120       TestSuite suite = new TestSuite();
121       suite.addTest(new TestSuite(clazz));
122       return getDeploySetup(suite, jarName);
123    }
124 }
125
Popular Tags