tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r512758 - in /incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src: main/java/org/apache/tuscany/binding/axis2/ test/java/org/apache/tuscany/binding/axis2/
Date Wed, 28 Feb 2007 14:01:10 GMT
Author: antelder
Date: Wed Feb 28 06:01:09 2007
New Revision: 512758

URL: http://svn.apache.org/viewvc?view=rev&rev=512758
Log:
Fixes and test for WebServiceBindingLoader

Added:
    incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/test/java/org/apache/tuscany/binding/axis2/WebServicebindingLoaderTestCase.java
  (with props)
Modified:
    incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java?view=diff&rev=512758&r1=512757&r2=512758
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java
(original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java
Wed Feb 28 06:01:09 2007
@@ -99,41 +99,38 @@
     }
 
     protected WebServiceBindingDefinition createWSBinding(String wsdlElement, String wsdliLocation,
String uri, DeploymentContext deploymentContext) throws LoaderException {
-        if (wsdlElement == null || wsdlElement.length() < 1) {
-            throw new IllegalArgumentException("missing wsdlElement attribute");
-        }
-        if (wsdlElement.indexOf("#wsdl.") < 1) {
-            throw new IllegalArgumentException("missing '#wsdl.' in wsdlElement attribute");
-        }
-
-        String ns = getWSDLNamespace(wsdlElement);
-
+        String ns = null;
         String serviceName = null;
         String portName = null;
         String bindingName = null;
 
-        String uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.service");
-        if (uriValue != null) {
-            serviceName = uriValue;
-        } else {
-            uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.port");
+        if (wsdlElement != null && wsdlElement.length() > 0) {
+
+            ns = getWSDLNamespace(wsdlElement);
+
+            String uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.service");
             if (uriValue != null) {
-                int i = uriValue.lastIndexOf('/');
-                if (i == -1) {
-                    throw new IllegalArgumentException("Missing '/' seperator between service
and port in wsdl.port() in wsdlElement attribute");
-                } 
-                serviceName = uriValue.substring(0, i);
-                portName = uriValue.substring(i);
+                serviceName = uriValue;
             } else {
-                uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.enpoint");
+                uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.port");
                 if (uriValue != null) {
-                    throw new IllegalArgumentException("WSDL 2.0 not supported for '#wsdl.endpoint'
in wsdlElement attribute");
-                } 
-                uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.binding");
-                if (uriValue == null) {
-                    throw new IllegalArgumentException("missing '#wsdl.service' or '#wsdl.port'
or '#wsdl.endpoint'or '#wsdl.binding' in wsdlElement attribute");
+                    int i = uriValue.lastIndexOf('/');
+                    if (i == -1) {
+                        throw new IllegalArgumentException("Missing '/' seperator between
service and port in wsdl.port() in wsdlElement attribute");
+                    } 
+                    serviceName = uriValue.substring(0, i);
+                    portName = uriValue.substring(i+1);
+                } else {
+                    uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.endpoint");
+                    if (uriValue != null) {
+                        throw new IllegalArgumentException("WSDL 2.0 not supported for '#wsdl.endpoint'
in wsdlElement attribute");
+                    } 
+                    uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.binding");
+                    if (uriValue == null) {
+                        throw new IllegalArgumentException("missing '#wsdl.service' or '#wsdl.port'
or '#wsdl.endpoint'or '#wsdl.binding' in wsdlElement attribute");
+                    }
+                    bindingName = uriValue;
                 }
-                bindingName = uriValue;
             }
         }
 
@@ -155,19 +152,19 @@
     
     protected String getWSDLElementURIValue(String wsdlElement, String type) { 
         String value = null;
-        type = "#" + type + "(";
-        int i = wsdlElement.indexOf(type);
+        String fullType = "#" + type + "(";
+        int i = wsdlElement.indexOf(fullType);
         if (i > -1) {
             int j = wsdlElement.indexOf(')',i);
             if (j < 0) {
-                throw new IllegalArgumentException("missing closing bracket ')' on " + type
+ " in wsdlElement attribute");
+                throw new IllegalArgumentException("missing closing bracket ')' on " + fullType
+ " in wsdlElement attribute");
             }
-            value = wsdlElement.substring(i, j);
+            value = wsdlElement.substring(i + fullType.length(), j);
         }
         return value;
     }
 
-    private String getWSDLNamespace(String wsdlElement) {
+    protected String getWSDLNamespace(String wsdlElement) {
         String ns = null;
         if (wsdlElement != null && wsdlElement.length() > 0) {
             int i = wsdlElement.indexOf('#');

Added: incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/test/java/org/apache/tuscany/binding/axis2/WebServicebindingLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/test/java/org/apache/tuscany/binding/axis2/WebServicebindingLoaderTestCase.java?view=auto&rev=512758
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/test/java/org/apache/tuscany/binding/axis2/WebServicebindingLoaderTestCase.java
(added)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/test/java/org/apache/tuscany/binding/axis2/WebServicebindingLoaderTestCase.java
Wed Feb 28 06:01:09 2007
@@ -0,0 +1,187 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.wsdl.Binding;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
+import org.easymock.EasyMock;
+
+/**
+ * Tests for the WebServicebindingLoader class
+ */
+@SuppressWarnings("deprecation")
+public class WebServicebindingLoaderTestCase extends TestCase {
+
+    public void testCreateWSBinding() throws Exception {
+        WSDLDefinitionRegistry wsdlReg = createMock(WSDLDefinitionRegistry.class);
+        Definition mockDef = createMock(Definition.class);
+        expect(wsdlReg.getDefinition("myNS")).andReturn(mockDef);
+        replay(wsdlReg);
+
+        WebServiceBindingLoader loader = new WebServiceBindingLoader(null, wsdlReg);
+
+        WebServiceBindingDefinition binding = loader.createWSBinding("myNS#wsdl.service(myService)",
null, null, null);
+        assertEquals(mockDef, binding.getWSDLDefinition());
+        
+        EasyMock.verify(wsdlReg);
+    }
+
+    public void testCreateWSBindingWsdlService() throws Exception {
+        WSDLDefinitionRegistry wsdlReg = createMock(WSDLDefinitionRegistry.class);
+        Definition mockDef = createMock(Definition.class);
+
+        Service wsdlService = createMock(Service.class);
+        expect(wsdlService.getQName()).andReturn(new QName("myNS", "myService"));
+
+        Map<String, Service> services = new HashMap<String, Service>();
+        services.put("myService", wsdlService);
+        expect(mockDef.getServices()).andReturn(services);
+
+        expect(wsdlReg.getDefinition("myNS")).andReturn(mockDef);
+
+        replay(wsdlService);
+        replay(wsdlReg);
+        replay(mockDef);
+
+        WebServiceBindingLoader loader = new WebServiceBindingLoader(null, wsdlReg);
+
+        WebServiceBindingDefinition binding = loader.createWSBinding("myNS#wsdl.service(myService)",
null, null, null);
+        assertEquals(mockDef, binding.getWSDLDefinition());
+        
+        assertEquals(wsdlService, binding.getWSDLService());
+
+        EasyMock.verify(wsdlService);
+        EasyMock.verify(wsdlReg);
+        EasyMock.verify(mockDef);
+    }
+
+    public void testCreateWSBindingWsdlPort() throws Exception {
+        WSDLDefinitionRegistry wsdlReg = createMock(WSDLDefinitionRegistry.class);
+        Definition mockDef = createMock(Definition.class);
+
+        Service wsdlService = createMock(Service.class);
+        expect(wsdlService.getQName()).andReturn(new QName("myNS", "myService"));
+
+        Port wsdlPort = createMock(Port.class);
+        expect(wsdlService.getPort("myPort")).andReturn(wsdlPort);
+
+        Map<String, Service> services = new HashMap<String, Service>();
+        services.put("myService", wsdlService);
+        expect(mockDef.getServices()).andReturn(services);
+
+        expect(wsdlReg.getDefinition("myNS")).andReturn(mockDef);
+
+        replay(wsdlService);
+        replay(wsdlReg);
+        replay(mockDef);
+
+        WebServiceBindingLoader loader = new WebServiceBindingLoader(null, wsdlReg);
+
+        WebServiceBindingDefinition binding = loader.createWSBinding("myNS#wsdl.port(myService/myPort)",
null, null, null);
+        assertEquals(mockDef, binding.getWSDLDefinition());
+        
+        assertEquals(wsdlPort, binding.getWSDLPort());
+
+        EasyMock.verify(wsdlService);
+        EasyMock.verify(wsdlReg);
+        EasyMock.verify(mockDef);
+    }
+
+    public void testCreateWSBindingWsdlBinding() throws Exception {
+        WSDLDefinitionRegistry wsdlReg = createMock(WSDLDefinitionRegistry.class);
+        Definition mockDef = createMock(Definition.class);
+
+        Binding wsdlBinding = createMock(Binding.class);
+        QName bindingQN = new QName("myNS", "myBinding");
+        expect(mockDef.getBinding(bindingQN)).andReturn(wsdlBinding);
+
+        expect(wsdlReg.getDefinition("myNS")).andReturn(mockDef);
+
+        replay(wsdlReg);
+        replay(mockDef);
+
+        WebServiceBindingLoader loader = new WebServiceBindingLoader(null, wsdlReg);
+
+        WebServiceBindingDefinition binding = loader.createWSBinding("myNS#wsdl.binding(myBinding)",
null, null, null);
+        assertEquals(mockDef, binding.getWSDLDefinition());
+        
+        assertEquals(wsdlBinding, binding.getBinding());
+
+        EasyMock.verify(wsdlReg);
+        EasyMock.verify(mockDef);
+    }
+
+    public void testGetWSDLElementURIValue() throws Exception {
+        WebServiceBindingLoader loader = new WebServiceBindingLoader(null, null);
+        assertEquals("myValue", loader.getWSDLElementURIValue("myNs#wsdl.foo(myValue)", "wsdl.foo"));
+        assertNull(loader.getWSDLElementURIValue("myNs#wsdl.XXX(myValue)", "wsdl.foo"));
+    }
+
+    public void testBadGetWSDLElementURIValue() throws Exception {
+        WebServiceBindingLoader loader = new WebServiceBindingLoader(null, null);
+        try {
+            loader.getWSDLElementURIValue("myNs#wsdl.foo(myValue", "wsdl.foo");
+            fail();
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    public void testGetWSDLNamespace() throws Exception {
+        WebServiceBindingLoader loader = new WebServiceBindingLoader(null, null);
+        assertEquals("myNS", loader.getWSDLNamespace("myNS#bla"));
+    }
+
+    public void testNullGetWSDLNamespace() throws Exception {
+        WebServiceBindingLoader loader = new WebServiceBindingLoader(null, null);
+        assertNull(loader.getWSDLNamespace(""));
+        assertNull(loader.getWSDLNamespace(null));
+    }
+
+    public void testBadGetWSDLNamespace() throws Exception {
+        WebServiceBindingLoader loader = new WebServiceBindingLoader(null, null);
+        try {
+            loader.getWSDLNamespace("bla");
+            fail();
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        try {
+            loader.getWSDLNamespace("#bla");
+            fail();
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+}

Propchange: incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/test/java/org/apache/tuscany/binding/axis2/WebServicebindingLoaderTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/test/java/org/apache/tuscany/binding/axis2/WebServicebindingLoaderTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message