You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by mm...@apache.org on 2007/10/10 03:22:06 UTC

svn commit: r583338 - in /incubator/cxf/trunk: systests/src/test/java/org/apache/cxf/systest/type_substitution/ testutils/ testutils/src/main/resources/wsdl/

Author: mmao
Date: Tue Oct  9 18:22:05 2007
New Revision: 583338

URL: http://svn.apache.org/viewvc?rev=583338&view=rev
Log:
cXF-991 
  TypeSubstitution system test


Added:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/CarDealerImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/Server.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/TypeSubClientServerTest.java
    incubator/cxf/trunk/testutils/src/main/resources/wsdl/cardealer.wsdl
Modified:
    incubator/cxf/trunk/testutils/pom.xml

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/CarDealerImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/CarDealerImpl.java?rev=583338&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/CarDealerImpl.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/CarDealerImpl.java Tue Oct  9 18:22:05 2007
@@ -0,0 +1,68 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.systest.type_substitution;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.xml.ws.WebServiceException;
+
+import org.apache.type_substitution.Car;
+import org.apache.type_substitution.CarDealer;
+import org.apache.type_substitution.Porsche;
+
+@WebService(name = "CarDealer")
+
+public class CarDealerImpl implements CarDealer {
+    public List<Car> getSedans(String carType) {
+        if (carType.equalsIgnoreCase("Porsche")) {
+            List<Car> cars = new ArrayList<Car>();
+            cars.add(newPorsche("Boxster", "1998", "white"));
+            cars.add(newPorsche("BoxsterS", "1999", "red"));
+            return cars;
+        }
+        throw new WebServiceException("Not a dealer of: " + carType);
+    }
+
+    @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
+    public Car tradeIn(Car oldCar) {
+        if (!(oldCar instanceof Porsche)) {
+            throw new WebServiceException("Expected Porsche, received, " + oldCar.getClass().getName());
+        }
+
+        Porsche porsche = (Porsche)oldCar;
+        if (porsche.getMake().equals("Porsche") && porsche.getModel().equals("GT2000")
+            && porsche.getYear().equals("2000") && porsche.getColor().equals("white")) {
+            return newPorsche("911GT3", "2007", "black");
+        }
+        throw new WebServiceException("Invalid Porsche Car");
+    }
+
+    private Porsche newPorsche(String model, String year, String color) {
+        Porsche porsche = new Porsche();
+        porsche.setMake("Porsche");
+        porsche.setModel(model);
+        porsche.setYear(year);
+        porsche.setColor(color);
+        return porsche;
+    }
+}

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/Server.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/Server.java?rev=583338&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/Server.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/Server.java Tue Oct  9 18:22:05 2007
@@ -0,0 +1,46 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.systest.type_substitution;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+public class Server extends AbstractBusTestServerBase {
+
+    protected void run()  {    
+        Object implementor = new CarDealerImpl();
+        String address = "http://localhost:9070/jaxws-type_substitution/cardealer";
+        Endpoint.publish(address, implementor);
+    }
+
+
+    public static void main(String[] args) {
+        try {
+            Server s = new Server();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+}

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/TypeSubClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/TypeSubClientServerTest.java?rev=583338&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/TypeSubClientServerTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/type_substitution/TypeSubClientServerTest.java Tue Oct  9 18:22:05 2007
@@ -0,0 +1,102 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.systest.type_substitution;
+
+import java.net.URL;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.type_substitution.Car;
+import org.apache.type_substitution.CarDealer;
+import org.apache.type_substitution.CarDealerService;
+import org.apache.type_substitution.Porsche;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TypeSubClientServerTest extends AbstractBusClientServerTestBase {    
+
+    private final QName serviceName = new QName("http://apache.org/type_substitution/",
+                                                "CarDealerService");
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", launchServer(Server.class));
+    }
+
+    @Test
+    public void testBasicConnection() throws Exception {
+        CarDealer dealer = getCardealer();
+
+        /**
+         * CarDealer.getSedans() returns List<Car>
+         * Car is abstract class. The code below shows
+         * that the client is expecting a Porsche which extends
+         * Car.
+         *
+         * It shows a doc wrapper style operation.
+        */
+
+        List<Car> cars = dealer.getSedans("porsche");
+        assertEquals(2, cars.size());
+        Porsche car = (Porsche) cars.get(0);
+        assertNotNull(car);
+        if (car != null && "Porsche".equals(car.getMake()) 
+            && "Boxster".equals(car.getModel()) 
+            && "1998".equals(car.getYear()) 
+            && "white".equals(car.getColor())) {
+            // get the right car
+        } else {
+            fail("Get the wrong car!");
+        }
+        
+        /**
+         * CarDealer.tradeIn(Car) takes an abstract class Car and returns the same.
+         * We will send a sub-class instead and expect to get the same.
+         *
+         */
+        Porsche oldCar = new Porsche();
+        oldCar.setMake("Porsche");
+        oldCar.setColor("white");
+        oldCar.setModel("GT2000");
+        oldCar.setYear("2000");
+        Porsche newCar = (Porsche)dealer.tradeIn(oldCar);
+        assertNotNull(newCar);
+
+        if (newCar != null && "Porsche".equals(newCar.getMake()) 
+            && "911GT3".equals(newCar.getModel()) 
+            && "2007".equals(newCar.getYear()) 
+            && "black".equals(newCar.getColor())) {
+            // get the right car
+        } else {
+            fail("Get the wrong car!");
+        }
+    }
+
+    private CarDealer getCardealer() {
+        URL wsdl = getClass().getResource("/wsdl/cardealer.wsdl");
+        assertNotNull("WSDL is null", wsdl);
+
+        CarDealerService service = new CarDealerService(wsdl, serviceName);
+        assertNotNull("Service is null ", service);
+        
+        return service.getCarDealerPort();
+    }
+}

Modified: incubator/cxf/trunk/testutils/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/pom.xml?rev=583338&r1=583337&r2=583338&view=diff
==============================================================================
--- incubator/cxf/trunk/testutils/pom.xml (original)
+++ incubator/cxf/trunk/testutils/pom.xml Tue Oct  9 18:22:05 2007
@@ -369,6 +369,9 @@
                                 <wsdlOption>
                                     <wsdl>${basedir}/src/main/resources/wsdl/inherit.wsdl</wsdl>
                                 </wsdlOption>
+                                <wsdlOption>
+                                    <wsdl>${basedir}/src/main/resources/wsdl/cardealer.wsdl</wsdl>
+                                </wsdlOption>
 
                             </wsdlOptions>
                         </configuration>

Added: incubator/cxf/trunk/testutils/src/main/resources/wsdl/cardealer.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/resources/wsdl/cardealer.wsdl?rev=583338&view=auto
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/resources/wsdl/cardealer.wsdl (added)
+++ incubator/cxf/trunk/testutils/src/main/resources/wsdl/cardealer.wsdl Tue Oct  9 18:22:05 2007
@@ -0,0 +1,114 @@
+<?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.
+-->
+<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
+	     xmlns:tns="http://apache.org/type_substitution/" 
+	     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
+	     xmlns="http://schemas.xmlsoap.org/wsdl/" 
+	     targetNamespace="http://apache.org/type_substitution/" name="CarDealerService">
+    <types>
+	<xsd:schema targetNamespace="http://apache.org/type_substitution/">
+	    <xsd:element name="getSedans" type="tns:getSedans"></xsd:element>
+
+	    <xsd:element name="getSedansResponse" type="tns:getSedansResponse"></xsd:element>
+
+	    <xsd:element name="tradeIn" type="tns:car"></xsd:element>
+
+	    <xsd:element name="tradeInResponse" type="tns:car"></xsd:element>
+
+	    <xsd:complexType name="car" abstract="true">
+		<xsd:sequence>
+		    <xsd:element name="make" type="xsd:string" minOccurs="0"></xsd:element>
+		    <xsd:element name="model" type="xsd:string" minOccurs="0"></xsd:element>
+		    <xsd:element name="year" type="xsd:string" minOccurs="0"></xsd:element>
+		</xsd:sequence>
+	    </xsd:complexType>
+
+	    <xsd:complexType name="porsche">
+		<xsd:complexContent>
+		    <xsd:extension base="tns:car">
+			<xsd:sequence>
+			    <xsd:element name="color" type="xsd:string" minOccurs="0"></xsd:element>
+			</xsd:sequence>
+		    </xsd:extension>
+		</xsd:complexContent>
+	    </xsd:complexType>
+
+	    <xsd:complexType name="getSedans">
+		<xsd:sequence>
+		    <xsd:element name="arg0" type="xsd:string" minOccurs="0"></xsd:element>
+		</xsd:sequence>
+	    </xsd:complexType>
+
+	    <xsd:complexType name="getSedansResponse">
+		<xsd:sequence>
+		    <xsd:element name="return" type="tns:car" nillable="true" minOccurs="0" maxOccurs="unbounded"></xsd:element>
+		</xsd:sequence>
+	    </xsd:complexType>
+	</xsd:schema>
+    </types>
+    <message name="getSedans">
+	<part name="parameters" element="tns:getSedans"></part>
+    </message>
+    <message name="getSedansResponse">
+	<part name="parameters" element="tns:getSedansResponse"></part>
+    </message>
+    <message name="tradeIn">
+	<part name="tradeIn" element="tns:tradeIn"></part>
+    </message>
+    <message name="tradeInResponse">
+	<part name="tradeInResponse" element="tns:tradeInResponse"></part>
+    </message>
+    <portType name="CarDealer">
+	<operation name="getSedans">
+	    <input message="tns:getSedans"></input>
+	    <output message="tns:getSedansResponse"></output>
+	</operation>
+	<operation name="tradeIn">
+	    <input message="tns:tradeIn"></input>
+	    <output message="tns:tradeInResponse"></output>
+	</operation>
+    </portType>
+    <binding name="CarDealerPortBinding" type="tns:CarDealer">
+	<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
+	<operation name="getSedans">
+	    <soap:operation soapAction=""></soap:operation>
+	    <input>
+		<soap:body use="literal"></soap:body>
+	    </input>
+	    <output>
+		<soap:body use="literal"></soap:body>
+	    </output>
+	</operation>
+	<operation name="tradeIn">
+	    <soap:operation soapAction=""></soap:operation>
+	    <input>
+		<soap:body use="literal"></soap:body>
+	    </input>
+	    <output>
+		<soap:body use="literal"></soap:body>
+	    </output>
+	</operation>
+    </binding>
+    <service name="CarDealerService">
+	<port name="CarDealerPort" binding="tns:CarDealerPortBinding">
+	    <soap:address location="http://localhost:9070/jaxws-type_substitution/cardealer"></soap:address>
+	</port>
+    </service>
+</definitions>
\ No newline at end of file