cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r776283 - in /cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm: ControlImpl.java SequenceTest.java rminterceptors_provider.xml
Date Tue, 19 May 2009 11:45:51 GMT
Author: eglynn
Date: Tue May 19 11:45:51 2009
New Revision: 776283

URL: http://svn.apache.org/viewvc?rev=776283&view=rev
Log:
Added Provider-based tests for WS-RM

Added:
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/rminterceptors_provider.xml
Modified:
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java?rev=776283&r1=776282&r2=776283&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java Tue May
19 11:45:51 2009
@@ -20,17 +20,33 @@
 
 package org.apache.cxf.systest.ws.rm;
 
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.logging.Logger;
 
 import javax.jws.WebService;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.Endpoint;
+import javax.xml.ws.Provider;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.ServiceMode;
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.XPathUtils;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
+//import org.apache.cxf.jaxws.EndpointImpl;
+
 
 @WebService(serviceName = "ControlService", 
             portName = "ControlPort", 
@@ -57,8 +73,13 @@
             greeterBus.getOutInterceptors().add(logOut);
             greeterBus.getOutFaultInterceptors().add(logOut);
 
-            Endpoint.publish(address, implementor);
-            LOG.info("Published greeter endpoint.");
+            if (cfgResource.indexOf("provider") == -1) {
+                Endpoint.publish(address, implementor);
+                LOG.info("Published greeter endpoint.");
+            } else {
+                Endpoint.publish(address, new GreeterProvider());
+                LOG.info("Published greeter provider.");
+            }
         } finally {
             if (derbyHome != null) {
                 System.setProperty("derby.system.home", derbyHome);
@@ -69,5 +90,40 @@
         
         return true;        
     }
-    
+
+    @WebService(serviceName = "GreeterService",
+                portName = "GreeterPort",
+                targetNamespace = "http://cxf.apache.org/greeter_control",
+                wsdlLocation = "/wsdl/greeter_control.wsdl")
+    @ServiceMode(Mode.PAYLOAD)
+    public static class GreeterProvider implements Provider<Source> {
+
+        public Source invoke(Source obj) {
+            DOMSource ds = (DOMSource)obj;
+            
+            Element el = ((Document)ds.getNode()).getDocumentElement();
+            Map<String, String> ns = new HashMap<String, String>();
+            ns.put("ns", "http://cxf.apache.org/greeter_control/types");
+            XPathUtils xp = new XPathUtils(ns);
+            String s = (String)xp.getValue("/ns:greetMe/ns:requestType",
+                                           el,
+                                           XPathConstants.STRING);
+
+            if (s == null || "".equals(s)) {
+                s = (String)xp.getValue("/ns:greetMeOneWay/ns:requestType",
+                                        el,
+                                        XPathConstants.STRING);
+                System.out.println("greetMeOneWay arg: " + s);
+                return null;
+            } else {
+                System.out.println("greetMe arg: " + s);
+                String resp =
+                    "<greetMeResponse "
+                        + "xmlns=\"http://cxf.apache.org/greeter_control/types\">"
+                        + "<responseType>" + s.toUpperCase() + "</responseType>"
+                    + "</greetMeResponse>";
+                return new StreamSource(new StringReader(resp));
+            }
+        }
+    }    
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java?rev=776283&r1=776282&r2=776283&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java Tue May
19 11:45:51 2009
@@ -22,8 +22,10 @@
 import java.io.InputStream;
 import java.io.StringWriter;
 import java.math.BigInteger;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 import java.util.logging.Logger;
@@ -36,14 +38,15 @@
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
-
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.handler.MessageContext;
+import javax.xml.xpath.XPathConstants;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -57,6 +60,7 @@
 import org.apache.cxf.greeter_control.ControlService;
 import org.apache.cxf.greeter_control.Greeter;
 import org.apache.cxf.greeter_control.GreeterService;
+import org.apache.cxf.helpers.XPathUtils;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxws.DispatchImpl;
 import org.apache.cxf.message.Message;
@@ -197,6 +201,17 @@
     }
 
     @Test
+    public void testOnewayAnonymousAcksProvider() throws Exception {
+        init("org/apache/cxf/systest/ws/rm/rminterceptors_provider.xml");
+
+        greeter.greetMeOneWay("once");
+        greeter.greetMeOneWay("twice");
+        greeter.greetMeOneWay("thrice");
+
+        verifyOnewayAnonymousAcks();
+    }
+
+    @Test
     public void testOnewayAnonymousAcksDispatch() throws Exception {
         init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false, true);
 
@@ -210,6 +225,22 @@
         verifyOnewayAnonymousAcks();
     }
 
+    @Test
+    public void testOnewayAnonymousAcksDispatchProvider() throws Exception {
+        init("org/apache/cxf/systest/ws/rm/rminterceptors_provider.xml",
+             false, 
+             true);
+
+        dispatch.getRequestContext().put(MessageContext.WSDL_OPERATION,
+                                         GREETMEONEWAY_NAME);
+
+        dispatch.invokeOneWay(getDOMRequest("One", true));
+        dispatch.invokeOneWay(getDOMRequest("Two", true));
+        dispatch.invokeOneWay(getDOMRequest("Three", true));
+
+        verifyOnewayAnonymousAcks();
+    }
+
     private void verifyOnewayAnonymousAcks() throws Exception {
         // three application messages plus createSequence
 
@@ -432,6 +463,17 @@
     }
 
     @Test
