[jbossws-commits] JBossWS SVN: r14324 - in shared-testsuite/trunk: src and 7 other directories.
jbossws-commits at lists.jboss.org
jbossws-commits at lists.jboss.org
Mon May 9 07:24:42 EDT 2011
Author: richard.opalka at jboss.com
Date: 2011-05-09 07:24:41 -0400 (Mon, 09 May 2011)
New Revision: 14324
Added:
shared-testsuite/trunk/src/
shared-testsuite/trunk/src/main/
shared-testsuite/trunk/src/main/java/
shared-testsuite/trunk/src/main/java/org/
shared-testsuite/trunk/src/main/java/org/jboss/
shared-testsuite/trunk/src/main/java/org/jboss/wsf/
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/DeployerJBoss6.java
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTest.java
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestSetup.java
shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/XOPTestSupport.java
shared-testsuite/trunk/src/main/java/pom.xml
Modified:
shared-testsuite/trunk/pom.xml
shared-testsuite/trunk/testsuite/src/test/scripts/assembly-testsuite.xml
Log:
[JBWS-3289] refactoring test support classes to shared-testsuite SVN module
Modified: shared-testsuite/trunk/pom.xml
===================================================================
--- shared-testsuite/trunk/pom.xml 2011-05-09 11:22:03 UTC (rev 14323)
+++ shared-testsuite/trunk/pom.xml 2011-05-09 11:24:41 UTC (rev 14324)
@@ -4,7 +4,6 @@
<name>JBoss Web Services - Stack Agnostic Test Suite</name>
<groupId>org.jboss.ws</groupId>
<artifactId>jbossws-shared-testsuite</artifactId>
- <packaging>pom</packaging>
<description>JBossWS Stack Agnostic Testsuite</description>
<version>4.0.0-SNAPSHOT</version>
@@ -23,7 +22,33 @@
<url>http://fisheye.jboss.com/viewrep/JBossWS/shared-testsuite/trunk</url>
</scm>
- <!-- Plugins -->
+ <properties>
+ <jbossws.common.version>2.0.0-SNAPSHOT</jbossws.common.version>
+ <jboss.logging.version>2.0.5.GA</jboss.logging.version>
+ <junit.version>3.8.2</junit.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.ws</groupId>
+ <artifactId>jbossws-common</artifactId>
+ <version>${jbossws.common.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ <version>${jboss.logging.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
<build>
<plugins>
<plugin>
@@ -36,7 +61,7 @@
</goals>
<configuration>
<descriptors>
- <descriptor>src/test/scripts/assembly-testsuite.xml</descriptor>
+ <descriptor>testsuite/src/test/scripts/assembly-testsuite.xml</descriptor>
</descriptors>
</configuration>
</execution>
Added: shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/DeployerJBoss6.java
===================================================================
--- shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/DeployerJBoss6.java (rev 0)
+++ shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/DeployerJBoss6.java 2011-05-09 11:24:41 UTC (rev 14324)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.wsf.test;
+
+import java.net.URL;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import org.jboss.wsf.spi.deployer.Deployer;
+
+/**
+ * A JBossWS test helper that deals with test deployment/undeployment, etc.
+ *
+ * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
+ */
+public final class DeployerJBoss6 implements Deployer
+{
+
+ private static final String MAIN_DEPLOYER = "jboss.system:service=MainDeployer";
+
+ private MBeanServerConnection server;
+
+ public DeployerJBoss6()
+ {
+ this.server = JBossWSTestHelper.getServer();
+ }
+
+ public void deploy(final URL url) throws Exception
+ {
+ invokeMainDeployer("deploy", url);
+ }
+
+ public void undeploy(final URL url) throws Exception
+ {
+ invokeMainDeployer("undeploy", url);
+ }
+
+ private void invokeMainDeployer(final String methodName, final URL url) throws Exception
+ {
+ server.invoke(new ObjectName(MAIN_DEPLOYER), methodName, new Object[]
+ {url}, new String[]
+ {"java.net.URL"});
+ }
+
+}
Added: shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTest.java
===================================================================
--- shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTest.java (rev 0)
+++ shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTest.java 2011-05-09 11:24:41 UTC (rev 14324)
@@ -0,0 +1,461 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.management.MBeanServerConnection;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.common.DOMWriter;
+import org.jboss.ws.common.concurrent.CopyJob;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Base class for JBossWS test cases.
+ *
+ * @author <a href="mailto:tdiesler at redhat.com">Thomas Diesler</a>
+ * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
+ */
+public abstract class JBossWSTest extends TestCase
+{
+ protected static Logger log = Logger.getLogger(JBossWSTest.class.getName());
+ //private static JBossWSTestHelper delegate = new JBossWSTestHelper();
+
+ public JBossWSTest()
+ {
+ }
+
+ public JBossWSTest(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Execute <b>command</b> in separate process.
+ * @param command command to execute
+ * @throws IOException if I/O error occurs
+ */
+ public static void executeCommand(String command) throws IOException
+ {
+ executeCommand(command, null, null, null);
+ }
+
+ /**
+ * Execute <b>command</b> in separate process. If process will fail, display custom <b>message</b> in assertion.
+ * @param command command to execute
+ * @param message message to display if assertion fails
+ * @throws IOException if I/O error occurs
+ */
+ public static void executeCommand(String command, String message) throws IOException
+ {
+ executeCommand(command, null, message, null);
+ }
+
+ /**
+ * Execute <b>command</b> in separate process, copy process input to <b>os</b>.
+ * @param command command to execute
+ * @param os output stream to copy process input to. If null, <b>System.out</b> will be used
+ * @throws IOException if I/O error occurs
+ */
+ public static void executeCommand(String command, OutputStream os) throws IOException
+ {
+ executeCommand(command, os, null, null);
+ }
+
+ /**
+ * Execute <b>command</b> in separate process, copy process input to <b>os</b>. If process will fail, display custom <b>message</b> in assertion.
+ * @param command command to execute
+ * @param os output stream to copy process input to. If null, <b>System.out</b> will be used
+ * @param message message to display if assertion fails
+ * @throws IOException if I/O error occurs
+ */
+ public static void executeCommand(String command, OutputStream os, String message) throws IOException
+ {
+ executeCommand(command, os, message, null);
+ }
+
+ /**
+ * Execute <b>command</b> in separate process, copy process input to <b>os</b>. If process will fail, display custom <b>message</b> in assertion.
+ * @param command command to execute
+ * @param os output stream to copy process input to. If null, <b>System.out</b> will be used
+ * @param message message to display if assertion fails
+ * @param env environment
+ * @throws IOException if I/O error occurs
+ */
+ public static void executeCommand(String command, OutputStream os, String message, Map<String, String> env) throws IOException
+ {
+ if (command == null)
+ throw new NullPointerException( "Command cannot be null" );
+
+ System.out.println("Executing command: " + command);
+ log.debug("Executing command: " + command);
+
+ StringTokenizer st = new StringTokenizer(command, " \t\r");
+ List<String> tokenizedCommand = new LinkedList<String>();
+ while (st.hasMoreTokens())
+ {
+ // PRECONDITION: command doesn't contain whitespaces in the paths
+ tokenizedCommand.add(st.nextToken());
+ }
+
+ try
+ {
+ executeCommand(tokenizedCommand, os, message, env);
+ }
+ catch (IOException e)
+ {
+ log.warn("Make sure there are no whitespaces in command paths", e);
+ throw e;
+ }
+ }
+
+ /**
+ * Execute <b>command</b> in separate process, copy process input to <b>os</b>. If process will fail, display custom <b>message</b> in assertion.
+ * @param command command to execute
+ * @param os output stream to copy process input to. If null, <b>System.out</b> will be used
+ * @param message message to display if assertion fails
+ * @param env environment
+ * @throws IOException if I/O error occurs
+ */
+ private static void executeCommand(List<String> command, OutputStream os, String message, Map<String, String> env) throws IOException
+ {
+ ProcessBuilder pb = new ProcessBuilder(command);
+ if (env != null)
+ {
+ for (String variable : env.keySet())
+ {
+ pb.environment().put(variable, env.get(variable));
+ }
+ }
+ Process p = pb.start();
+ CopyJob inputStreamJob = new CopyJob(p.getInputStream(), os == null ? System.out : os);
+ CopyJob errorStreamJob = new CopyJob(p.getErrorStream(), System.err);
+ // unfortunately the following threads are needed because of Windows behavior
+ System.out.println("Process input stream:");
+ System.err.println("Process error stream:");
+ Thread inputJob = new Thread(inputStreamJob);
+ Thread outputJob = new Thread(errorStreamJob);
+ try
+ {
+ inputJob.start();
+ inputJob.join(5000);
+ outputJob.start();
+ outputJob.join(5000);
+ int statusCode = p.waitFor();
+ String fallbackMessage = "Process did exit with status " + statusCode;
+ assertTrue(message != null ? message : fallbackMessage, statusCode == 0);
+ }
+ catch (InterruptedException ie)
+ {
+ ie.printStackTrace(System.err);
+ }
+ finally
+ {
+ inputStreamJob.kill();
+ errorStreamJob.kill();
+ p.destroy();
+ }
+ }
+
+ public static MBeanServerConnection getServer() throws NamingException
+ {
+ return JBossWSTestHelper.getServer();
+ }
+
+ public static boolean isTargetJBoss5()
+ {
+ return JBossWSTestHelper.isTargetJBoss5();
+ }
+
+ public static boolean isTargetJBoss51()
+ {
+ return JBossWSTestHelper.isTargetJBoss51();
+ }
+
+ public static boolean isTargetJBoss50()
+ {
+ return JBossWSTestHelper.isTargetJBoss50();
+ }
+
+ public static boolean isTargetJBoss6()
+ {
+ return JBossWSTestHelper.isTargetJBoss6();
+ }
+
+ public static boolean isTargetJBoss61()
+ {
+ return JBossWSTestHelper.isTargetJBoss61();
+ }
+
+ public static boolean isTargetJBoss60()
+ {
+ return JBossWSTestHelper.isTargetJBoss60();
+ }
+
+ public static boolean isIntegrationNative()
+ {
+ return JBossWSTestHelper.isIntegrationNative();
+ }
+
+ public static boolean isIntegrationMetro()
+ {
+ return JBossWSTestHelper.isIntegrationMetro();
+ }
+
+ public static boolean isIntegrationCXF()
+ {
+ return JBossWSTestHelper.isIntegrationCXF();
+ }
+
+ /** Deploy the given archive
+ */
+ public static void deploy(String archive) throws Exception
+ {
+ JBossWSTestHelper.deploy(archive);
+ }
+
+ /** Undeploy the given archive
+ */
+ public static void undeploy(String archive) throws Exception
+ {
+ JBossWSTestHelper.undeploy(archive);
+ }
+
+ public static String getServerHost()
+ {
+ return JBossWSTestHelper.getServerHost();
+ }
+
+ public static File getArchiveFile(String archive)
+ {
+ return JBossWSTestHelper.getArchiveFile(archive);
+ }
+
+ public static URL getArchiveURL(String archive) throws MalformedURLException
+ {
+ return JBossWSTestHelper.getArchiveURL(archive);
+ }
+
+ public static File getResourceFile(String resource)
+ {
+ return JBossWSTestHelper.getResourceFile(resource);
+ }
+
+ public static URL getResourceURL(String resource) throws MalformedURLException
+ {
+ return JBossWSTestHelper.getResourceURL(resource);
+ }
+
+ public static File createResourceFile(String filename)
+ {
+ File resDir = new File(JBossWSTestHelper.getTestResourcesDir());
+ return new File(resDir.getAbsolutePath() + File.separator + filename);
+ }
+
+ public static File createResourceFile(File parent, String filename)
+ {
+ return new File(parent, filename);
+ }
+
+ /** Get the client's env context for a given name.
+ */
+ @SuppressWarnings("unchecked")
+ protected static InitialContext getInitialContext(String clientName) throws NamingException
+ {
+ InitialContext iniCtx = new InitialContext();
+ Hashtable env = iniCtx.getEnvironment();
+ env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
+ env.put("j2ee.clientName", clientName);
+ return new InitialContext(env);
+ }
+
+ /** Get the client's env context
+ */
+ protected static InitialContext getInitialContext() throws NamingException
+ {
+ return getInitialContext("jbossws-client");
+ }
+
+ public static void assertEquals(Element expElement, Element wasElement, boolean ignoreWhitespace)
+ {
+ normalizeWhitespace(expElement, ignoreWhitespace);
+ normalizeWhitespace(wasElement, ignoreWhitespace);
+ String expStr = DOMWriter.printNode(expElement, false);
+ String wasStr = DOMWriter.printNode(wasElement, false);
+ if (expStr.equals(wasStr) == false)
+ {
+ System.out.println("\nExp: " + expStr + "\nWas: " + wasStr);
+ }
+ assertEquals(expStr, wasStr);
+ }
+
+ public static void assertEquals(Element expElement, Element wasElement)
+ {
+ assertEquals(expElement, wasElement, false);
+ }
+
+ public static void assertEquals(Object exp, Object was)
+ {
+ if (exp instanceof Object[] && was instanceof Object[])
+ assertEqualsArray((Object[])exp, (Object[])was);
+ else if (exp instanceof byte[] && was instanceof byte[])
+ assertEqualsArray((byte[])exp, (byte[])was);
+ else if (exp instanceof boolean[] && was instanceof boolean[])
+ assertEqualsArray((boolean[])exp, (boolean[])was);
+ else if (exp instanceof short[] && was instanceof short[])
+ assertEqualsArray((short[])exp, (short[])was);
+ else if (exp instanceof int[] && was instanceof int[])
+ assertEqualsArray((int[])exp, (int[])was);
+ else if (exp instanceof long[] && was instanceof long[])
+ assertEqualsArray((long[])exp, (long[])was);
+ else if (exp instanceof float[] && was instanceof float[])
+ assertEqualsArray((float[])exp, (float[])was);
+ else if (exp instanceof double[] && was instanceof double[])
+ assertEqualsArray((double[])exp, (double[])was);
+ else
+ TestCase.assertEquals(exp, was);
+ }
+
+ private static void assertEqualsArray(Object[] exp, Object[] was)
+ {
+ if (exp == null && was == null)
+ return;
+
+ if (exp != null && was != null)
+ {
+ if (exp.length != was.length)
+ {
+ fail("Expected <" + exp.length + "> array items, but was <" + was.length + ">");
+ }
+ else
+ {
+ for (int i = 0; i < exp.length; i++)
+ {
+
+ Object compExp = exp[i];
+ Object compWas = was[i];
+ assertEquals(compExp, compWas);
+ }
+ }
+ }
+ else if (exp == null)
+ {
+ fail("Expected a null array, but was: " + Arrays.asList(was));
+ }
+ else if (was == null)
+ {
+ fail("Expected " + Arrays.asList(exp) + ", but was: null");
+ }
+ }
+
+ private static void assertEqualsArray(byte[] exp, byte[] was)
+ {
+ assertTrue("Arrays don't match", Arrays.equals(exp, was));
+ }
+
+ private static void assertEqualsArray(boolean[] exp, boolean[] was)
+ {
+ assertTrue("Arrays don't match", Arrays.equals(exp, was));
+ }
+
+ private static void assertEqualsArray(short[] exp, short[] was)
+ {
+ assertTrue("Arrays don't match", Arrays.equals(exp, was));
+ }
+
+ private static void assertEqualsArray(int[] exp, int[] was)
+ {
+ assertTrue("Arrays don't match", Arrays.equals(exp, was));
+ }
+
+ private static void assertEqualsArray(long[] exp, long[] was)
+ {
+ assertTrue("Arrays don't match", Arrays.equals(exp, was));
+ }
+
+ private static void assertEqualsArray(float[] exp, float[] was)
+ {
+ assertTrue("Arrays don't match", Arrays.equals(exp, was));
+ }
+
+ private static void assertEqualsArray(double[] exp, double[] was)
+ {
+ assertTrue("Arrays don't match", Arrays.equals(exp, was));
+ }
+
+ /** Removes whitespace text nodes if they have an element sibling.
+ */
+ private static void normalizeWhitespace(Element element, boolean ignoreWhitespace)
+ {
+ boolean hasChildElement = false;
+ ArrayList<Node> toDetach = new ArrayList<Node>();
+
+ NodeList childNodes = element.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++)
+ {
+ Node node = childNodes.item(i);
+ if (node.getNodeType() == Node.TEXT_NODE)
+ {
+ String nodeValue = node.getNodeValue();
+ if (nodeValue.trim().length() == 0)
+ toDetach.add(node);
+ }
+ if (node.getNodeType() == Node.ELEMENT_NODE)
+ {
+ normalizeWhitespace((Element)node, ignoreWhitespace);
+ hasChildElement = true;
+ }
+ }
+
+ // remove whitespace nodes
+ if (hasChildElement || ignoreWhitespace)
+ {
+ Iterator<Node> it = toDetach.iterator();
+ while (it.hasNext())
+ {
+ Node whiteSpaceNode = it.next();
+ element.removeChild(whiteSpaceNode);
+ }
+ }
+ }
+
+}
Added: shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java
===================================================================
--- shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java (rev 0)
+++ shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java 2011-05-09 11:24:41 UTC (rev 14324)
@@ -0,0 +1,365 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.Hashtable;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.ws.Service;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.soap.SOAPBinding;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.common.ObjectNameFactory;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.deployer.Deployer;
+
+/**
+ * A JBossWS test helper that deals with test deployment/undeployment, etc.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @author ropalka at redhat.com
+ */
+public class JBossWSTestHelper
+{
+ private static final Logger LOGGER = Logger.getLogger(JBossWSTestHelper.class);
+
+ private static final String SYSPROP_JBOSSWS_INTEGRATION_TARGET = "jbossws.integration.target";
+ private static final String SYSPROP_JBOSS_BIND_ADDRESS = "jboss.bind.address";
+ private static final String SYSPROP_TEST_ARCHIVE_DIRECTORY = "test.archive.directory";
+ private static final String SYSPROP_TEST_RESOURCES_DIRECTORY = "test.resources.directory";
+ private static final boolean DEPLOY_PROCESS_ENABLED = !Boolean.getBoolean("test.disable.deployment");
+ private static final Deployer DEPLOYER;
+
+ private static MBeanServerConnection server;
+ private static String integrationTarget;
+ private static String implVendor;
+ private static String implTitle;
+ private static String implVersion;
+ private static String testArchiveDir;
+ private static String testResourcesDir;
+
+ static
+ {
+ SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ DEPLOYER = spiProvider.getSPI(Deployer.class);
+ }
+
+ /** Deploy the given archive
+ */
+ public static void deploy(String archive) throws Exception
+ {
+ if ( DEPLOY_PROCESS_ENABLED )
+ {
+ URL archiveURL = getArchiveFile(archive).toURI().toURL();
+ DEPLOYER.deploy(archiveURL);
+ }
+ }
+
+ /** Undeploy the given archive
+ */
+ public static void undeploy(String archive) throws Exception
+ {
+ if ( DEPLOY_PROCESS_ENABLED )
+ {
+ URL archiveURL = getArchiveFile(archive).toURI().toURL();
+ DEPLOYER.undeploy(archiveURL);
+ }
+ }
+
+ /** True, if -Djbossws.integration.target=jboss5x */
+ public static boolean isTargetJBoss5()
+ {
+ return isTargetJBoss51() || isTargetJBoss50();
+ }
+
+ /** True, if -Djbossws.integration.target=jboss50x */
+ public static boolean isTargetJBoss50()
+ {
+ String target = getIntegrationTarget();
+ return target.startsWith("jboss50");
+ }
+
+ /** True, if -Djbossws.integration.target=jboss51x */
+ public static boolean isTargetJBoss51()
+ {
+ String target = getIntegrationTarget();
+ return target.startsWith("jboss51");
+ }
+
+ /** True, if -Djbossws.integration.target=jboss6x */
+ public static boolean isTargetJBoss6()
+ {
+ return isTargetJBoss61() || isTargetJBoss60();
+ }
+
+ /** True, if -Djbossws.integration.target=jboss60x */
+ public static boolean isTargetJBoss60()
+ {
+ String target = getIntegrationTarget();
+ return target.startsWith("jboss60");
+ }
+
+ /** True, if -Djbossws.integration.target=jboss61x */
+ public static boolean isTargetJBoss61()
+ {
+ String target = getIntegrationTarget();
+ return target.startsWith("jboss61");
+ }
+
+ public static boolean isIntegrationNative()
+ {
+ String vendor = getImplementationVendor();
+ return vendor.toLowerCase().indexOf("jboss") != -1;
+ }
+
+ public static boolean isIntegrationMetro()
+ {
+ String vendor = getImplementationVendor();
+ return vendor.toLowerCase().indexOf("sun") != -1;
+ }
+
+ public static boolean isIntegrationCXF()
+ {
+ String vendor = getImplementationVendor();
+ return vendor.toLowerCase().indexOf("apache") != -1;
+ }
+
+ private static String getImplementationVendor()
+ {
+ if (implVendor == null)
+ {
+ Object obj = getImplementationObject();
+ implVendor = obj.getClass().getPackage().getImplementationVendor();
+ if (implVendor == null)
+ implVendor = getImplementationPackage();
+
+ implTitle = obj.getClass().getPackage().getImplementationTitle();
+ implVersion = obj.getClass().getPackage().getImplementationVersion();
+
+ System.out.println(implVendor + ", " + implTitle + ", " + implVersion);
+ }
+ return implVendor;
+ }
+
+ private static Object getImplementationObject()
+ {
+ Service service = Service.create(new QName("dummyService"));
+ Object obj = service.getHandlerResolver();
+ if (obj == null)
+ {
+ service.addPort(new QName("dummyPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://dummy-address");
+ obj = service.createDispatch(new QName("dummyPort"), Source.class, Mode.PAYLOAD);
+ }
+ return obj;
+ }
+
+ private static String getImplementationPackage()
+ {
+ return getImplementationObject().getClass().getPackage().getName();
+ }
+
+ /**
+ * Get the JBoss server host from system property "jboss.bind.address"
+ * This defaults to "localhost"
+ */
+ public static String getServerHost()
+ {
+ final String host = System.getProperty(SYSPROP_JBOSS_BIND_ADDRESS, "localhost");
+ return toIPv6URLFormat(host);
+ }
+
+ private static String toIPv6URLFormat(final String host)
+ {
+ try
+ {
+ final boolean isIPv6Address = InetAddress.getByName(host) instanceof Inet6Address;
+ final boolean isIPv6Formatted = isIPv6Address && host.startsWith("[");
+ return isIPv6Address && !isIPv6Formatted ? "[" + host + "]" : host;
+ }
+ catch (final UnknownHostException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static MBeanServerConnection getServer()
+ {
+ if (server == null)
+ {
+ if (getIntegrationTarget().startsWith("jboss7"))
+ {
+ server = getAS7ServerConnection();
+ }
+ else
+ {
+ server = getAS6ServerConnection();
+ }
+ }
+ return server;
+ }
+
+ private static MBeanServerConnection getAS7ServerConnection()
+ {
+ String host = getServerHost();
+ String urlString = System.getProperty("jmx.service.url", "service:jmx:rmi:///jndi/rmi://" + host + ":" + 1090 + "/jmxrmi");
+ try {
+ JMXServiceURL serviceURL = new JMXServiceURL(urlString);
+ return JMXConnectorFactory.connect(serviceURL, null).getMBeanServerConnection();
+ } catch (IOException ex) {
+ throw new IllegalStateException("Cannot obtain MBeanServerConnection to: " + urlString, ex);
+ }
+ }
+
+ private static MBeanServerConnection getAS6ServerConnection()
+ {
+ Hashtable jndiEnv = null;
+ try
+ {
+ InitialContext iniCtx = new InitialContext();
+ jndiEnv = iniCtx.getEnvironment();
+ return (MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
+ }
+ catch (NamingException ex)
+ {
+ throw new RuntimeException("Cannot obtain MBeanServerConnection using jndi props: " + jndiEnv, ex);
+ }
+ }
+
+ public static String getIntegrationTarget()
+ {
+ if (integrationTarget == null)
+ {
+ integrationTarget = System.getProperty(SYSPROP_JBOSSWS_INTEGRATION_TARGET);
+
+ if (integrationTarget == null)
+ throw new IllegalStateException("Cannot obtain system property: " + SYSPROP_JBOSSWS_INTEGRATION_TARGET);
+
+ LOGGER.fatal("TODO: remove this ugly hack");
+ if (!integrationTarget.startsWith("jboss7"))
+ {
+ // Read the JBoss SpecificationVersion
+ String jbossVersion = null;
+ try
+ {
+ ObjectName oname = ObjectNameFactory.create("jboss.system:type=Server");
+ jbossVersion = (String)getServer().getAttribute(oname, "VersionNumber");
+ if (jbossVersion == null)
+ throw new IllegalStateException("Cannot obtain jboss version");
+
+ if (jbossVersion.startsWith("5.1"))
+ jbossVersion = "jboss51";
+ else if (jbossVersion.startsWith("5.0"))
+ jbossVersion = "jboss50";
+ else if (jbossVersion.startsWith("6.1"))
+ jbossVersion = "jboss61";
+ else if (jbossVersion.startsWith("6.0"))
+ jbossVersion = "jboss60";
+ else throw new IllegalStateException("Unsupported jboss version: " + jbossVersion);
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+
+ if (integrationTarget.startsWith(jbossVersion) == false)
+ throw new IllegalStateException("Integration target mismatch: " + integrationTarget + ".startsWith(" + jbossVersion + ")");
+ }
+ }
+
+ return integrationTarget;
+ }
+
+ /** Try to discover the URL for the deployment archive */
+ public static URL getArchiveURL(String archive) throws MalformedURLException
+ {
+ return getArchiveFile(archive).toURI().toURL();
+ }
+
+ /** Try to discover the File for the deployment archive */
+ public static File getArchiveFile(String archive)
+ {
+ File file = new File(archive);
+ if (file.exists())
+ return file;
+
+ file = new File(getTestArchiveDir() + "/" + archive);
+ if (file.exists())
+ return file;
+
+ String notSet = (getTestArchiveDir() == null ? " System property '" + SYSPROP_TEST_ARCHIVE_DIRECTORY + "' not set." : "");
+ throw new IllegalArgumentException("Cannot obtain '" + getTestArchiveDir() + "/" + archive + "'." + notSet);
+ }
+
+ /** Try to discover the URL for the test resource */
+ public static URL getResourceURL(String resource) throws MalformedURLException
+ {
+ return getResourceFile(resource).toURI().toURL();
+ }
+
+ /** Try to discover the File for the test resource */
+ public static File getResourceFile(String resource)
+ {
+ File file = new File(resource);
+ if (file.exists())
+ return file;
+
+ file = new File(getTestResourcesDir() + "/" + resource);
+ if (file.exists())
+ return file;
+
+ String notSet = (getTestResourcesDir() == null ? " System property '" + SYSPROP_TEST_RESOURCES_DIRECTORY + "' not set." : "");
+ throw new IllegalArgumentException("Cannot obtain '" + getTestResourcesDir() + "/" + resource + "'." + notSet);
+ }
+
+ public static String getTestArchiveDir()
+ {
+ if (testArchiveDir == null)
+ testArchiveDir = System.getProperty(SYSPROP_TEST_ARCHIVE_DIRECTORY);
+
+ return testArchiveDir;
+ }
+
+ public static String getTestResourcesDir()
+ {
+ if (testResourcesDir == null)
+ testResourcesDir = System.getProperty(SYSPROP_TEST_RESOURCES_DIRECTORY);
+
+ return testResourcesDir;
+ }
+}
Added: shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestSetup.java
===================================================================
--- shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestSetup.java (rev 0)
+++ shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/JBossWSTestSetup.java 2011-05-09 11:24:41 UTC (rev 14324)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.test;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.management.MBeanServerConnection;
+import javax.naming.NamingException;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A test setup that deploys/undeploys archives
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 14-Oct-2004
+ */
+public class JBossWSTestSetup extends TestSetup
+{
+ // provide logging
+ private static Logger log = Logger.getLogger(JBossWSTestSetup.class);
+
+ private JBossWSTestHelper delegate = new JBossWSTestHelper();
+ private String[] archives = new String[0];
+ private ClassLoader originalClassLoader;
+
+ public JBossWSTestSetup(Class<?> testClass, String archiveList)
+ {
+ super(new TestSuite(testClass));
+ getArchiveArray(archiveList);
+ }
+
+ public JBossWSTestSetup(Test test, String archiveList)
+ {
+ super(test);
+ getArchiveArray(archiveList);
+ }
+
+ public JBossWSTestSetup(Test test)
+ {
+ super(test);
+ }
+
+ public File getArchiveFile(String archive)
+ {
+ return delegate.getArchiveFile(archive);
+ }
+
+ public URL getArchiveURL(String archive) throws MalformedURLException
+ {
+ return delegate.getArchiveFile(archive).toURI().toURL();
+ }
+
+ public File getResourceFile(String resource)
+ {
+ return delegate.getResourceFile(resource);
+ }
+
+ public URL getResourceURL(String resource) throws MalformedURLException
+ {
+ return delegate.getResourceFile(resource).toURI().toURL();
+ }
+
+ private void getArchiveArray(String archiveList)
+ {
+ if (archiveList != null)
+ {
+ StringTokenizer st = new StringTokenizer(archiveList, ", ");
+ archives = new String[st.countTokens()];
+
+ for (int i = 0; i < archives.length; i++)
+ archives[i] = st.nextToken();
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ // verify integration target
+ String integrationTarget = delegate.getIntegrationTarget();
+ log.debug("Integration target: " + integrationTarget);
+
+ List<URL> clientJars = new ArrayList<URL>();
+ for (int i = 0; i < archives.length; i++)
+ {
+ String archive = archives[i];
+ try
+ {
+ delegate.deploy(archive);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ delegate.undeploy(archive);
+ }
+
+ if (archive.endsWith("-client.jar"))
+ {
+ URL archiveURL = getArchiveURL(archive);
+ clientJars.add(archiveURL);
+ }
+ }
+
+ ClassLoader parent = Thread.currentThread().getContextClassLoader();
+ originalClassLoader = parent;
+ // add client jars to the class loader
+ if (!clientJars.isEmpty())
+ {
+ URL[] urls = new URL[clientJars.size()];
+ for (int i = 0; i < clientJars.size(); i++)
+ {
+ urls[i] = clientJars.get(i);
+ }
+ URLClassLoader cl = new URLClassLoader(urls, parent);
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+ }
+
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ for (int i = 0; i < archives.length; i++)
+ {
+ String archive = archives[archives.length - i - 1];
+ delegate.undeploy(archive);
+ }
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ }
+
+ public MBeanServerConnection getServer() throws NamingException
+ {
+ return JBossWSTestHelper.getServer();
+ }
+}
Added: shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/XOPTestSupport.java
===================================================================
--- shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/XOPTestSupport.java (rev 0)
+++ shared-testsuite/trunk/src/main/java/org/jboss/wsf/test/XOPTestSupport.java 2011-05-09 11:24:41 UTC (rev 14324)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.test;
+
+import java.awt.Image;
+import java.awt.Toolkit;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.activation.DataHandler;
+import javax.xml.transform.stream.StreamSource;
+
+import org.jboss.ws.common.IOUtils;
+
+/**
+ * @author Heiko Braun <heiko.braun at jboss.com>
+ * @since 22-Sep-2006
+ */
+public class XOPTestSupport
+{
+
+ public static byte[] getBytesFromFile(File file) throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ IOUtils.copyStream(baos, new FileInputStream(file));
+ return baos.toByteArray();
+ }
+
+ public static Image createTestImage(File imgFile)
+ {
+ Image image = null;
+ try
+ {
+ URL url = imgFile.toURI().toURL();
+
+ image = null;
+ try
+ {
+ image = Toolkit.getDefaultToolkit().createImage(url);
+ }
+ catch (Throwable th)
+ {
+ //log.warn("Cannot create Image: " + th);
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ return image;
+ }
+
+ public static StreamSource createTestSource()
+ {
+ return new StreamSource(new ByteArrayInputStream("<some><nestedXml/></some>".getBytes()));
+ }
+
+ public static DataHandler createDataHandler(File imgFile)
+ {
+ try
+ {
+ URL url = imgFile.toURI().toURL();
+ return new DataHandler(url);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: shared-testsuite/trunk/src/main/java/pom.xml
===================================================================
--- shared-testsuite/trunk/src/main/java/pom.xml (rev 0)
+++ shared-testsuite/trunk/src/main/java/pom.xml 2011-05-09 11:24:41 UTC (rev 14324)
@@ -0,0 +1,86 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <name>JBoss Web Services - Stack Agnostic Test Suite</name>
+ <groupId>org.jboss.ws</groupId>
+ <artifactId>jbossws-shared-testsuite</artifactId>
+ <description>JBossWS Stack Agnostic Testsuite</description>
+
+ <version>4.0.0-SNAPSHOT</version>
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.ws</groupId>
+ <artifactId>jbossws-parent</artifactId>
+ <version>1.0.10-SNAPSHOT</version>
+ </parent>
+
+ <!-- Source Control Management -->
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossws/shared-testsuite/trunk</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossws/shared-testsuite/trunk</developerConnection>
+ <url>http://fisheye.jboss.com/viewrep/JBossWS/shared-testsuite/trunk</url>
+ </scm>
+
+ <properties>
+ <jbossws.common.version>2.0.0-SNAPSHOT</jbossws.common.version>
+ <jboss.logging.version>2.0.5.GA</jboss.logging.version>
+ <junit.version>3.8.2</junit.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.ws</groupId>
+ <artifactId>jbossws-common</artifactId>
+ <version>${jbossws.common.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ <version>${jboss.logging.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- Plugins -->
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>src/test/scripts/assembly-testsuite.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.0-beta-8</version>
+ <configuration>
+ <scmCommentPrefix>[${jira.issue}] :</scmCommentPrefix>
+ <autoVersionSubmodules>true</autoVersionSubmodules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Modified: shared-testsuite/trunk/testsuite/src/test/scripts/assembly-testsuite.xml
===================================================================
--- shared-testsuite/trunk/testsuite/src/test/scripts/assembly-testsuite.xml 2011-05-09 11:22:03 UTC (rev 14323)
+++ shared-testsuite/trunk/testsuite/src/test/scripts/assembly-testsuite.xml 2011-05-09 11:24:41 UTC (rev 14324)
@@ -6,7 +6,7 @@
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
- <directory>src/test</directory>
+ <directory>testsuite/src/test</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
More information about the jbossws-commits
mailing list