You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yoko-commits@incubator.apache.org by dm...@apache.org on 2007/05/25 13:34:33 UTC

svn commit: r541641 - in /incubator/yoko/branches/perf: pom.xml src/test/java/org/apache/yoko/bindings/corba/CorbaNestedObjReferenceTest.java src/test/resources/wsdl/NestedObjRef.wsdl

Author: dmiddlem
Date: Fri May 25 06:34:32 2007
New Revision: 541641

URL: http://svn.apache.org/viewvc?view=rev&rev=541641
Log:
Commit for YOKO-366:
* Added beginnning of a separate test for object references nested inside other types (currently 
  just structs)


Added:
    incubator/yoko/branches/perf/src/test/java/org/apache/yoko/bindings/corba/CorbaNestedObjReferenceTest.java   (with props)
    incubator/yoko/branches/perf/src/test/resources/wsdl/NestedObjRef.wsdl   (with props)
Modified:
    incubator/yoko/branches/perf/pom.xml

Modified: incubator/yoko/branches/perf/pom.xml
URL: http://svn.apache.org/viewvc/incubator/yoko/branches/perf/pom.xml?view=diff&rev=541641&r1=541640&r2=541641
==============================================================================
--- incubator/yoko/branches/perf/pom.xml (original)
+++ incubator/yoko/branches/perf/pom.xml Fri May 25 06:34:32 2007
@@ -355,6 +355,26 @@
                         </goals>
                     </execution>
                     <execution>
+                        <id>generate-corba-nested-object-reference-test-java-sources</id>
+                        <phase>process-test-resources</phase>
+                        <configuration>
+                            <testSourceRoot>${basedir}/target/generated/src/test/java</testSourceRoot>
+                            <wsdlOptions>
+                                <wsdlOption>
+                                    <wsdl>
+                                        ${basedir}/src/test/resources/wsdl/NestedObjRef.wsdl
+                                    </wsdl>
+                                    <extraargs>
+                                        <extraarg>-verbose</extraarg>
+                                    </extraargs>
+                                </wsdlOption>
+                            </wsdlOptions>
+                        </configuration>
+                        <goals>
+                            <goal>wsdl2java</goal>
+                        </goals>
+                    </execution>
+                    <execution>
                         <id>generate-corba-exception-test-java-sources</id>
                         <phase>process-test-resources</phase>
                         <configuration>