+    public void testTwowayNonAnonymousProvider() throws Exception {
+        init("org/apache/cxf/systest/ws/rm/rminterceptors_provider.xml", true);
+
+        assertEquals("ONE", greeter.greetMe("one"));
+        assertEquals("TWO", greeter.greetMe("two"));
+        assertEquals("THREE", greeter.greetMe("three"));
+
+        verifyTwowayNonAnonymous();
+    }
+
+    @Test
     public void testTwowayNonAnonymousDispatch() throws Exception {
         init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", true, true);
 
@@ -445,6 +487,22 @@
         verifyTwowayNonAnonymous();
     }
 
+    @Test
+    public void testTwowayNonAnonymousDispatchProvider() throws Exception {
+        init("org/apache/cxf/systest/ws/rm/rminterceptors_provider.xml",
+             true,
+             true);
+
+        dispatch.getRequestContext().put(MessageContext.WSDL_OPERATION,
+                                         GREETME_NAME);
+
+        verifyDOMResponse(dispatch.invoke(getDOMRequest("One")), "ONE");
+        verifyDOMResponse(dispatch.invoke(getDOMRequest("Two")), "TWO");
+        verifyDOMResponse(dispatch.invoke(getDOMRequest("Three")), "THREE");
+
+        verifyTwowayNonAnonymous();
+    }
+
     private void verifyTwowayNonAnonymous() throws Exception {
     
         // CreateSequence and three greetMe messages
@@ -1431,9 +1489,11 @@
         return getDOMRequest(n, false);
     }
 
-    private DOMSource getDOMRequest(String n, boolean oneway) throws Exception {
-        InputStream is = getClass().getResourceAsStream((oneway ? "oneway" : "twoway") +
"Req" + n + ".xml");
-         
+    private DOMSource getDOMRequest(String n, boolean oneway)
+        throws Exception {
+        InputStream is = 
+            getClass().getResourceAsStream((oneway ? "oneway" : "twoway")
+                                           + "Req" + n + ".xml");
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         factory.setNamespaceAware(true);
         DocumentBuilder builder = factory.newDocumentBuilder();
@@ -1441,14 +1501,34 @@
         return new DOMSource(newDoc);
     }
 
-    private static String convertToString(DOMSource domSource) throws TransformerException
{
-        Transformer xformer = TransformerFactory.newInstance().newTransformer();
+    private static String convertToString(DOMSource domSource)
+        throws TransformerException {
+        Transformer xformer =
+            TransformerFactory.newInstance().newTransformer();
         StringWriter output = new StringWriter();
         xformer.transform(domSource, new StreamResult(output));
         return output.toString();
     }
 
-    private void verifyDOMResponse(DOMSource domResponse, String expected) throws Exception
{
-        assertTrue(convertToString(domResponse).indexOf(expected) != -1);
+    private static String parseResponse(DOMSource domResponse) {
+        Element el = ((Document)domResponse.getNode()).getDocumentElement();
+        Map<String, String> ns = new HashMap<String, String>();
+        ns.put("soap", "http://schemas.xmlsoap.org/soap/envelope/");
+        ns.put("ns", "http://cxf.apache.org/greeter_control/types");
+        XPathUtils xp = new XPathUtils(ns);
+        return (String)xp.getValue("/soap:Envelope/soap:Body"
+                                   + "/ns:greetMeResponse/ns:responseType",
+                                   el,
+                                   XPathConstants.STRING);
+    }
+
+    private void verifyDOMResponse(DOMSource domResponse, String expected) 
+        throws TransformerException {
+        String s = convertToString(domResponse);
+        assertTrue("expected: " + s + " to contain: " + expected,
+                   s.indexOf(expected) != -1);
+        assertEquals("unexpected response: " + s,
+                     expected,
+                     parseResponse(domResponse));
     }
 }

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/rminterceptors_provider.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/rminterceptors_provider.xml?rev=776283&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/rminterceptors_provider.xml
(added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/rminterceptors_provider.xml
Tue May 19 11:45:51 2009
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="mapAggregator" class="org.apache.cxf.ws.addressing.MAPAggregator"/>
+    <bean id="mapCodec" class="org.apache.cxf.ws.addressing.soap.MAPCodec"/>
+    <bean id="rmLogicalOut" class="org.apache.cxf.ws.rm.RMOutInterceptor">
+        <property name="bus" ref="cxf"/>
+    </bean>
+    <bean id="rmLogicalIn" class="org.apache.cxf.ws.rm.RMInInterceptor">
+        <property name="bus" ref="cxf"/>
+    </bean>
+    <bean id="rmCodec" class="org.apache.cxf.ws.rm.soap.RMSoapInterceptor"/>
+
+    <!-- We are adding the interceptors to the bus as we will have only one endpoint/service/bus.
-->
+
+    <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl">
+        <property name="inInterceptors">
+            <list>
+                <ref bean="mapAggregator"/>
+                <ref bean="mapCodec"/>
+                <ref bean="rmLogicalIn"/>
+                <ref bean="rmCodec"/>
+                <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
+            </list>
+        </property>
+        <property name="inFaultInterceptors">
+            <list>
+                <ref bean="mapAggregator"/>
+                <ref bean="mapCodec"/>
+                <ref bean="rmLogicalIn"/>
+                <ref bean="rmCodec"/>
+                <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
+            </list>
+        </property>
+        <property name="outInterceptors">
+            <list>
+                <ref bean="mapAggregator"/>
+                <ref bean="mapCodec"/>
+                <ref bean="rmLogicalOut"/>
+                <ref bean="rmCodec"/>
+                <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
+            </list>
+        </property>
+        <property name="outFaultInterceptors">
+            <list>
+                <ref bean="mapAggregator"/>
+                <ref bean="mapCodec"/>
+                <ref bean="rmLogicalOut"/>
+                <ref bean="rmCodec"/>
+                <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
+            </list>
+        </property>
+    </bean>
+</beans>



Mime
View raw message