Author: alessio.soldano(a)jboss.com
Date: 2011-05-10 03:04:52 -0400 (Tue, 10 May 2011)
New Revision: 14338
Added:
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/ClientHelper.java
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/JBossWSCXFTestSetup.java
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/TestServlet.java
Modified:
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/pom.xml
Log:
[JBWS-3289] Fixing build w/ spring testsuite
Modified: stack/cxf/trunk/modules/testsuite/cxf-spring-tests/pom.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-spring-tests/pom.xml 2011-05-10 06:36:54 UTC
(rev 14337)
+++ stack/cxf/trunk/modules/testsuite/cxf-spring-tests/pom.xml 2011-05-10 07:04:52 UTC
(rev 14338)
@@ -21,11 +21,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.ws.cxf</groupId>
- <artifactId>jbossws-cxf-specific-tests</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
<groupId>org.picketbox</groupId>
<artifactId>picketbox-bare</artifactId>
<scope>test</scope>
Added:
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/ClientHelper.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/ClientHelper.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/ClientHelper.java 2011-05-10
07:04:52 UTC (rev 14338)
@@ -0,0 +1,27 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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;
+
+public interface ClientHelper
+{
+ public void setTargetEndpoint(String address);
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/JBossWSCXFTestSetup.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/JBossWSCXFTestSetup.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/JBossWSCXFTestSetup.java 2011-05-10
07:04:52 UTC (rev 14338)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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 junit.framework.Test;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.jboss.logging.Logger;
+import org.jboss.wsf.test.JBossWSTestSetup;
+
+public class JBossWSCXFTestSetup extends JBossWSTestSetup
+{
+ private Bus defaultBus;
+
+ public JBossWSCXFTestSetup(Class<?> testClass, String archiveList)
+ {
+ super(testClass, archiveList);
+ }
+
+ public JBossWSCXFTestSetup(Test test, String archiveList)
+ {
+ super(test, archiveList);
+ }
+
+ public JBossWSCXFTestSetup(Test test)
+ {
+ super(test);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ defaultBus = BusFactory.getDefaultBus(false);
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ try
+ {
+ Bus afterTestsDefaultBus = BusFactory.getDefaultBus(false);
+
+ if (defaultBus == null && afterTestsDefaultBus != null)
+ {
+ Logger.getLogger(this.getClass()).info("Default CXF bus has been set
during test execution");
+ }
+ else if (defaultBus != afterTestsDefaultBus)
+ {
+ throw new Exception("CXF Default bus changed during test: \nBEFORE:
" + defaultBus + "\nAFTER: "
+ + afterTestsDefaultBus);
+ }
+ }
+ finally
+ {
+ defaultBus = null; //remove reference, to help GC
+ super.tearDown();
+ }
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/TestServlet.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/TestServlet.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-spring-tests/src/test/java/org/jboss/wsf/test/TestServlet.java 2011-05-10
07:04:52 UTC (rev 14338)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 01-Apr-2011
+ *
+ */
+@WebServlet(name = "TestServlet", urlPatterns = "/*")
+public class TestServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
+ {
+ String helperClassName = req.getParameter("helper");
+ if (helperClassName == null || helperClassName.length() == 0)
+ throw new ServletException("helper not specified!");
+ String path = req.getParameter("path");
+ if (path == null || path.length() == 0)
+ throw new ServletException("path not specified!");
+ try
+ {
+ ClientHelper helper = (ClientHelper)
Class.forName(helperClassName).newInstance();
+ helper.setTargetEndpoint("http://" +
System.getProperty("jboss.bind.address", "localhost") +
":8080" + path);
+ List<String> failedTests = new LinkedList<String>();
+ List<String> errorTests = new LinkedList<String>();
+ Method[] methods = helper.getClass().getMethods();
+ String methodName = req.getParameter("method");
+ int testsRun = 0;
+ if (methodName != null && methodName.length() > 0)
+ {
+ Method m = null;
+ m = helper.getClass().getMethod(methodName);
+ testsRun++;
+ invokeMethod(m, helper, failedTests, errorTests);
+ }
+ else
+ {
+ for (Method m : methods)
+ {
+ if (m.getName().startsWith("test") &&
m.getParameterTypes().length == 0
+ && m.getReturnType().equals(boolean.class))
+ {
+ testsRun++;
+ invokeMethod(m, helper, failedTests, errorTests);
+ }
+ }
+ }
+ if (failedTests.isEmpty() && errorTests.isEmpty())
+ {
+ res.getWriter().print(testsRun);
+ }
+ else
+ {
+ PrintWriter w = res.getWriter();
+ w.print("# Failed tests: ");
+ for (Iterator<String> it = failedTests.iterator(); it.hasNext();)
+ {
+ w.print(it.next());
+ if (it.hasNext())
+ w.print(", ");
+ }
+ res.getWriter().print(" # Error tests: ");
+ for (Iterator<String> it = errorTests.iterator(); it.hasNext();)
+ {
+ w.print(it.next());
+ if (it.hasNext())
+ w.print(", ");
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new ServletException(e);
+ }
+ }
+
+ private void invokeMethod(Method m, ClientHelper helper, List<String>
failedTests, List<String> errorTests) throws ServletException
+ {
+ try
+ {
+ if (!(Boolean)m.invoke(helper))
+ {
+ failedTests.add(m.getName());
+ }
+ }
+ catch (InvocationTargetException e)
+ {
+ Throwable thrownException = e.getTargetException();
+ errorTests.add(m.getName() + ": " +
thrownException.getClass().getName() + " " + thrownException.getMessage());
+ thrownException.printStackTrace();
+ }
+ catch (Exception e)
+ {
+ throw new ServletException(e);
+ }
+ }
+}