KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > WebserviceTestBase


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.webservice;
23
24 import java.util.Hashtable JavaDoc;
25
26 import javax.naming.InitialContext JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28 import javax.xml.rpc.ServiceException JavaDoc;
29 import javax.xml.rpc.ServiceFactory JavaDoc;
30
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33
34 import org.jboss.test.JBossTestCase;
35
36 /** Common functionality for web services test cases.
37  *
38  * @author Thomas.Diesler@jboss.org
39  * @version $Revision: 43667 $
40  */

41 public class WebserviceTestBase extends JBossTestCase
42 {
43
44    public WebserviceTestBase(String JavaDoc name)
45    {
46       super(name);
47    }
48
49    /**
50     * Get the client's env context, see tracker [840598] for details
51     */

52    protected InitialContext JavaDoc getClientContext(String JavaDoc clientName) throws NamingException JavaDoc
53    {
54       InitialContext JavaDoc initialContext = new InitialContext JavaDoc();
55       Hashtable JavaDoc jndiEnv = initialContext.getEnvironment();
56       jndiEnv.put("java.naming.factory.url.pkgs", "org.jboss.naming.client");
57       jndiEnv.put("j2ee.clientName", clientName);
58       log.debug("jndiEnv: " + jndiEnv);
59       return new InitialContext JavaDoc(jndiEnv);
60    }
61
62    /**
63     * Get the client's env context, see tracker [840598] for details
64     */

65    protected InitialContext JavaDoc getClientContext() throws NamingException JavaDoc
66    {
67       return getClientContext("ws4ee-client");
68    }
69
70    /** Return true if the Axis based stack is available
71     */

72    public static boolean isWS4EEAvailable()
73    {
74       try
75       {
76          ServiceFactory JavaDoc factory = ServiceFactory.newInstance();
77          if ("org.jboss.webservice.client.ServiceFactoryImpl".equals(factory.getClass().getName()))
78             return true;
79       }
80       catch (ServiceException JavaDoc e)
81       {
82          // ignore
83
}
84       return false;
85    }
86
87    /** Return true if the JBossWS stack is available
88     */

89    public static boolean isJBossWSAvailable()
90    {
91       try
92       {
93          ServiceFactory JavaDoc factory = ServiceFactory.newInstance();
94          if ("org.jboss.ws.jaxrpc.ServiceFactoryImpl".equals(factory.getClass().getName()))
95             return true;
96       }
97       catch (ServiceException JavaDoc e)
98       {
99          // ignore
100
}
101       return false;
102    }
103
104    public static Test getDeploySetupForWS4EE(final Class JavaDoc clazz, String JavaDoc jarName) throws Exception JavaDoc
105    {
106       TestSuite suite = new TestSuite();
107       suite.addTest(new TestSuite(clazz));
108       if (isWS4EEAvailable() == false)
109       {
110          jarName = null;
111       }
112       return getDeploySetup(suite, jarName);
113    }
114
115    public static Test getDeploySetupForJBossWS(final Class JavaDoc clazz, String JavaDoc jarName) throws Exception JavaDoc
116    {
117       TestSuite suite = new TestSuite();
118       suite.addTest(new TestSuite(clazz));
119       if (isJBossWSAvailable() == false)
120       {
121          jarName = null;
122       }
123       return getDeploySetup(suite, jarName);
124    }
125 }
126
Popular Tags