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 2007/01/03 17:41:17 UTC

svn commit: r492207 - in /incubator/tuscany/java/sca/kernel/core/src: main/java/org/apache/tuscany/core/databinding/impl/ test/java/org/apache/tuscany/core/databinding/impl/

Author: jmarino
Date: Wed Jan  3 08:41:17 2007
New Revision: 492207

URL: http://svn.apache.org/viewvc?view=rev&rev=492207
Log:
modify databinding post processor to not interpose an interceptor in a chain where the source and target have undefined databinding types; add missing version tags

Added:
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java   (with props)
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessor.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java?view=diff&rev=492207&r1=492206&r2=492207
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java Wed Jan  3 08:41:17 2007
@@ -32,6 +32,8 @@
 
 /**
  * An interceptor to transform data accross databindings on the wire
+ *
+ * @version $Rev$ $Date$
  */
 public class DataBindingInteceptor implements Interceptor {
     private Interceptor next;
@@ -44,8 +46,7 @@
 
     private Mediator mediator;
 
-    public DataBindingInteceptor(Wire sourceWire, Operation<?> sourceOperation, Wire targetWire,
-                                 Operation<?> targetOperation) {
+    public DataBindingInteceptor(Wire sourceWire, Operation<?> sourceOperation, Operation<?> targetOperation) {
         super();
         // this.sourceWire = sourceWire;
         this.sourceOperation = sourceOperation;

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessor.java?view=diff&rev=492207&r1=492206&r2=492207
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessor.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessor.java Wed Jan  3 08:41:17 2007
@@ -58,13 +58,16 @@
                 getTargetOperation(target.getInvocationChains().keySet(), sourceOperation.getName());
             String sourceDataBinding = sourceOperation.getDataBinding();
             String targetDataBinding = targetOperation.getDataBinding();
+            if (sourceDataBinding == null && targetDataBinding == null) {
+                continue;
+            }
             if (sourceDataBinding == null || targetDataBinding == null
                 || !sourceDataBinding.equals(targetDataBinding)) {
                 // Add the interceptor to the source side because multiple
                 // references can be wired
                 // to the same service
                 DataBindingInteceptor interceptor =
-                    new DataBindingInteceptor(source, sourceOperation, target, targetOperation);
+                    new DataBindingInteceptor(source, sourceOperation, targetOperation);
                 interceptor.setMediator(mediator);
                 entry.getValue().addInterceptor(0, interceptor);
             }
@@ -89,13 +92,16 @@
                     .getName());
             String sourceDataBinding = sourceOperation.getDataBinding();
             String targetDataBinding = targetOperation.getDataBinding();
+            if (sourceDataBinding == null && targetDataBinding == null) {
+                continue;
+            }
             if (sourceDataBinding == null || targetDataBinding == null
                 || !sourceDataBinding.equals(targetDataBinding)) {
                 // Add the interceptor to the source side because multiple
                 // references can be wired
                 // to the same service
                 DataBindingInteceptor interceptor =
-                    new DataBindingInteceptor(source, sourceOperation, target, targetOperation);
+                    new DataBindingInteceptor(source, sourceOperation, targetOperation);
                 interceptor.setMediator(mediator);
                 entry.getValue().addInterceptor(0, interceptor);
             }
@@ -114,11 +120,14 @@
                 getTargetOperation(target.getInvocationChains().keySet(), sourceOperation.getName());
             String sourceDataBinding = sourceOperation.getDataBinding();
             String targetDataBinding = targetOperation.getDataBinding();
+            if (sourceDataBinding == null && targetDataBinding == null) {
+                continue;
+            }
             if (sourceDataBinding == null || targetDataBinding == null
                 || !sourceDataBinding.equals(targetDataBinding)) {
                 // Add the interceptor to the source side
                 DataBindingInteceptor interceptor =
-                    new DataBindingInteceptor(source, sourceOperation, target, targetOperation);
+                    new DataBindingInteceptor(source, sourceOperation, targetOperation);
                 interceptor.setMediator(mediator);
                 if (isReference) {
                     // FIXME: We need a better way to position the interceptors

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java?view=diff&rev=492207&r1=492206&r2=492207
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java Wed Jan  3 08:41:17 2007
@@ -19,8 +19,6 @@
 
 package org.apache.tuscany.core.databinding.impl;
 
-import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -30,6 +28,7 @@
 import org.apache.tuscany.spi.databinding.Mediator;
 import org.apache.tuscany.spi.model.DataType;
 import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
 import org.apache.tuscany.spi.wire.InboundWire;
 import org.apache.tuscany.spi.wire.Interceptor;
 import org.apache.tuscany.spi.wire.Message;
@@ -44,17 +43,9 @@
 import static org.easymock.EasyMock.replay;
 
 /**
- * 
+ * @version $Rev$ $Date$
  */
 public class DataBindingInterceptorTestCase extends TestCase {
-    private DataBindingInteceptor interceptor;
-
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception {
-        super.setUp();
-    }
 
     @SuppressWarnings("unchecked")
     public final void testInvoke() {
@@ -88,7 +79,7 @@
         EasyMock.expect(outboundWire.getContainer()).andReturn(component);
         EasyMock.replay(outboundWire, inboundWire, composite, component);
 
-        interceptor = new DataBindingInteceptor(outboundWire, operation1, inboundWire, operation2);
+        DataBindingInteceptor interceptor = new DataBindingInteceptor(outboundWire, operation1, operation2);
         Mediator mediator = createMock(Mediator.class);
         Object[] source = new Object[]{"<foo>bar</foo>"};
         Foo foo = new Foo();
@@ -120,6 +111,10 @@
         String result = (String) msg.getBody();
         Assert.assertEquals(source[0], result);
         EasyMock.verify(mediator, msg, next);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
     }
 
     private static class Foo {

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java?view=auto&rev=492207
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java Wed Jan  3 08:41:17 2007
@@ -0,0 +1,111 @@
+/*
+ * 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.core.databinding.impl;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies that data binding interceptor is not added to invocation chains when the data binding types are not set on
+ * service contracts
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingWirePostProcessorOptimizationTestCase extends TestCase {
+    private DataBindingWirePostProcessor processor;
+    private OutboundInvocationChain outboundChain;
+    private OutboundWire outboundWire;
+    private InboundInvocationChain inboundChain;
+    private InboundWire inboundWire;
+
+    public void testNoInterceptorInterposedOutboundToInbound() {
+        processor.process(outboundWire, inboundWire);
+        EasyMock.verify(outboundChain);
+        EasyMock.verify(inboundChain);
+        EasyMock.verify(outboundWire);
+        EasyMock.verify(inboundWire);
+    }
+
+    public void testNoInterceptorInterposedInboundToOutbound() {
+        processor.process(inboundWire, outboundWire);
+        EasyMock.verify(outboundChain);
+        EasyMock.verify(inboundChain);
+        EasyMock.verify(outboundWire);
+        EasyMock.verify(inboundWire);
+    }
+
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        SCAObject container = EasyMock.createMock(SCAObject.class);
+        EasyMock.expect(container.getName()).andReturn("foo");
+        EasyMock.replay(container);
+
+        Mediator mediator = new MediatorImpl();
+        processor = new DataBindingWirePostProcessor(mediator);
+
+        ServiceContract<Type> contract = new JavaServiceContract(null);
+        Operation<Type> operation = new Operation<Type>("test", null, null, null);
+        operation.setServiceContract(contract);
+        Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+        operations.put("test", operation);
+        contract.setOperations(operations);
+        contract.setCallbackOperations(operations);
+
+        inboundChain = EasyMock.createMock(InboundInvocationChain.class);
+        EasyMock.replay(inboundChain);
+        Map<Operation<?>, InboundInvocationChain> inboundChains = new HashMap<Operation<?>, InboundInvocationChain>();
+        inboundChains.put(operation, inboundChain);
+
+        outboundChain = EasyMock.createMock(OutboundInvocationChain.class);
+        EasyMock.replay(outboundChain);
+        Map<Operation<?>, OutboundInvocationChain> outboundChains =
+            new HashMap<Operation<?>, OutboundInvocationChain>();
+        outboundChains.put(operation, outboundChain);
+
+        outboundWire = EasyMock.createMock(OutboundWire.class);
+        EasyMock.expect(outboundWire.getInvocationChains()).andReturn(outboundChains);
+        EasyMock.expect(outboundWire.getServiceContract()).andReturn(contract).anyTimes();
+        EasyMock.expect(outboundWire.getContainer()).andReturn(container).anyTimes();
+        EasyMock.expect(outboundWire.getTargetCallbackInvocationChains()).andReturn(inboundChains).anyTimes();
+        EasyMock.replay(outboundWire);
+
+        inboundWire = EasyMock.createMock(InboundWire.class);
+        EasyMock.expect(inboundWire.getInvocationChains()).andReturn(inboundChains);
+        EasyMock.expect(inboundWire.getContainer()).andReturn(container).anyTimes();
+        EasyMock.expect(inboundWire.getSourceCallbackInvocationChains(EasyMock.eq("foo"))).andReturn(outboundChains)
+            .anyTimes();
+        EasyMock.replay(inboundWire);
+
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java?view=diff&rev=492207&r1=492206&r2=492207
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java Wed Jan  3 08:41:17 2007
@@ -19,9 +19,6 @@
 
 package org.apache.tuscany.core.databinding.impl;
 
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -29,7 +26,7 @@
 import java.util.List;
 import java.util.Map;
 
-import junit.framework.TestCase;
+import org.w3c.dom.Node;
 
 import org.apache.tuscany.spi.component.Component;
 import org.apache.tuscany.spi.component.CompositeComponent;
@@ -45,11 +42,14 @@
 import org.apache.tuscany.spi.wire.Interceptor;
 import org.apache.tuscany.spi.wire.OutboundInvocationChain;
 import org.apache.tuscany.spi.wire.OutboundWire;
+
+import junit.framework.TestCase;
 import org.easymock.EasyMock;
-import org.w3c.dom.Node;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
 
 /**
- * 
+ * @version $Rev$ $Date$
  */
 public class DataBindingWirePostProcessorTestCase extends TestCase {
     private DataBindingWirePostProcessor processor;
@@ -88,7 +88,7 @@
         OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class);
         outboundChains.put(op1, outboundChain);
         expect(outboundWire.getInvocationChains()).andReturn(outboundChains);
-        outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor)EasyMock.anyObject());
+        outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject());
 
         Map<Operation<?>, InboundInvocationChain> inboundChains =
             new HashMap<Operation<?>, InboundInvocationChain>();
@@ -142,7 +142,7 @@
         OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class);
         outboundChains.put(op1, outboundChain);
         expect(outboundWire.getInvocationChains()).andReturn(outboundChains).anyTimes();
-        outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor)EasyMock.anyObject());
+        outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject());
 
         Map<Operation<?>, InboundInvocationChain> inboundChains =
             new HashMap<Operation<?>, InboundInvocationChain>();
@@ -216,7 +216,7 @@
         InboundInvocationChain inboundChain = createMock(InboundInvocationChain.class);
         inboundChains.put(op2, inboundChain);
         expect(inboundWire.getInvocationChains()).andReturn(inboundChains).anyTimes();
-        inboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor)EasyMock.anyObject());
+        inboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject());
 
         ServiceContract<Type> contract = new JavaServiceContract();
         Map<String, Operation<Type>> operations = Collections.emptyMap();



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