[jbossws-commits] JBossWS SVN: r16087 - in stack/cxf/trunk/modules/testsuite/cxf-tests: src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic and 1 other directory.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Apr 4 05:04:52 EDT 2012


Author: alessio.soldano at jboss.com
Date: 2012-04-04 05:04:51 -0400 (Wed, 04 Apr 2012)
New Revision: 16087

Added:
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptHelper.java
Modified:
   stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptGCMTestCase.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptTestCase.java
Log:
Adding in-container wsse client testing


Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml	2012-04-04 05:20:26 UTC (rev 16086)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml	2012-04-04 09:04:51 UTC (rev 16087)
@@ -178,6 +178,22 @@
         <include name="alice.jks" />
       </metainf>
     </jar>
+    <war warfile="${tests.output.dir}/test-libs/jaxws-samples-wsse-policy-sign-encrypt-client.war" needxmlfile='false'>
+      <classes dir="${tests.output.dir}/test-classes">
+        <include name="org/jboss/wsf/test/ClientHelper.class"/>
+        <include name="org/jboss/wsf/test/TestServlet.class"/>
+        <include name="org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptHelper.class"/>
+      	<include name="org/jboss/test/ws/jaxws/samples/wsse/policy/basic/ServiceIface.class"/>
+        <include name="org/jboss/test/ws/jaxws/samples/wsse/policy/basic/KeystorePasswordCallback.class"/>
+      </classes>
+      <zipfileset dir="${tests.output.dir}/test-resources/jaxws/samples/wsse/policy/basic/sign-encrypt" prefix="WEB-INF/classes">
+          <include name="META-INF/alice.properties" />
+          <include name="META-INF/alice.jks" />
+      </zipfileset>
+      <manifest>
+        <attribute name="Dependencies" value="org.jboss.ws.cxf.jbossws-cxf-client services, org.apache.ws.security"/>
+      </manifest>
+    </war>
 
     <!-- jaxws-samples-wsse-policy-sign-encrypt-mc-client -->
     <jar destfile="${tests.output.dir}/test-libs/jaxws-samples-wsse-policy-sign-encrypt-mc-client.jar">

Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptGCMTestCase.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptGCMTestCase.java	2012-04-04 05:20:26 UTC (rev 16086)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptGCMTestCase.java	2012-04-04 09:04:51 UTC (rev 16087)
@@ -21,16 +21,12 @@
  */
 package org.jboss.test.ws.jaxws.samples.wsse.policy.basic;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.net.URL;
 
-import javax.xml.namespace.QName;
-import javax.xml.ws.BindingProvider;
-import javax.xml.ws.Service;
-import javax.xml.ws.soap.SOAPFaultException;
-
 import junit.framework.Test;
 
-import org.apache.cxf.ws.security.SecurityConstants;
 import org.jboss.wsf.test.JBossWSCXFTestSetup;
 import org.jboss.wsf.test.JBossWSTest;
 
@@ -47,32 +43,24 @@
    
    public static Test suite()
    {
-      return new JBossWSCXFTestSetup(SignEncryptGCMTestCase.class, "jaxws-samples-wsse-policy-sign-encrypt-client.jar jaxws-samples-wsse-policy-sign-encrypt-gcm.war");
+      return new JBossWSCXFTestSetup(SignEncryptGCMTestCase.class, 
+            "jaxws-samples-wsse-policy-sign-encrypt-client.jar " +
+            "jaxws-samples-wsse-policy-sign-encrypt-client.war " +
+            "jaxws-samples-wsse-policy-sign-encrypt-gcm.war");
    }
-
-   public void test() throws Exception
+   
+   public void testClientSide() throws Exception
    {
-      QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
-      URL wsdlURL = new URL(serviceURL + "?wsdl");
-      Service service = Service.create(wsdlURL, serviceName);
-      ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
-      setupWsse(proxy);
-      try
-      {
-         assertEquals("Secure Hello World!", proxy.sayHello());
-      }
-      catch (SOAPFaultException e)
-      {
-         throw new Exception("Please check that the Bouncy Castle provider is installed.", e);
-      }
+      SignEncryptHelper helper = new SignEncryptHelper();
+      helper.setTargetEndpoint(serviceURL);
+      assertTrue(helper.testSignEncrypt());
    }
    
