cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1531901 - /cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10Test.java
Date Mon, 14 Oct 2013 13:58:15 GMT
Author: dkulp
Date: Mon Oct 14 13:58:14 2013
New Revision: 1531901

URL: http://svn.apache.org/r1531901
Log:
Experiment with using Parameterized tests instead of a big loop

Modified:
    cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10Test.java

Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10Test.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10Test.java?rev=1531901&r1=1531900&r2=1531901&view=diff
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10Test.java
(original)
+++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10Test.java
Mon Oct 14 13:58:14 2013
@@ -22,13 +22,13 @@ package org.apache.cxf.systest.ws.wssec1
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
 
 import javax.xml.namespace.QName;
 import javax.xml.ws.BindingProvider;
 
-import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
-import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.systest.ws.common.SecurityTestUtil;
@@ -37,8 +37,11 @@ import org.apache.cxf.testutil.common.Ab
 import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 import org.apache.cxf.ws.security.SecurityConstants;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized.Parameters;
 
 import wssec.wssec10.IPingService;
 import wssec.wssec10.PingService;
@@ -47,6 +50,7 @@ import wssec.wssec10.PingService;
 /**
  * It tests both DOM + StAX clients against the DOM server
  */
+@RunWith(value = org.junit.runners.Parameterized.class)
 public class WSSecurity10Test extends AbstractBusClientServerTestBase {
     static final String PORT = allocatePort(Server.class);
     static final String SSL_PORT = allocatePort(Server.class, 1);
@@ -57,6 +61,41 @@ public class WSSecurity10Test extends Ab
     static {
         unrestrictedPoliciesInstalled = SecurityTestUtil.checkUnrestrictedPoliciesInstalled();
     };    
+    
+    final TestParam test;
+    
+    
+    public WSSecurity10Test(TestParam type) {
+        this.test = type;
+    }
+    
+    static class TestParam {
+        final String prefix;
+        final boolean streaming;
+        
+        public TestParam(String p, boolean b) {
+            prefix = p;
+            streaming = b;
+        }
+        public String toString() {
+            return prefix + ":" + (streaming ? "streaming" : "dom");
+        }
+    }
+    
+    @Parameters(name = "{0}")
+    public static Collection<TestParam[]> data() {
+       
+        return Arrays.asList(new TestParam[][] {{new TestParam("UserName", false)},
+                                                {new TestParam("UserNameOverTransport", false)},
+                                                {new TestParam("MutualCertificate10SignEncrypt",
false)},
+                                                {new TestParam("MutualCertificate10SignEncryptRsa15TripleDes",
false)},
+                                                {new TestParam("UserName", true)},
+                                                {new TestParam("UserNameOverTransport", true)},
+                                                {new TestParam("MutualCertificate10SignEncrypt",
true)},
+                                                {new TestParam("MutualCertificate10SignEncryptRsa15TripleDes",
true)}
+        
+        });
+    }
 
     @BeforeClass
     public static void startServers() throws Exception {
@@ -67,6 +106,11 @@ public class WSSecurity10Test extends Ab
             // set this to false to fork
             launchServer(Server.class, true)
         );
+        if (unrestrictedPoliciesInstalled) {
+            createStaticBus("org/apache/cxf/systest/ws/wssec10/client.xml");
+        } else {
+            createStaticBus("org/apache/cxf/systest/ws/wssec10/client_restricted.xml");
+        }
     }
     
     @org.junit.AfterClass
