cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [22/50] [abbrv] cxf git commit: [CXF-6908] Adding testcase
Date Thu, 26 May 2016 21:45:50 GMT
[CXF-6908] Adding testcase


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/ffa81f69
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ffa81f69
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ffa81f69

Branch: refs/heads/master-jaxrs-2.1
Commit: ffa81f69c90a6287429631b7da2eb0390f5608f4
Parents: e28b6d2
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Fri May 20 21:36:40 2016 +0200
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Fri May 20 21:37:23 2016 +0200

----------------------------------------------------------------------
 .../systest/ws/security/SecurityPolicyTest.java | 68 ++++++++++++++++++++
 .../cxf/systest/ws/security/DoubleIt.wsdl       |  3 +
 2 files changed, 71 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/ffa81f69/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
index 4ab13d7..fb0eea0 100644
--- a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
+++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
@@ -29,6 +29,8 @@ import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.callback.UnsupportedCallbackException;
 import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.BindingProvider;
@@ -39,6 +41,7 @@ import javax.xml.ws.Service;
 import javax.xml.ws.Service.Mode;
 import javax.xml.ws.ServiceMode;
 import javax.xml.ws.WebServiceProvider;
+import javax.xml.ws.soap.SOAPFaultException;
 import javax.xml.xpath.XPathConstants;
 
 import org.w3c.dom.Document;
@@ -79,6 +82,8 @@ public class SecurityPolicyTest extends AbstractBusClientServerTestBase
 {
             + PORT + "/SecPolTestSignThenEncrypt";
     public static final String POLICY_SIGNENC_PROVIDER_ADDRESS 
         = "http://localhost:" + PORT + "/SecPolTestSignThenEncryptProvider";
+    public static final String POLICY_FAULT_SIGNENC_PROVIDER_ADDRESS 
+    = "http://localhost:" + PORT + "/SecPolTestFaultSignThenEncryptProvider";
     public static final String POLICY_SIGN_ADDRESS = "http://localhost:" + PORT + "/SecPolTestSign";
     public static final String POLICY_XPATH_ADDRESS = "http://localhost:" + PORT + "/SecPolTestXPath";
     public static final String POLICY_SIGNONLY_ADDRESS = "http://localhost:" + PORT + "/SecPolTestSignedOnly";
@@ -164,6 +169,12 @@ public class SecurityPolicyTest extends AbstractBusClientServerTestBase
 {
         ei = ep.getServer().getEndpoint().getEndpointInfo(); 
         setCryptoProperties(ei, "bob.properties", "alice.properties");
         
+        ep = (EndpointImpl)Endpoint.publish(POLICY_FAULT_SIGNENC_PROVIDER_ADDRESS,
+                                            new DoubleItFaultProvider());
+        
+        ei = ep.getServer().getEndpoint().getEndpointInfo(); 
+        setCryptoProperties(ei, "bob.properties", "alice.properties");
+        
         ep = (EndpointImpl)Endpoint.create(new DoubleItImpl());
         ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortSignedOnly"));
         ep.setWsdlLocation(wsdl.getPath());
@@ -468,6 +479,28 @@ public class SecurityPolicyTest extends AbstractBusClientServerTestBase
 {
         
     }
     
+    @WebServiceProvider(targetNamespace = "http://www.example.org/contract/DoubleIt",
+                        portName = "DoubleItFaultPortSignThenEncrypt",
+                        serviceName = "DoubleItService",
+                        wsdlLocation = "classpath:/org/apache/cxf/systest/ws/security/DoubleIt.wsdl")
+    @ServiceMode(value = Mode.MESSAGE)
+    public static class DoubleItFaultProvider implements Provider<SOAPMessage> {
+
+        public SOAPMessage invoke(SOAPMessage request) {
+            try {
+                MessageFactory messageFactory = MessageFactory.newInstance();
+                SOAPMessage msg = messageFactory.createMessage();
+                msg.getSOAPBody().addFault(new QName("http://schemas.xmlsoap.org/soap/envelope/",
"Server"),
+                                           "Foo");
+                return msg;
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            return null;
+        }
+
+    }
+
     @Test
     public void testCXF3041() throws Exception {
         SpringBusFactory bf = new SpringBusFactory();
@@ -666,4 +699,39 @@ public class SecurityPolicyTest extends AbstractBusClientServerTestBase
 {
         epBus.shutdown(true);
         bus.shutdown(true);
     }
+    
+    @Test
+    public void testFault() throws Exception {
+        SpringBusFactory bf = new SpringBusFactory();
+
+        URL busFile = SecurityPolicyTest.class.getResource("https_config_client.xml");
+        Bus bus = bf.createBus(busFile.toString());
+        SpringBusFactory.setDefaultBus(bus);
+        SpringBusFactory.setThreadDefaultBus(bus);
+        
+        URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl");
+        Service service = Service.create(wsdl, SERVICE_QNAME);
+        
+        QName portQName = new QName(NAMESPACE, "DoubleItFaultPortSignThenEncrypt");
+        DoubleItPortType pt = service.getPort(portQName, DoubleItPortType.class);
+        updateAddressPort(pt, PORT);
+        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,

+                                                      new KeystorePasswordCallback());
+        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
+                                                      "alice.properties");
+        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,

+                                                      "bob.properties");
+        
+        // DOM
+        try {
+            pt.doubleIt(5);
+            fail("SOAPFaultException expected!");
+        } catch (SOAPFaultException e) {
+            assertEquals("Foo", e.getFault().getFaultString());
+        } finally {
+            ((java.io.Closeable)pt).close();
+            bus.shutdown(true);
+        }
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/ffa81f69/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl
----------------------------------------------------------------------
diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl
b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl
index f478fa6..20f2f2e 100644
--- a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl
+++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl
@@ -246,6 +246,9 @@
         <wsdl:port name="DoubleItPortSignThenEncrypt" binding="tns:DoubleItBindingSignThenEncrypt">
             <soap:address location="http://localhost:9010/SecPolTestSignThenEncrypt"/>
         </wsdl:port>
+        <wsdl:port name="DoubleItFaultPortSignThenEncrypt" binding="tns:DoubleItBindingSignThenEncrypt">
+            <soap:address location="http://localhost:9010/SecPolTestFaultSignThenEncryptProvider"/>
+        </wsdl:port>
         <wsdl:port name="DoubleItPortSign" binding="tns:DoubleItBindingSign">
             <soap:address location="http://localhost:9010/SecPolTestSign"/>
         </wsdl:port>


Mime
View raw message