You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/10/07 10:18:27 UTC

svn commit: r453857 - in /incubator/tuscany/java/sca/kernel: core/src/main/java/org/apache/tuscany/core/wire/jdk/ spi/src/main/java/org/apache/tuscany/spi/model/ spi/src/main/java/org/apache/tuscany/spi/wire/ spi/src/test/java/org/apache/tuscany/spi/wire/

Author: jmarino
Date: Sat Oct  7 01:18:27 2006
New Revision: 453857

URL: http://svn.apache.org/viewvc?view=rev&rev=453857
Log:
create wire service extension and move it to SPI; fix errors in service contract compatibility and add minimal test coverage to verify

Added:
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireServiceExtension.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java   (with props)
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java?view=diff&rev=453857&r1=453856&r2=453857
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java Sat Oct  7 01:18:27 2006
@@ -18,20 +18,15 @@
  */
 package org.apache.tuscany.core.wire.jdk;
 
-import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
-
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.tuscany.core.implementation.composite.CompositeReference;
-import org.apache.tuscany.core.implementation.composite.CompositeService;
-import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
-import org.apache.tuscany.core.wire.InboundWireImpl;
-import org.apache.tuscany.core.wire.InvokerInterceptor;
-import org.apache.tuscany.core.wire.OutboundInvocationChainImpl;
-import org.apache.tuscany.core.wire.OutboundWireImpl;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+
 import org.apache.tuscany.spi.QualifiedName;
 import org.apache.tuscany.spi.annotation.Autowire;
 import org.apache.tuscany.spi.component.Component;
@@ -40,6 +35,7 @@
 import org.apache.tuscany.spi.component.ReferenceNotFoundException;
 import org.apache.tuscany.spi.component.Service;
 import org.apache.tuscany.spi.component.WorkContext;
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
 import org.apache.tuscany.spi.model.ComponentDefinition;
 import org.apache.tuscany.spi.model.ComponentType;
 import org.apache.tuscany.spi.model.CompositeComponentType;
@@ -52,33 +48,36 @@
 import org.apache.tuscany.spi.policy.PolicyBuilderRegistry;
 import org.apache.tuscany.spi.wire.InboundInvocationChain;
 import org.apache.tuscany.spi.wire.InboundWire;
-import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
 import org.apache.tuscany.spi.wire.OutboundInvocationChain;
 import org.apache.tuscany.spi.wire.OutboundWire;
 import org.apache.tuscany.spi.wire.ProxyCreationException;
 import org.apache.tuscany.spi.wire.RuntimeWire;
 import org.apache.tuscany.spi.wire.WireInvocationHandler;
-import org.apache.tuscany.spi.wire.WireService;
-import org.osoa.sca.annotations.Constructor;
-import org.osoa.sca.annotations.Init;
-import org.osoa.sca.annotations.Scope;
+import org.apache.tuscany.spi.wire.WireServiceExtension;
+
+import org.apache.tuscany.core.implementation.composite.CompositeReference;
+import org.apache.tuscany.core.implementation.composite.CompositeService;
+import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
+import org.apache.tuscany.core.wire.InboundWireImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.OutboundInvocationChainImpl;
+import org.apache.tuscany.core.wire.OutboundWireImpl;
 
 /**
+ * the default implementation of a wire service that uses JDK dynamic proxies
+ *
  * @version $$Rev$$ $$Date$$
  */
 @Scope("MODULE")