Added: incubator/yoko/branches/perf/src/test/java/org/apache/yoko/bindings/corba/CorbaNestedObjReferenceTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/branches/perf/src/test/java/org/apache/yoko/bindings/corba/CorbaNestedObjReferenceTest.java?view=auto&rev=541641
==============================================================================
--- incubator/yoko/branches/perf/src/test/java/org/apache/yoko/bindings/corba/CorbaNestedObjReferenceTest.java (added)
+++ incubator/yoko/branches/perf/src/test/java/org/apache/yoko/bindings/corba/CorbaNestedObjReferenceTest.java Fri May 25 06:34:32 2007
@@ -0,0 +1,269 @@
+/**
+ * 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.yoko.bindings.corba;
+
+import java.io.File;
+import java.util.HashMap;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Service;
+
+import org.apache.cxf.jaxb.JAXBUtils;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.cxf.wsdl.EndpointReferenceUtils;
+import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.cxf.wsdl11.WSDLManagerImpl;
+
+import org.apache.schemas.yoko.idl.nestedobjref.Foo;
+import org.apache.schemas.yoko.idl.nestedobjref.FooCORBAService;
+import org.apache.schemas.yoko.idl.nestedobjref.FooFactory;
+import org.apache.schemas.yoko.idl.nestedobjref.FooFactoryCORBAService;
+import org.apache.schemas.yoko.idl.nestedobjref.FooRefStruct;
+
+import junit.framework.TestCase;
+
+public class CorbaNestedObjReferenceTest extends TestCase {
+
+    private final QName OBJECT_PORT_NAME = 
+        new QName("http://schemas.apache.org/yoko/idl/NestedObjRef", "FooCORBAPort"); 
+    
+    private final QName OBJECT_PORT_TYPE = 
+        new QName("http://schemas.apache.org/yoko/idl/NestedObjRef", "Foo"); 
+    
+    private final QName OBJECT_SERVICE_NAME = 
+        new QName("http://schemas.apache.org/yoko/idl/NestedObjRef", "FooCORBAService"); 
+    
+    private final QName INTERFACE_PORT_NAME = 
+        new QName("http://schemas.apache.org/yoko/idl/NestedObjRef", "FooFactoryCORBAPort"); 
+    
+    private final QName INTERFACE_SERVICE_NAME = 
+        new QName("http://schemas.apache.org/yoko/idl/NestedObjRef", "FooFactoryCORBAService"); 
+    
+    private final static String WSDL_LOCATION = "/wsdl/NestedObjRef.wsdl";
+    private final static int MAX_WAIT_COUNT = 15;
+    
+    private static TestServer server;
+    private static boolean testServerReady;
+    private FooFactory client;
+    private URL wsdlUrl;
+
+    public CorbaNestedObjReferenceTest(String arg0) {
+        super(arg0);
+    }
+    
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(CorbaNestedObjReferenceTest.class);
+    }
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+       
+        if (server == null) {
+            server = new TestServer();
+            server.start();
+        }
+
+        int waitCount = 0;
+        // Wait for the server to start if it hasn't already
+        while (waitCount < MAX_WAIT_COUNT && !server.isReady()) {
+            try {
+                Thread.sleep(1000);
+                waitCount++;
+            } catch (Exception ex) {
+                // Consume
+            }
+        }
+
+        if (!server.isReady()) {
+            throw new Exception("Server failed to start in a timely fashion");
+        }
+
+        // Now initialize the client-side
+        try {
+            wsdlUrl = FooFactory.class.getResource(WSDL_LOCATION);
+        } catch (Exception ex) {
+            throw new Exception("Unable to resolve WSDL location");
+        }
+        
+        FooFactoryCORBAService service = 
+            new FooFactoryCORBAService(wsdlUrl, INTERFACE_SERVICE_NAME);
+        client = service.getPort(INTERFACE_PORT_NAME, FooFactory.class);
+
+        if (client == null) {
+            throw new Exception("Unable to create client");
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        server.interrupt();
+
+        try {
+            // Sleep for 3 seconds waiting for the server to shut down
+            Thread.sleep(3000);
+        } catch (Exception ex) {
+            // Move on to check if the server is down
+        }
+
+        if (server.isAlive()) {
+            throw new Exception("Did not terminate test server!");
+        }
+    }
+
+    // TODO: Provide test methods
+    public void testCreateFooRefInStruct() {
+        FooRefStruct ref = client.createFooRefInStruct();
+        //EndpointReferenceType epr = createObjectFromEndpointReferenceType(ref.getRef());
+        EndpointReferenceType epr = ref.getRef();
+
+        assertNotNull(epr.getAddress().getValue());
+
+        QName interfaceName = EndpointReferenceUtils.getInterfaceName(epr);
+        assertTrue(interfaceName.equals(OBJECT_PORT_TYPE));
+
+        String wsdlLocation = EndpointReferenceUtils.getWSDLLocation(epr);
+        assertTrue(wsdlLocation.equals(wsdlUrl.toString()));
+
+        QName serviceName = EndpointReferenceUtils.getServiceName(epr);
+        assertTrue(serviceName.equals(OBJECT_SERVICE_NAME));
+
+        String portName = EndpointReferenceUtils.getPortName(epr);
+        assertTrue(portName.equals(OBJECT_PORT_NAME.getLocalPart()));
+    }
+
+    // Helper methods that can be used throughout the test
+    public EndpointReferenceType createEndpointReferenceType(String name, boolean serverSide) {
+        String corbaAddress = null;
+        // The server and client bindings need to be on two different ORBs since they can't
+        // share.  So we need to make sure that the port numbers are different.
+        if (serverSide) {
+            corbaAddress = "corbaloc::localhost:50000/Server" + name;
+        } else {
+            corbaAddress = "corbaloc::localhost:51000/Client" + name;
+        }
+
+        Object testObj = new FooImpl();
+        Endpoint ep = Endpoint.create("http://schemas.apache.org/yoko/bindings/corba", testObj);
+        String wsdlLocation = getClass().getResource("/wsdl/NestedObjRef.wsdl").toString();
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("javax.xml.ws.wsdl.description", wsdlLocation);
+        ep.setProperties(props);
+        ep.publish(corbaAddress);
+
+        EndpointReferenceType ref =
+            EndpointReferenceUtils.getEndpointReference(wsdlUrl,
+                                                        OBJECT_SERVICE_NAME,
+                                                        OBJECT_PORT_NAME.getLocalPart());
+        EndpointReferenceUtils.setInterfaceName(ref, OBJECT_PORT_TYPE);
+        EndpointReferenceUtils.setAddress(ref, corbaAddress);
+
+        return ref;
+    }
+
+    public Foo createObjectFromEndpointReferenceType(EndpointReferenceType epr) throws Exception {
+            WSDLManager manager = null;
+            manager = new WSDLManagerImpl();
+
+            QName interfaceName = EndpointReferenceUtils.getInterfaceName(epr);
+            String wsdlLocation = EndpointReferenceUtils.getWSDLLocation(epr);
+            QName serviceName = EndpointReferenceUtils.getServiceName(epr);
+            String portName = EndpointReferenceUtils.getPortName(epr);
+
+            QName port = new QName(serviceName.getNamespaceURI(), portName);
+
+            StringBuffer seiName = new StringBuffer();
+            seiName.append("org.apache.schemas.yoko.idl.nestedobjref.");
+            seiName.append(JAXBUtils.nameToIdentifier(interfaceName.getLocalPart(),
+                           JAXBUtils.IdentifierType.INTERFACE));
+
+            Class<?> sei = null;
+            sei = Class.forName(seiName.toString(), true, manager.getClass().getClassLoader());
+
+            Service service = Service.create(wsdlUrl, serviceName);
+            Foo testObj = (Foo)service.getPort(port, sei);
+
+            Map<String, Object> requestContext = ((BindingProvider)testObj).getRequestContext();
+            requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, epr.getAddress().getValue());
+
+            return testObj;
+    }
+    
+    
+    // A small test server for the test case to interact with
+    public class TestServer extends Thread {
+        private boolean serverReady;
+
+        public TestServer() {
+            serverReady = false;
+        }
+
+        public void run() {
+            Object implementor = new FooFactoryImpl();
+            String address = "corbaloc::localhost:50000/NestedObjRefTest";
+            Endpoint ep = Endpoint.create("http://schemas.apache.org/yoko/bindings/corba", implementor);
+            String wsdlLocation = getClass().getResource("/wsdl/NestedObjRef.wsdl").toString();
+            Map<String, Object> props = new HashMap<String, Object>();      
+            props.put("javax.xml.ws.wsdl.description", wsdlLocation);
+            ep.setProperties(props);
+            ep.publish(address);
+
+            serverReady = true;
+        }
+
+        public boolean isReady() {
+            return serverReady;
+        }
+    }
+
+    // A minimal FooFactory implementation to test object references
+    @WebService(portName = "FooFactoryCORBAPort",
+                serviceName = "FooFactoryCORBAService",
+                targetNamespace = "http://schemas.apache.org/yoko/idl/NestedObjRef",
+                endpointInterface = "org.apache.schemas.yoko.idl.nestedobjref.FooFactory")
+    public class FooFactoryImpl implements FooFactory {
+
+        // TODO: Provide methods
+        public FooRefStruct createFooRefInStruct() {
+            FooRefStruct ref = new FooRefStruct();
+            ref.setName("FooRefStruct");
+            EndpointReferenceType epr = createEndpointReferenceType("StructRef", true);
+            ref.setRef(epr);
+            return ref;
+        }
+    }
+    
+    // A minimal Foo implementation to test object references
+    @javax.jws.WebService(portName = "FooCORBAPort",
+                          serviceName = "FooCORBAService",
+                          targetNamespace = "http://schemas.apache.org/yoko/idl/NestedObjRef",
+                          endpointInterface = "org.apache.schemas.yoko.idl.nestedobjref.Foo")
+    public class FooImpl implements Foo {
+
+        public void doBar() {
+        }
+    }
+}

Propchange: incubator/yoko/branches/perf/src/test/java/org/apache/yoko/bindings/corba/CorbaNestedObjReferenceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/branches/perf/src/test/java/org/apache/yoko/bindings/corba/CorbaNestedObjReferenceTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/yoko/branches/perf/src/test/resources/wsdl/NestedObjRef.wsdl
URL: http://svn.apache.org/viewvc/incubator/yoko/branches/perf/src/test/resources/wsdl/NestedObjRef.wsdl?view=auto&rev=541641
==============================================================================
--- incubator/yoko/branches/perf/src/test/resources/wsdl/NestedObjRef.wsdl (added)
+++ incubator/yoko/branches/perf/src/test/resources/wsdl/NestedObjRef.wsdl Fri May 25 06:34:32 2007
@@ -0,0 +1,138 @@
+<?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.
+-->
+<wsdl:definitions targetNamespace="http://schemas.apache.org/yoko/idl/NestedObjRef" xmlns:tns="http://schemas.apache.org/yoko/idl/NestedObjRef" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:corba="http://schemas.apache.org/yoko/bindings/corba" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+  <corba:typeMapping targetNamespace="http://schemas.apache.org/yoko/idl/NestedObjRef/typemap">
+    <corba:object xmlns:ns5="http://www.w3.org/2005/08/addressing" xmlns:ns4="http://schemas.apache.org/yoko/idl/NestedObjRef/typemap" xmlns="http://schemas.apache.org/yoko/idl/NestedObjRef" binding="FooCORBABinding" repositoryID="IDL:Foo:1.0" name="ns4:Foo" type="ns5:EndpointReferenceType" />
+    <corba:struct xmlns:ns4="http://schemas.apache.org/yoko/idl/NestedObjRef" xmlns="http://schemas.apache.org/yoko/idl/NestedObjRef/typemap" repositoryID="IDL:FooRefStruct:1.0" name="FooRefStruct" type="ns4:FooRefStruct">
+      <corba:member name="name" idltype="corba:string" />
+      <corba:member name="ref" idltype="Foo" />
+    </corba:struct>
+  </corba:typeMapping>
+  <wsdl:types>
+    <xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://schemas.apache.org/yoko/idl/NestedObjRef" xmlns="http://schemas.apache.org/yoko/idl/NestedObjRef" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+      <xs:import namespace="http://www.w3.org/2005/08/addressing" schemaLocation="http://www.w3.org/2005/08/addressing/ws-addr.xsd">
+      </xs:import>
+      <xs:element name="doBar">
+        <xs:complexType>
+          <xs:sequence>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+      <xs:element name="doBarResponse">
+        <xs:complexType>
+          <xs:sequence>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+      <xs:element name="FooRef" type="wsa:EndpointReferenceType">
+        <xs:annotation>
+          <xs:appinfo>
+          </xs:appinfo>
+        </xs:annotation>
+      </xs:element>
+      <xs:complexType name="FooRefStruct">
+        <xs:sequence>
+          <xs:element name="name" type="xs:string">
+          </xs:element>
+          <xs:element name="ref" nillable="true" type="wsa:EndpointReferenceType">
+          </xs:element>
+        </xs:sequence>
+      </xs:complexType>
+      <xs:element name="createFooRefInStruct">
+        <xs:complexType>
+          <xs:sequence>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+      <xs:element name="createFooRefInStructResponse">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element name="return" type="FooRefStruct">
+            </xs:element>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+    </xs:schema>
+  </wsdl:types>
+  <wsdl:message name="createFooRefInStructResponse">
+    <wsdl:part name="outparameter" element="tns:createFooRefInStructResponse">
+    </wsdl:part>
+  </wsdl:message>
+  <wsdl:message name="doBarResponse">
+    <wsdl:part name="outparameter" element="tns:doBarResponse">
+    </wsdl:part>
+  </wsdl:message>
+  <wsdl:message name="doBar">
+    <wsdl:part name="inparameter" element="tns:doBar">
+    </wsdl:part>
+  </wsdl:message>
+  <wsdl:message name="createFooRefInStruct">
+    <wsdl:part name="inparameter" element="tns:createFooRefInStruct">
+    </wsdl:part>
+  </wsdl:message>
+  <wsdl:portType name="FooFactory">
+    <wsdl:operation name="createFooRefInStruct">
+      <wsdl:input name="createFooRefInStructRequest" message="tns:createFooRefInStruct">
+    </wsdl:input>
+      <wsdl:output name="createFooRefInStructResponse" message="tns:createFooRefInStructResponse">
+    </wsdl:output>
+    </wsdl:operation>
+  </wsdl:portType>
+  <wsdl:portType name="Foo">
+    <wsdl:operation name="doBar">
+      <wsdl:input name="doBarRequest" message="tns:doBar">
+    </wsdl:input>
+      <wsdl:output name="doBarResponse" message="tns:doBarResponse">
+    </wsdl:output>
+    </wsdl:operation>
+  </wsdl:portType>
+  <wsdl:binding name="FooFactoryCORBABinding" type="tns:FooFactory">
+    <corba:binding repositoryID="IDL:FooFactory:1.0" />
+    <wsdl:operation name="createFooRefInStruct">
+      <corba:operation name="createFooRefInStruct">
+        <corba:return xmlns="http://schemas.apache.org/yoko/idl/NestedObjRef/typemap" name="return" idltype="FooRefStruct" />
+      </corba:operation>
+      <wsdl:input name="createFooRefInStructRequest">
+      </wsdl:input>
+      <wsdl:output name="createFooRefInStructResponse">
+      </wsdl:output>
+    </wsdl:operation>
+  </wsdl:binding>
+  <wsdl:binding name="FooCORBABinding" type="tns:Foo">
+    <corba:binding repositoryID="IDL:Foo:1.0" />
+    <wsdl:operation name="doBar">
+      <corba:operation name="doBar" />
+      <wsdl:input name="doBarRequest">
+      </wsdl:input>
+      <wsdl:output name="doBarResponse">
+      </wsdl:output>
+    </wsdl:operation>
+  </wsdl:binding>
+  <wsdl:service name="FooCORBAService">
+    <wsdl:port name="FooCORBAPort" binding="tns:FooCORBABinding">
+      <corba:address location="corbaloc::localhost:51000/Foo" />
+    </wsdl:port>
+  </wsdl:service>
+  <wsdl:service name="FooFactoryCORBAService">
+    <wsdl:port name="FooFactoryCORBAPort" binding="tns:FooFactoryCORBABinding">
+      <corba:address location="corbaloc::localhost:50000/NestedObjRefTest" />
+    </wsdl:port>
+  </wsdl:service>
+</wsdl:definitions>

Propchange: incubator/yoko/branches/perf/src/test/resources/wsdl/NestedObjRef.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/branches/perf/src/test/resources/wsdl/NestedObjRef.wsdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/yoko/branches/perf/src/test/resources/wsdl/NestedObjRef.wsdl
------------------------------------------------------------------------------
    svn:mime-type = text/xml