001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.webservice;
023:
024: import java.util.Hashtable;
025:
026: import javax.naming.InitialContext;
027: import javax.naming.NamingException;
028: import javax.xml.rpc.ServiceException;
029: import javax.xml.rpc.ServiceFactory;
030:
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033:
034: import org.jboss.test.JBossTestCase;
035:
036: /** Common functionality for web services test cases.
037: *
038: * @author Thomas.Diesler@jboss.org
039: * @version $Revision: 59464 $
040: */
041: public class WebserviceTestBase extends JBossTestCase {
042:
043: public WebserviceTestBase(String name) {
044: super (name);
045: }
046:
047: /**
048: * Get the client's env context, see tracker [840598] for details
049: */
050: protected InitialContext getClientContext(String clientName)
051: throws NamingException {
052: InitialContext initialContext = new InitialContext();
053: Hashtable jndiEnv = initialContext.getEnvironment();
054: jndiEnv.put("java.naming.factory.url.pkgs",
055: "org.jboss.naming.client");
056: jndiEnv.put("j2ee.clientName", clientName);
057: log.debug("jndiEnv: " + jndiEnv);
058: return new InitialContext(jndiEnv);
059: }
060:
061: /**
062: * Get the client's env context, see tracker [840598] for details
063: */
064: protected InitialContext getClientContext() throws NamingException {
065: return getClientContext("ws4ee-client");
066: }
067:
068: /** Return true if the Axis based stack is available
069: */
070: public static boolean isWS4EEAvailable() {
071: try {
072: ServiceFactory factory = ServiceFactory.newInstance();
073: if ("org.jboss.webservice.client.ServiceFactoryImpl"
074: .equals(factory.getClass().getName()))
075: return true;
076: } catch (ServiceException e) {
077: // ignore
078: }
079: return false;
080: }
081:
082: /** Return true if the JBossWS stack is available
083: */
084: public static boolean isJBossWSAvailable() {
085: try {
086: ServiceFactory factory = ServiceFactory.newInstance();
087: if ("org.jboss.ws.core.jaxrpc.ServiceFactoryImpl"
088: .equals(factory.getClass().getName()))
089: return true;
090: } catch (ServiceException e) {
091: // ignore
092: }
093: return false;
094: }
095:
096: public static Test getDeploySetupForWS4EE(final Class clazz,
097: String jarName) throws Exception {
098: TestSuite suite = new TestSuite();
099: suite.addTest(new TestSuite(clazz));
100: if (isWS4EEAvailable() == false) {
101: jarName = null;
102: }
103: return getDeploySetup(suite, jarName);
104: }
105:
106: public static Test getDeploySetupForJBossWS(final Class clazz,
107: String jarName) throws Exception {
108: TestSuite suite = new TestSuite();
109: suite.addTest(new TestSuite(clazz));
110: if (isJBossWSAvailable() == false) {
111: jarName = null;
112: }
113: return getDeploySetup(suite, jarName);
114: }
115: }
|