-public class JDKWireService implements WireService {
-
-    private WorkContext context;
-    //private PolicyBuilderRegistry policyRegistry;
+public class JDKWireService extends WireServiceExtension {
 
     public JDKWireService() {
+        super(null, null);
     }
 
     @Constructor({"workContext", "policyregisty"})
     public JDKWireService(@Autowire WorkContext context, @Autowire PolicyBuilderRegistry policyRegistry) {
-        this.context = context;
-        //this.policyRegistry = policyRegistry;
+        super(context, policyRegistry);
     }
 
     @Init(eager = true)
@@ -205,7 +204,7 @@
             inboundWire.addInvocationChain(operation, chain);
         }
         OutboundWire outboundWire = new OutboundWireImpl();
-        
+
         // [rfeng] Check if the Reference has the binding contract
         ServiceContract<?> bindingContract = reference.getBindingServiceContract();
         if (bindingContract == null) {
@@ -279,7 +278,7 @@
 
     public void createWires(Service service, String targetName, ServiceContract<?> contract) {
         InboundWire inboundWire = new InboundWireImpl();
-        
+
         // [rfeng] Check if the Reference has the binding contract
         ServiceContract<?> bindingContract = service.getBindingServiceContract();
         if (bindingContract == null) {
@@ -291,7 +290,7 @@
             InboundInvocationChain inboundChain = createInboundChain(operation);
             inboundWire.addInvocationChain(operation, inboundChain);
         }
-        
+
         OutboundWire outboundWire = new OutboundWireImpl();
         outboundWire.setServiceContract(contract);
         outboundWire.setTargetName(new QualifiedName(targetName));
@@ -322,80 +321,6 @@
         service.setOutboundWire(outboundWire);
     }
 
-    /**
-     * Compares two operations for wiring compatibility as defined by the SCA
-     * assembly specification, namely: <p/>
-     * <ol>
-     * <li>compatibility for the individual method is defined as compatibility
-     * of the signature, that is method name, input types, and output types MUST
-     * BE the same.
-     * <li>the order of the input and output types also MUST BE the same.
-     * <li>the set of Faults and Exceptions expected by the source MUST BE the
-     * same or be a superset of those specified by the service.
-     * </ol>
-     * 
-     * @param source the source contract to compare
-     * @param target the target contract to compare
-     * @IncompatibleServiceContractException Thrown if the two contracts don't
-     *                                       match
-     */
-    public void checkCompatibility(ServiceContract<?> source, ServiceContract<?> target, boolean ignoreCallback)
-        throws IncompatibleServiceContractException {
-        if (source == target) {
-            // Shortcut for performance
-            return;
-        }
-        if (source.isRemotable() != target.isRemotable()) {
-            IncompatibleServiceContractException ex =
-                new IncompatibleServiceContractException("The remotable settings don't match");
-            ex.addContextName("source.remotable: " + source.isRemotable());
-            ex.addContextName("target.remotable: " + target.isRemotable());
-            throw ex;
-        }
-        if (source.getInteractionScope() != target.getInteractionScope()) {
-            IncompatibleServiceContractException ex =
-                new IncompatibleServiceContractException("The interaction scopes don't match");
-            ex.addContextName("source.interactionScope: " + source.getInteractionScope());
-            ex.addContextName("target.interactionScope: " + target.getInteractionScope());
-            throw ex;
-        }
-
-        for (Operation<?> operation : source.getOperations().values()) {
-            Operation<?> targetOperation = target.getOperations().get(operation.getName());
-            if (targetOperation == null) {
-                IncompatibleServiceContractException ex =
-                    new IncompatibleServiceContractException("A operation is not in the target");
-                ex.addContextName("operation: " + operation.getName());
-                throw ex;
-            }
-            if (!operation.equals(targetOperation)) {
-                IncompatibleServiceContractException ex =
-                    new IncompatibleServiceContractException("A target operation is not compatible");
-                ex.addContextName("operation: " + operation.getName());
-                throw ex;
-            }
-        }
-
-        if (ignoreCallback) {
-            return;
-        }
-        
-        for (Operation<?> operation : source.getCallbackOperations().values()) {
-            Operation<?> targetOperation = target.getCallbackOperations().get(operation.getName());
-            if (targetOperation == null) {
-                IncompatibleServiceContractException ex =
-                    new IncompatibleServiceContractException("A callback operation is not in the target");
-                ex.addContextName("operation: " + operation.getName());
-                throw ex;
-            }
-            if (!operation.equals(targetOperation)) {
-                IncompatibleServiceContractException ex =
-                    new IncompatibleServiceContractException("A target callback operation is not compatible");
-                ex.addContextName("operation: " + operation.getName());
-                throw ex;
-            }
-        }
-    }
 
     private Map<Method, InboundInvocationChain> createInboundMapping(InboundWire wire, Method[] methods)
         throws NoMethodForOperationException {

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java?view=diff&rev=453857&r1=453856&r2=453857
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java Sat Oct  7 01:18:27 2006
@@ -148,6 +148,7 @@
         return result;
     }
 
+    @SuppressWarnings("unchecked")
     public boolean equals(Object o) {
         if (this == o) {
             return true;
@@ -158,19 +159,45 @@
 
         final DataType dataType = (DataType) o;
 
-        if (dataBinding != null ? !dataBinding.equals(dataType.dataBinding) : dataType.dataBinding != null) {
-            return false;
+        if (logical instanceof Class && dataType.logical instanceof Class) {
+            Class<?> logicalClass = (Class<?>) logical;
+            Class<?> targetLogicalClass = (Class<?>) dataType.logical;
+            if (!logicalClass.isAssignableFrom(targetLogicalClass)) {
+                return false;
+            }
+        } else {
+            if (logical != null ? !logical.equals(dataType.logical) : dataType.logical != null) {
+                return false;
+            }
+        }
+        if (physical instanceof Class && dataType.physical instanceof Class) {
+            Class<?> physicalClass = (Class<?>) physical;
+            Class<?> physicalTargetClass = (Class<?>) dataType.physical;
+            if (dataBinding != null
+                && dataType.dataBinding != null
+                && dataBinding.equals(physicalClass.getName())
+                && dataType.dataBinding.equals(physicalTargetClass.getName())) {
+                return physicalClass.isAssignableFrom(physicalTargetClass);
+            }
+            if (!physicalClass.isAssignableFrom(physicalTargetClass)) {
+                return false;
+            }
+            return !(dataBinding != null ? !dataBinding.equals(dataType.dataBinding) : dataType.dataBinding != null);
+
+
         }
-        if (logical != null ? !logical.equals(dataType.logical) : dataType.logical != null) {
+
+        if (dataBinding != null ? !dataBinding.equals(dataType.dataBinding) : dataType.dataBinding != null) {
             return false;
         }
+
         return !(physical != null ? !physical.equals(dataType.physical) : dataType.physical != null);
     }
-    
+
     public String toString() {
         StringBuffer sb = new StringBuffer();
         sb.append(physical).append(" ").append(dataBinding).append(" ").append(logical);
         return sb.toString();
     }
-    
+
 }

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java?view=diff&rev=453857&r1=453856&r2=453857
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java Sat Oct  7 01:18:27 2006
@@ -51,7 +51,7 @@
     private boolean callback;
 
     private String dataBinding;
-    
+
     private boolean wrapperStyle;
     private WrapperInfo wrapper;
 
@@ -264,8 +264,21 @@
             return true;
         }
 
-        if (faultTypes != null ? !faultTypes.equals(operation.faultTypes) : operation.faultTypes != null) {
+        if (faultTypes == null && operation.faultTypes != null) {
             return false;
+        } else if (faultTypes != null
+            && operation.faultTypes != null
+            && faultTypes.size() != 0
+            && operation.faultTypes.size() != 0) {
+            if (faultTypes.size() < operation.faultTypes.size()) {
+                return false;
+            } else {
+                for (int i = 0; i < operation.faultTypes.size(); i++) {
+                    if (!faultTypes.get(i).equals(operation.faultTypes.get(i))) {
+                        return false;
+                    }
+                }
+            }
         }
 
         if (inputType != null ? !inputType.equals(operation.inputType) : operation.inputType != null) {
@@ -300,14 +313,16 @@
 
     /**
      * Returns true if the operation is wrapper style
+     *
      * @return the wrapperStyle
      */
     public boolean isWrapperStyle() {
         return wrapperStyle;
     }
-    
+
     /**
      * Return the Wrapper information for this operation is it's wrapper style
+     *
      * @return The Wrapper
      */
     public WrapperInfo getWrapper() {
@@ -331,5 +346,6 @@
     public void setWrapperStyle(boolean wrapperStyle) {
         this.wrapperStyle = wrapperStyle;
     }
+
 
 }

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java?view=diff&rev=453857&r1=453856&r2=453857
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java Sat Oct  7 01:18:27 2006
@@ -231,4 +231,16 @@
         result = 29 * result + (callbackOperations != null ? callbackOperations.hashCode() : 0);
         return result;
     }
+
+    public String toString() {
+        if (interfaceName != null) {
+            return new StringBuilder().append("ServiceContract[").append(interfaceName).append("]").toString();
+        } else if (interfaceClass != null) {
+            return new StringBuilder().append("ServiceContract[").append(interfaceClass.getName()).append("]")
+                .toString();
+        } else {
+            return super.toString();
+        }
+
+    }
 }

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireServiceExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireServiceExtension.java?view=auto&rev=453857
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireServiceExtension.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireServiceExtension.java Sat Oct  7 01:18:27 2006
@@ -0,0 +1,109 @@
+/*
+ * 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.spi.wire;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.policy.PolicyBuilderRegistry;
+
+/**
+ * Base class for wire service extensions
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class WireServiceExtension implements WireService {
+
+    protected PolicyBuilderRegistry policyRegistry;
+    protected WorkContext context;
+
+    protected WireServiceExtension(WorkContext context, PolicyBuilderRegistry policyRegistry) {
+        this.policyRegistry = policyRegistry;
+        this.context = context;
+    }
+
+    /**
+     * Compares two operations for wiring compatibility as defined by the SCA assembly specification, namely: <p/> <ol>
+     * <li>compatibility for the individual method is defined as compatibility of the signature, that is method name,
+     * input types, and output types MUST BE the same. <li>the order of the input and output types also MUST BE the
+     * same. <li>the set of Faults and Exceptions expected by the source MUST BE the same or be a superset of those
+     * specified by the service. </ol>
+     *
+     * @param source the source contract to compare
+     * @param target the target contract to compare
+     * @throws IncompatibleServiceContractException
+     *          if the two contracts don't match
+     */
+    public void checkCompatibility(ServiceContract<?> source, ServiceContract<?> target, boolean ignoreCallback)
+        throws IncompatibleServiceContractException {
+        if (source == target) {
+            // Shortcut for performance
+            return;
+        }
+        if (source.isRemotable() != target.isRemotable()) {
+            IncompatibleServiceContractException ex =
+                new IncompatibleServiceContractException("The remotable settings don't match");
+            ex.setIdentifier(source.toString() + "," + target.toString());
+            throw ex;
+        }
+        if (source.getInteractionScope() != target.getInteractionScope()) {
+            IncompatibleServiceContractException ex =
+                new IncompatibleServiceContractException("The interaction scopes don't match");
+            ex.setIdentifier(source.toString() + "," + target.toString());
+            throw ex;
+        }
+
+        for (Operation<?> operation : source.getOperations().values()) {
+            Operation<?> targetOperation = target.getOperations().get(operation.getName());
+            if (targetOperation == null) {
+                IncompatibleServiceContractException ex =
+                    new IncompatibleServiceContractException("Operation not found on target");
+                ex.setIdentifier(operation.getName());
+                throw ex;
+            }
+            if (!operation.equals(targetOperation)) {
+                IncompatibleServiceContractException ex =
+                    new IncompatibleServiceContractException("Target operation is not compatible");
+                ex.setIdentifier(operation.getServiceContract().toString() + ":" + operation.getName());
+                throw ex;
+            }
+        }
+
+        if (ignoreCallback) {
+            return;
+        }
+
+        for (Operation<?> operation : source.getCallbackOperations().values()) {
+            Operation<?> targetOperation = target.getCallbackOperations().get(operation.getName());
+            if (targetOperation == null) {
+                IncompatibleServiceContractException ex =
+                    new IncompatibleServiceContractException("Callback operation not found on target");
+                ex.setIdentifier(operation.getName());
+                throw ex;
+            }
+            if (!operation.equals(targetOperation)) {
+                IncompatibleServiceContractException ex =
+                    new IncompatibleServiceContractException("Target callback operation is not compatible");
+                ex.setIdentifier(operation.getName());
+                throw ex;
+            }
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireServiceExtension.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireServiceExtension.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java?view=auto&rev=453857
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java Sat Oct  7 01:18:27 2006
@@ -0,0 +1,365 @@
+package org.apache.tuscany.spi.wire;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContractCompatibilityTestCase extends TestCase {
+
+    private WireService wireService = new MockWireService();
+
+    public void testNoOperation() throws Exception {
+        ServiceContract source = new MockContract<Type>("FooContract");
+        ServiceContract target = new MockContract<Type>("FooContract");
+        wireService.checkCompatibility(source, target, false);
+    }
+
+    public void testBasic() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        Operation<Type> opSource1 = new Operation<Type>("op1", null, null, null, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        Operation<Type> opSource2 = new Operation<Type>("op1", null, null, null, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opSource2);
+        target.setOperations(targetOperations);
+        wireService.checkCompatibility(source, target, false);
+    }
+
+    public void testBasicIncompatibleOperationNames() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        Operation<Type> opSource1 = new Operation<Type>("op1", null, null, null, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        Operation<Type> opSource2 = new Operation<Type>("op2", null, null, null, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op2", opSource2);
+        target.setOperations(targetOperations);
+        try {
+            wireService.checkCompatibility(source, target, false);
+            fail();
+        } catch (IncompatibleServiceContractException e) {
+            //expected
+        }
+    }
+
+    public void testInputTypes() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>();
+        sourceInputTypes.add(new DataType<Type>(Object.class, Object.class));
+        DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes);
+        Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>();
+        targetInputTypes.add(new DataType<Type>(Object.class, Object.class));
+        DataType<List<DataType<Type>>> targetInputType =
+            new DataType<List<DataType<Type>>>(String.class, targetInputTypes);
+
+        Operation<Type> opTarget = new Operation<Type>("op1", targetInputType, null, null, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        wireService.checkCompatibility(source, target, false);
+    }
+
+
+    public void testIncompatibleInputTypes() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>();
+        sourceInputTypes.add(new DataType<Type>(Integer.class, Integer.class));
+        DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes);
+        Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>();
+        targetInputTypes.add(new DataType<Type>(String.class, String.class));
+        DataType<List<DataType<Type>>> targetInputType =
+            new DataType<List<DataType<Type>>>(String.class, targetInputTypes);
+
+        Operation<Type> opTarget = new Operation<Type>("op1", targetInputType, null, null, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        try {
+            wireService.checkCompatibility(source, target, false);
+            fail();
+        } catch (IncompatibleServiceContractException e) {
+            //expected
+        }
+    }
+
+    /**
+     * Verfies source input types can be super types of the target
+     */
+    public void testSourceSuperTypeInputCompatibility() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>();
+        sourceInputTypes.add(new DataType<Type>(Object.class, Object.class));
+        DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes);
+        Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>();
+        targetInputTypes.add(new DataType<Type>(String.class, String.class));
+        DataType<List<DataType<Type>>> targetInputType =
+            new DataType<List<DataType<Type>>>(String.class, targetInputTypes);
+
+        Operation<Type> opTarget = new Operation<Type>("op1", targetInputType, null, null, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        wireService.checkCompatibility(source, target, false);
+    }
+
+    public void testOutputTypes() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        DataType<Type> sourceOutputType = new DataType<Type>(String.class, String.class);
+        Operation<Type> opSource1 = new Operation<Type>("op1", null, sourceOutputType, null, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        DataType<Type> targetOutputType = new DataType<Type>(String.class, String.class);
+        Operation<Type> opTarget = new Operation<Type>("op1", null, targetOutputType, null, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        wireService.checkCompatibility(source, target, false);
+    }
+
+    /**
+     * Verfies a return type that is a supertype of of the target is compatible
+     */
+    public void testSupertypeOutputTypes() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        DataType<Type> sourceOutputType = new DataType<Type>(Object.class, Object.class);
+        Operation<Type> opSource1 = new Operation<Type>("op1", null, sourceOutputType, null, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        DataType<Type> targetOutputType = new DataType<Type>(String.class, String.class);
+        Operation<Type> opTarget = new Operation<Type>("op1", null, targetOutputType, null, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        wireService.checkCompatibility(source, target, false);
+    }
+
+    public void testIncompatibleOutputTypes() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        DataType<Type> sourceOutputType = new DataType<Type>(String.class, String.class);
+        Operation<Type> opSource1 = new Operation<Type>("op1", null, sourceOutputType, null, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        DataType<Type> targetOutputType = new DataType<Type>(Integer.class, Integer.class);
+        Operation<Type> opTarget = new Operation<Type>("op1", null, targetOutputType, null, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        try {
+            wireService.checkCompatibility(source, target, false);
+            fail();
+        } catch (IncompatibleServiceContractException e) {
+            //expected
+        }
+    }
+
+    public void testFaultTypes() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        DataType<Type> sourceFaultType = new DataType<Type>(String.class, String.class);
+        List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+        sourceFaultTypes.add(0, sourceFaultType);
+        Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        DataType<Type> targetFaultType = new DataType<Type>(String.class, String.class);
+        List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>();
+        targetFaultTypes.add(0, targetFaultType);
+
+        Operation<Type> opTarget = new Operation<Type>("op1", null, null, targetFaultTypes, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        wireService.checkCompatibility(source, target, false);
+    }
+
+    public void testSourceFaultTargetNoFaultCompatibility() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        DataType<Type> sourceFaultType = new DataType<Type>(String.class, String.class);
+        List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+        sourceFaultTypes.add(0, sourceFaultType);
+        Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        Operation<Type> opTarget = new Operation<Type>("op1", null, null, null, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        wireService.checkCompatibility(source, target, false);
+    }
+
+    /**
+     * Verifies a source's fault which is a supertype of the target's fault are compatibile
+     *
+     * @throws Exception
+     */
+    public void testFaultSuperTypes() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        DataType<Type> sourceFaultType = new DataType<Type>(Exception.class, Exception.class);
+        List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+        sourceFaultTypes.add(0, sourceFaultType);
+        Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        DataType<Type> targetFaultType = new DataType<Type>(TuscanyException.class, TuscanyException.class);
+        List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>();
+        targetFaultTypes.add(0, targetFaultType);
+
+        Operation<Type> opTarget = new Operation<Type>("op1", null, null, targetFaultTypes, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        wireService.checkCompatibility(source, target, false);
+    }
+
+    /**
+     * Verifies a source's faults which are supertypes and a superset of the target's faults are compatibile
+     */
+    public void testFaultSuperTypesAndSuperset() throws Exception {
+        ServiceContract<Type> source = new MockContract<Type>("FooContract");
+        DataType<Type> sourceFaultType = new DataType<Type>(Exception.class, Exception.class);
+        DataType<Type> sourceFaultType2 = new DataType<Type>(RuntimeException.class, RuntimeException.class);
+        List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+        sourceFaultTypes.add(0, sourceFaultType);
+        sourceFaultTypes.add(1, sourceFaultType2);
+        Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null);
+        Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+        sourceOperations.put("op1", opSource1);
+        source.setOperations(sourceOperations);
+
+        ServiceContract<Type> target = new MockContract<Type>("FooContract");
+        DataType<Type> targetFaultType = new DataType<Type>(TuscanyException.class, TuscanyException.class);
+        List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>();
+        targetFaultTypes.add(0, targetFaultType);
+
+        Operation<Type> opTarget = new Operation<Type>("op1", null, null, targetFaultTypes, false, null);
+        Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+        targetOperations.put("op1", opTarget);
+        target.setOperations(targetOperations);
+        wireService.checkCompatibility(source, target, false);
+    }
+
+    private class MockContract<T> extends ServiceContract<T> {
+        public MockContract() {
+        }
+
+        public MockContract(Class interfaceClass) {
+            super(interfaceClass);
+        }
+
+        public MockContract(String interfaceName) {
+            super(interfaceName);
+        }
+    }
+
+    private class MockWireService extends WireServiceExtension {
+        public MockWireService() {
+            super(null, null);
+        }
+
+        public Object createProxy(RuntimeWire wire) throws ProxyCreationException {
+            throw new UnsupportedOperationException();
+        }
+
+        public Object createCallbackProxy(ServiceContract<?> contract, InboundWire wire) throws ProxyCreationException {
+            throw new UnsupportedOperationException();
+        }
+
+
+        public WireInvocationHandler createHandler(RuntimeWire wire) {
+            throw new UnsupportedOperationException();
+        }
+
+        public WireInvocationHandler createCallbackHandler(InboundWire wire) {
+            throw new UnsupportedOperationException();
+        }
+
+        public OutboundInvocationChain createOutboundChain(Operation<?> operation) {
+            throw new UnsupportedOperationException();
+        }
+
+        public InboundInvocationChain createInboundChain(Operation<?> operation) {
+            throw new UnsupportedOperationException();
+        }
+
+        public InboundWire createWire(ServiceDefinition service) {
+            throw new UnsupportedOperationException();
+        }
+
+        public OutboundWire createWire(ReferenceTarget reference, ReferenceDefinition def) {
+            throw new UnsupportedOperationException();
+        }
+
+        public void createWires(Component component, ComponentDefinition<?> definition) {
+            throw new UnsupportedOperationException();
+        }
+
+        public void createWires(Reference reference, ServiceContract<?> contract) {
+            throw new UnsupportedOperationException();
+        }
+
+        public void createWires(Service service, String targetName, ServiceContract<?> contract) {
+            throw new UnsupportedOperationException();
+        }
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ContractCompatibilityTestCase.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