-   private void setupWsse(ServiceIface proxy)
+   public void testServerSide() throws Exception
    {
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/alice.properties"));
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/alice.properties"));
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "alice");
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.ENCRYPT_USERNAME, "bob");
+      URL url = new URL("http://" + getServerHost() + ":8080/jaxws-samples-wsse-policy-sign-encrypt-client?" +
+            "path=/jaxws-samples-wsse-policy-sign-encrypt-gcm&method=testSignEncrypt&helper=" + SignEncryptHelper.class.getName());
+      BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
+      assertEquals("1", br.readLine());
    }
 }

Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptHelper.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptHelper.java	                        (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptHelper.java	2012-04-04 09:04:51 UTC (rev 16087)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, 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.test.ws.jaxws.samples.wsse.policy.basic;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPFaultException;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.ws.security.SecurityConstants;
+import org.jboss.wsf.test.ClientHelper;
+
+public class SignEncryptHelper implements ClientHelper
+{
+   private String targetEndpoint;
+   
+   @Override
+   public void setTargetEndpoint(String address)
+   {
+      targetEndpoint = address;
+   }
+   
+   public boolean testSignEncrypt() throws Exception
+   {
+      Bus bus = BusFactory.newInstance().createBus();
+      try
+      {
+         BusFactory.setThreadDefaultBus(bus);
+      
+         QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
+         URL wsdlURL = new URL(targetEndpoint + "?wsdl");
+         Service service = Service.create(wsdlURL, serviceName);
+         ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
+         setupWsse(proxy);
+         try
+         {
+            return "Secure Hello World!".equals(proxy.sayHello());
+         }
+         catch (SOAPFaultException e)
+         {
+            throw new Exception("Please check that the Bouncy Castle provider is installed.", e);
+         }
+      }
+      finally
+      {
+         bus.shutdown(true);
+      }
+   }
+   
+   private void setupWsse(ServiceIface proxy)
+   {
+      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
+      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/alice.properties"));
+      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/alice.properties"));
+      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "alice");
+      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.ENCRYPT_USERNAME, "bob");
+   }
+
+}

Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptTestCase.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptTestCase.java	2012-04-04 05:20:26 UTC (rev 16086)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptTestCase.java	2012-04-04 09:04:51 UTC (rev 16087)
@@ -1,6 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source.
- * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, 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.
  *
@@ -21,16 +21,12 @@
  */
 package org.jboss.test.ws.jaxws.samples.wsse.policy.basic;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.net.URL;
 
-import javax.xml.namespace.QName;
-import javax.xml.ws.BindingProvider;
-import javax.xml.ws.Service;
-import javax.xml.ws.soap.SOAPFaultException;
-
 import junit.framework.Test;
 
-import org.apache.cxf.ws.security.SecurityConstants;
 import org.jboss.wsf.test.JBossWSCXFTestSetup;
 import org.jboss.wsf.test.JBossWSTest;
 
@@ -46,32 +42,24 @@
    
    public static Test suite()
    {
-      return new JBossWSCXFTestSetup(SignEncryptTestCase.class, "jaxws-samples-wsse-policy-sign-encrypt-client.jar jaxws-samples-wsse-policy-sign-encrypt.war");
+      return new JBossWSCXFTestSetup(SignEncryptTestCase.class,
+            "jaxws-samples-wsse-policy-sign-encrypt-client.jar " +
+            "jaxws-samples-wsse-policy-sign-encrypt-client.war " +
+            "jaxws-samples-wsse-policy-sign-encrypt.war");
    }
-
-   public void test() throws Exception
+   
+   public void testClientSide() throws Exception
    {
-      QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
-      URL wsdlURL = new URL(serviceURL + "?wsdl");
-      Service service = Service.create(wsdlURL, serviceName);
-      ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
-      setupWsse(proxy);
-      try
-      {
-         assertEquals("Secure Hello World!", proxy.sayHello());
-      }
-      catch (SOAPFaultException e)
-      {
-         throw new Exception("Please check that the Bouncy Castle provider is installed.", e);
-      }
+      SignEncryptHelper helper = new SignEncryptHelper();
+      helper.setTargetEndpoint(serviceURL);
+      assertTrue(helper.testSignEncrypt());
    }
    
-   private void setupWsse(ServiceIface proxy)
+   public void testServerSide() throws Exception
    {
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/alice.properties"));
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("META-INF/alice.properties"));
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "alice");
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.ENCRYPT_USERNAME, "bob");
+      URL url = new URL("http://" + getServerHost() + ":8080/jaxws-samples-wsse-policy-sign-encrypt-client?" +
+      		"path=/jaxws-samples-wsse-policy-sign-encrypt&method=testSignEncrypt&helper=" + SignEncryptHelper.class.getName());
+      BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
+      assertEquals("1", br.readLine());
    }
 }



More information about the jbossws-commits mailing list