@@ -77,88 +121,25 @@ public class WSSecurity10Test extends Ab
 
     @Test
     public void testClientServerDOM() {
-
-        String[] argv = new String[] {
-            "UserName",
-            "UserNameOverTransport",
-            "MutualCertificate10SignEncrypt",
-            "MutualCertificate10SignEncryptRsa15TripleDes"
-        };
-        //argv = new String[] {argv[1]};
-        Bus bus = null;
-        if (unrestrictedPoliciesInstalled) {
-            bus = new SpringBusFactory().createBus("org/apache/cxf/systest/ws/wssec10/client.xml");
-        } else {
-            bus = new SpringBusFactory().createBus(
-                    "org/apache/cxf/systest/ws/wssec10/client_restricted.xml");
-        }
-        BusFactory.setDefaultBus(bus);
-        BusFactory.setThreadDefaultBus(bus);
+        BusFactory.setDefaultBus(getStaticBus());
+        BusFactory.setThreadDefaultBus(getStaticBus());
         URL wsdlLocation = null;
-        for (String portPrefix : argv) {
-            PingService svc = null; 
-            wsdlLocation = getWsdlLocation(portPrefix); 
-            svc = new PingService(wsdlLocation);
-            final IPingService port = 
-                svc.getPort(
-                    new QName(
-                        "http://WSSec/wssec10",
-                        portPrefix + "_IPingService"
-                    ),
-                    IPingService.class
-                );
-         
-            Client cl = ClientProxy.getClient(port);
-            
-            HTTPConduit http = (HTTPConduit) cl.getConduit();
-             
-            HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
-            httpClientPolicy.setConnectionTimeout(0);
-            httpClientPolicy.setReceiveTimeout(0);
-             
-            http.setClient(httpClientPolicy);
-            String output = port.echo(INPUT);
-            assertEquals(INPUT, output);
-            
-            cl.destroy();
-        }
-        
-        bus.shutdown(true);
-    }
-    
-    @Test
-    public void testClientServerStreaming() {
 
-        String[] argv = new String[] {
-            "UserName",
-            "UserNameOverTransport",
-            "MutualCertificate10SignEncrypt",
-            "MutualCertificate10SignEncryptRsa15TripleDes"
-        };
-        //argv = new String[] {argv[1]};
-        Bus bus = null;
-        if (unrestrictedPoliciesInstalled) {
-            bus = new SpringBusFactory().createBus("org/apache/cxf/systest/ws/wssec10/client.xml");
-        } else {
-            bus = new SpringBusFactory().createBus(
-                    "org/apache/cxf/systest/ws/wssec10/client_restricted.xml");
-        }
-        BusFactory.setDefaultBus(bus);
-        BusFactory.setThreadDefaultBus(bus);
-        URL wsdlLocation = null;
-        for (String portPrefix : argv) {
-            PingService svc = null; 
-            wsdlLocation = getWsdlLocation(portPrefix); 
-            svc = new PingService(wsdlLocation);
-            final IPingService port = 
-                svc.getPort(
-                    new QName(
-                        "http://WSSec/wssec10",
-                        portPrefix + "_IPingService"
-                    ),
-                    IPingService.class
-                );
-         
+        PingService svc = null; 
+        wsdlLocation = getWsdlLocation(test.prefix); 
+        svc = new PingService(wsdlLocation);
+        final IPingService port = 
+            svc.getPort(
+                new QName(
+                    "http://WSSec/wssec10",
+                    test.prefix + "_IPingService"
+                ),
+                IPingService.class
+            );
+     
+        Client cl = ClientProxy.getClient(port);
+        
+        if (test.streaming) {
             // Streaming
             ((BindingProvider)port).getRequestContext().put(
                 SecurityConstants.ENABLE_STREAMING_SECURITY, "true"
@@ -166,24 +147,21 @@ public class WSSecurity10Test extends Ab
             ((BindingProvider)port).getResponseContext().put(
                 SecurityConstants.ENABLE_STREAMING_SECURITY, "true"
             );
-            Client cl = ClientProxy.getClient(port);
-            
-            HTTPConduit http = (HTTPConduit) cl.getConduit();
-             
-            HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
-            httpClientPolicy.setConnectionTimeout(0);
-            httpClientPolicy.setReceiveTimeout(0);
-             
-            http.setClient(httpClientPolicy);
-            String output = port.echo(INPUT);
-            assertEquals(INPUT, output);
-            
-            cl.destroy();
         }
         
-        bus.shutdown(true);
+        HTTPConduit http = (HTTPConduit) cl.getConduit();
+         
+        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
+        httpClientPolicy.setConnectionTimeout(0);
+        httpClientPolicy.setReceiveTimeout(0);
+         
+        http.setClient(httpClientPolicy);
+        String output = port.echo(INPUT);
+        assertEquals(INPUT, output);
+        
+        cl.destroy();
     }
-    
+        
     private static URL getWsdlLocation(String portPrefix) {
         try {
             if ("UserNameOverTransport".equals(portPrefix)) {



Mime
View raw message