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/02 11:33:17 UTC
svn commit: r491771 - in /incubator/tuscany/java/sca/kernel/core/src:
main/java/org/apache/tuscany/core/builder/
test/java/org/apache/tuscany/core/builder/
Author: jmarino
Date: Tue Jan 2 02:33:16 2007
New Revision: 491771
URL: http://svn.apache.org/viewvc?view=rev&rev=491771
Log:
add assertions to connector; reorganize connector unit tests; add connector unit tests
Added:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java (with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java (with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java (with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java (with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java (with props)
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/WireConnectException.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java?view=diff&rev=491771&r1=491770&r2=491771
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java Tue Jan 2 02:33:16 2007
@@ -106,7 +106,10 @@
postProcessorRegistry.process(sourceWire, targetWire);
}
return;
- } else if (optimizable && sourceWire.getContainer().isSystem() && targetWire.getContainer().isSystem()) {
+ } else if (optimizable && sourceWire.getContainer() != null
+ && sourceWire.getContainer().isSystem()
+ && targetWire.getContainer() != null
+ && targetWire.getContainer().isSystem()) {
// system services are directly wired withut invocation chains
// JFM FIXME test this
sourceWire.setTargetWire(targetWire);
@@ -137,7 +140,9 @@
public void connect(OutboundWire sourceWire, InboundWire targetWire, boolean optimizable)
throws WiringException {
SCAObject source = sourceWire.getContainer();
+ assert source != null;
SCAObject target = targetWire.getContainer();
+ assert target != null;
ServiceContract contract = sourceWire.getServiceContract();
Map<Operation<?>, InboundInvocationChain> targetChains = targetWire.getInvocationChains();
// perform optimization, if possible
@@ -150,7 +155,11 @@
postProcessorRegistry.process(sourceWire, targetWire);
}
return;
- } else if (optimizable && sourceWire.getContainer().isSystem() && targetWire.getContainer().isSystem()) {
+ } else if (optimizable
+ && sourceWire.getContainer() != null
+ && sourceWire.getContainer().isSystem()
+ && targetWire.getContainer() != null
+ && targetWire.getContainer().isSystem()) {
// JFM FIXME test this
sourceWire.setTargetWire(targetWire);
return;
@@ -309,9 +318,11 @@
protected void connect(OutboundInvocationChain sourceChain,
InboundInvocationChain targetChain,
TargetInvoker invoker,
- boolean nonBlocking) {
+ boolean nonBlocking) throws WireConnectException {
Interceptor head = targetChain.getHeadInterceptor();
- assert head != null;
+ if (head == null) {
+ throw new WireConnectException("Inbound chain must contain at least one interceptor");
+ }
if (nonBlocking) {
sourceChain.setTargetInterceptor(new NonBlockingBridgingInterceptor(scheduler, workContext, head));
} else {
@@ -328,9 +339,14 @@
* @param sourceChain the source chain to connect
* @param targetChain the target chain to connect
*/
- protected void connect(InboundInvocationChain sourceChain, OutboundInvocationChain targetChain) {
+ protected void connect(InboundInvocationChain sourceChain, OutboundInvocationChain targetChain)
+ throws WireConnectException {
+ Interceptor head = targetChain.getHeadInterceptor();
+ if (head == null) {
+ throw new WireConnectException("Outbound chain must contain at least one interceptor");
+ }
// invocations from inbound to outbound chains are always synchronous as they occur in services and references
- sourceChain.addInterceptor(new SynchronousBridgingInterceptor(targetChain.getHeadInterceptor()));
+ sourceChain.addInterceptor(new SynchronousBridgingInterceptor(head));
}
/**
@@ -341,6 +357,7 @@
*/
private void handleService(Service service) throws WiringException {
CompositeComponent parent = service.getParent();
+ assert parent != null;
for (ServiceBinding binding : service.getServiceBindings()) {
InboundWire inboundWire = binding.getInboundWire();
OutboundWire outboundWire = binding.getOutboundWire();
@@ -361,6 +378,7 @@
private void handleReference(Reference reference) throws WiringException {
CompositeComponent parent = reference.getParent();
+ assert parent != null;
for (ReferenceBinding binding : reference.getReferenceBindings()) {
InboundWire inboundWire = binding.getInboundWire();
Map<Operation<?>, InboundInvocationChain> inboundChains = inboundWire.getInvocationChains();
@@ -391,7 +409,7 @@
if (binding instanceof LocalReferenceBinding) {
String targetName = outboundWire.getTargetName().getPartName();
String serviceName = outboundWire.getTargetName().getPortName();
- // A reference configured with the local binding is alwaysconnected to a target that is a sibling
+ // A reference configured with the local binding is always connected to a target that is a sibling
// of the reference's parent composite.
parent = parent.getParent();
if (parent == null) {
@@ -402,7 +420,7 @@
serviceName);
}
SCAObject target = parent.getChild(targetName);
- connect(parent, outboundWire, target);
+ connect(reference, outboundWire, target);
}
}
@@ -410,6 +428,7 @@
private void handleAtomic(AtomicComponent sourceComponent) throws WiringException {
CompositeComponent parent = sourceComponent.getParent();
+ assert parent != null;
// connect outbound wires for component references to their targets
for (List<OutboundWire> referenceWires : sourceComponent.getOutboundWires().values()) {
for (OutboundWire outboundWire : referenceWires) {
@@ -569,6 +588,25 @@
targetName.getPartName(),
targetName.getPortName());
}
+ boolean optimizable = isOptimizable(source.getScope(), target.getScope());
+ connect(sourceWire, targetWire, optimizable);
+ } else if (target instanceof Service) {
+ // xcv
+ InboundWire targetWire = null;
+ Service service = (Service) target;
+ for (ServiceBinding binding : service.getServiceBindings()) {
+ InboundWire candidate = binding.getInboundWire();
+ if (sourceWire.getBindingType().equals(candidate.getBindingType())) {
+ targetWire = candidate;
+ break;
+ }
+ }
+ if (targetWire == null) {
+ throw new NoCompatibleBindingsException(source.getName(),
+ targetName.getPartName(),
+ targetName.getPortName());
+ }
+ checkIfWireable(sourceWire, targetWire);
boolean optimizable = isOptimizable(source.getScope(), target.getScope());
connect(sourceWire, targetWire, optimizable);
} else if (target == null) {
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/WireConnectException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/WireConnectException.java?view=diff&rev=491771&r1=491770&r2=491771
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/WireConnectException.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/WireConnectException.java Tue Jan 2 02:33:16 2007
@@ -29,7 +29,11 @@
*/
public class WireConnectException extends WiringException {
- protected WireConnectException(String message,
+ public WireConnectException(String message) {
+ super(message);
+ }
+
+ public WireConnectException(String message,
String sourceName,
String referenceName,
String targetName,
Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java?view=auto&rev=491771
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java Tue Jan 2 02:33:16 2007
@@ -0,0 +1,163 @@
+package org.apache.tuscany.core.builder;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.QualifiedName;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+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.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+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.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractConnectorImplTestCase extends TestCase {
+ protected static final String FOO_SERVICE = "FooService";
+ protected static final QualifiedName FOO_TARGET = new QualifiedName("target/FooService");
+ protected static final String RESPONSE = "response";
+
+ protected ConnectorImpl connector;
+ protected ServiceContract contract;
+ protected Operation<Type> operation;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ connector = new ConnectorImpl();
+ contract = new JavaServiceContract(AbstractConnectorImplTestCase.Foo.class);
+ operation = new Operation<Type>("bar", null, null, null);
+ }
+
+ protected interface Foo {
+ String echo();
+ }
+
+ protected AtomicComponent createAtomicTarget() throws Exception {
+ InboundInvocationChain chain = new InboundInvocationChainImpl(operation);
+ chain.addInterceptor(new InvokerInterceptor());
+ InboundWire targetWire = new InboundWireImpl();
+ targetWire.setServiceContract(contract);
+ targetWire.addInvocationChain(operation, chain);
+
+ // create the target
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(target.isSystem()).andReturn(false).atLeastOnce();
+ target.getInboundWire(EasyMock.eq(FOO_SERVICE));
+ EasyMock.expectLastCall().andReturn(targetWire).atLeastOnce();
+ target.createTargetInvoker(EasyMock.eq(FOO_SERVICE), EasyMock.eq(operation), EasyMock.eq(targetWire));
+ AbstractConnectorImplTestCase.MockInvoker mockInvoker = new AbstractConnectorImplTestCase.MockInvoker();
+ EasyMock.expectLastCall().andReturn(mockInvoker);
+ EasyMock.replay(target);
+ targetWire.setContainer(target);
+ return target;
+ }
+
+ protected AtomicComponent createAtomicSource(CompositeComponent parent) throws Exception {
+ // create the outbound wire and chain from the source component
+ OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
+
+ OutboundWire outboundWire = new OutboundWireImpl();
+ outboundWire.setTargetName(FOO_TARGET);
+ outboundWire.setServiceContract(contract);
+ outboundWire.addInvocationChain(operation, outboundChain);
+
+ Map<String, List<OutboundWire>> outboundWires = new HashMap<String, List<OutboundWire>>();
+ List<OutboundWire> list = new ArrayList<OutboundWire>();
+ list.add(outboundWire);
+ outboundWires.put(FOO_SERVICE, list);
+
+ // create the source
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce();
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce();
+ EasyMock.expect(source.getOutboundWires()).andReturn(outboundWires).atLeastOnce();
+ EasyMock.expect(source.getName()).andReturn("source").atLeastOnce();
+ source.getInboundWires();
+ EasyMock.expectLastCall().andReturn(Collections.emptyList());
+ EasyMock.replay(source);
+
+ outboundWire.setContainer(source);
+ return source;
+ }
+
+ protected static class MockInvoker implements TargetInvoker {
+ public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException {
+ return null;
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ Message resp = new MessageImpl();
+ resp.setBody(RESPONSE);
+ return resp;
+ }
+
+ public boolean isCacheable() {
+ return false;
+ }
+
+ public void setCacheable(boolean cacheable) {
+
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+ }
+
+ protected static class MockInterceptor implements Interceptor {
+ private Interceptor next;
+ private boolean invoked;
+
+ public Message invoke(Message msg) {
+ invoked = true;
+ return next.invoke(msg);
+ }
+
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ public Interceptor getNext() {
+ return next;
+ }
+
+ public boolean isInvoked() {
+ return invoked;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java?view=auto&rev=491771
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java Tue Jan 2 02:33:16 2007
@@ -0,0 +1,108 @@
+package org.apache.tuscany.core.builder;
+
+import org.apache.tuscany.spi.QualifiedName;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.apache.tuscany.core.binding.local.LocalServiceBinding;
+import org.apache.tuscany.core.binding.local.LocalReferenceBinding;
+import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
+import org.apache.tuscany.core.wire.SynchronousBridgingInterceptor;
+import org.apache.tuscany.core.wire.InboundWireImpl;
+import org.apache.tuscany.core.wire.OutboundInvocationChainImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.OutboundWireImpl;
+import org.apache.tuscany.core.implementation.composite.ServiceImpl;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
+
+/**
+ * Verifies various wiring "scenarios" or paths through the connector
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractLocalWiringTestCase extends AbstractConnectorImplTestCase {
+ protected static String TARGET = "target";
+ protected static QualifiedName TARGET_NAME = new QualifiedName(TARGET);
+ protected ReferenceBinding referenceBinding;
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * Creates a service configured with the local binding and places an invoker interceptor on the end of each outbound
+ * chain for invocation testing without needing to wire the service to a target
+ *
+ * @throws org.apache.tuscany.core.builder.WireConnectException
+ */
+ protected Service createLocalService(CompositeComponent parent) throws WireConnectException {
+ LocalServiceBinding serviceBinding = new LocalServiceBinding(TARGET, parent);
+ InboundInvocationChain targetInboundChain = new InboundInvocationChainImpl(operation);
+ targetInboundChain.addInterceptor(new SynchronousBridgingInterceptor());
+ InboundWire targetInboundWire = new InboundWireImpl();
+ targetInboundWire.setServiceContract(contract);
+ targetInboundWire.addInvocationChain(operation, targetInboundChain);
+ targetInboundWire.setContainer(serviceBinding);
+
+ OutboundInvocationChain targetOutboundChain = new OutboundInvocationChainImpl(operation);
+ // place an invoker interceptor on the end
+ targetOutboundChain.addInterceptor(new InvokerInterceptor());
+ OutboundWire targetOutboundWire = new OutboundWireImpl();
+ targetOutboundWire.setServiceContract(contract);
+ targetOutboundWire.addInvocationChain(operation, targetOutboundChain);
+ targetOutboundWire.setContainer(serviceBinding);
+
+ serviceBinding.setInboundWire(targetInboundWire);
+ serviceBinding.setOutboundWire(targetOutboundWire);
+ // manually connect the service chains
+ connector.connect(targetInboundChain, targetOutboundChain);
+ Service service = new ServiceImpl(TARGET, null, contract);
+ service.addServiceBinding(serviceBinding);
+ return service;
+ }
+
+ protected Reference createLocalReference(CompositeComponent parent) throws Exception {
+ ReferenceBinding referenceBinding = createLocalReferenceBinding();
+ Reference reference = new ReferenceImpl("foo", parent, contract);
+ reference.addReferenceBinding(referenceBinding);
+ return reference;
+ }
+
+ protected ReferenceBinding createLocalReferenceBinding()
+ throws TargetInvokerCreationException {
+ referenceBinding = new LocalReferenceBinding("local", null);
+ InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
+ InboundWire inboundWire = new InboundWireImpl();
+ inboundWire.setServiceContract(contract);
+ inboundWire.setContainer(referenceBinding);
+ inboundWire.addInvocationChain(operation, inboundChain);
+
+ OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
+ // Outbound chains always contains at least one interceptor
+ outboundChain.addInterceptor(new SynchronousBridgingInterceptor());
+ OutboundWire outboundWire = new OutboundWireImpl();
+ outboundWire.setServiceContract(contract);
+ outboundWire.setTargetName(TARGET_NAME);
+ outboundWire.addInvocationChain(operation, outboundChain);
+ outboundWire.setContainer(referenceBinding);
+
+ referenceBinding.setInboundWire(inboundWire);
+ referenceBinding.setOutboundWire(outboundWire);
+
+ return referenceBinding;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java?view=auto&rev=491771
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java Tue Jan 2 02:33:16 2007
@@ -0,0 +1,160 @@
+/*
+ * 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.builder;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
+
+import org.apache.tuscany.core.implementation.composite.ServiceImpl;
+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.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AtomicConnectorTestCase extends AbstractConnectorImplTestCase {
+
+ public void testConnectSynchronousServiceWiresToAtomicTarget() throws Exception {
+ AtomicComponent target = createAtomicTarget();
+
+ // create the parent composite
+ CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(parent.getChild("target")).andReturn(target);
+ EasyMock.replay(parent);
+
+ InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
+ InboundWire inboundWire = new InboundWireImpl();
+ inboundWire.addInvocationChain(operation, inboundChain);
+ inboundWire.setServiceContract(contract);
+
+ OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
+ OutboundWire outboundWire = new OutboundWireImpl();
+ outboundWire.setTargetName(FOO_TARGET);
+ outboundWire.addInvocationChain(operation, outboundChain);
+ outboundWire.setServiceContract(contract);
+
+ // create the binding
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ EasyMock.expect(binding.getName()).andReturn("source");
+ binding.setService(EasyMock.isA(Service.class));
+ EasyMock.expect(binding.isSystem()).andReturn(false).atLeastOnce();
+ EasyMock.expect(binding.getInboundWire()).andReturn(inboundWire).atLeastOnce();
+ EasyMock.expect(binding.getOutboundWire()).andReturn(outboundWire);
+ EasyMock.expect(binding.getScope()).andReturn(Scope.SYSTEM);
+ EasyMock.replay(binding);
+
+ outboundWire.setContainer(binding);
+ inboundWire.setContainer(binding);
+
+ Service service = new ServiceImpl("foo", parent, null);
+ service.addServiceBinding(binding);
+
+ connector.connect(service);
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(inboundChain.getTargetInvoker());
+ Message resp = inboundChain.getHeadInterceptor().invoke(msg);
+ assertEquals(RESPONSE, resp.getBody());
+ EasyMock.verify(binding);
+ }
+
+ public void testConnectNonBlockingServiceWiresToAtomicTarget() throws Exception {
+ // JFM FIXME
+ }
+
+ public void testConnectCallbackServiceWiresToAtomicTarget() throws Exception {
+ // JFM FIXME
+ }
+
+ /**
+ * Verifies connecting a wire from an atomic component to a target atomic component with one synchronous operation
+ */
+ public void testConnectAtomicComponentToAtomicComponentSyncWire() throws Exception {
+
+ AtomicComponent target = createAtomicTarget();
+ // create the parent composite
+ CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(parent.getChild("target")).andReturn(target);
+ EasyMock.replay(parent);
+ AtomicComponent source = createAtomicSource(parent);
+ connector.connect(source);
+
+ MessageImpl msg = new MessageImpl();
+ Map<String, List<OutboundWire>> wires = source.getOutboundWires();
+ OutboundWire wire = wires.get(FOO_SERVICE).get(0);
+ OutboundInvocationChain chain = wire.getInvocationChains().get(operation);
+ msg.setTargetInvoker(chain.getTargetInvoker());
+ Message resp = chain.getHeadInterceptor().invoke(msg);
+ assertEquals(RESPONSE, resp.getBody());
+ }
+
+ public void testConnectInboundAtomicComponentWires() throws Exception {
+ CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class);
+ // create the inbound wire and chain
+ InboundInvocationChain chain = new InboundInvocationChainImpl(operation);
+ chain.addInterceptor(new InvokerInterceptor());
+ InboundWire wire = new InboundWireImpl();
+ wire.setServiceContract(contract);
+ wire.addInvocationChain(operation, chain);
+ wire.setServiceName(FOO_SERVICE);
+ List<InboundWire> wires = new ArrayList<InboundWire>();
+ wires.add(wire);
+
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getParent()).andReturn(parent);
+ source.getOutboundWires();
+ EasyMock.expectLastCall().andReturn(Collections.emptyMap());
+ source.getInboundWires();
+ EasyMock.expectLastCall().andReturn(wires);
+ source.createTargetInvoker(EasyMock.eq(FOO_SERVICE), EasyMock.eq(operation), (InboundWire) EasyMock.isNull());
+ EasyMock.expectLastCall().andReturn(new MockInvoker());
+ EasyMock.replay(source);
+
+ wire.setContainer(source);
+
+ connector.connect(source);
+ Message msg = new MessageImpl();
+ msg.setTargetInvoker(chain.getTargetInvoker());
+ Message resp = chain.getHeadInterceptor().invoke(msg);
+ assertEquals(RESPONSE, resp.getBody());
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java?view=diff&rev=491771&r1=491770&r2=491771
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java Tue Jan 2 02:33:16 2007
@@ -18,194 +18,30 @@
*/
package org.apache.tuscany.core.builder;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.tuscany.spi.QualifiedName;
import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.component.Reference;
-import org.apache.tuscany.spi.component.ReferenceBinding;
-import org.apache.tuscany.spi.component.Service;
-import org.apache.tuscany.spi.component.ServiceBinding;
-import org.apache.tuscany.spi.idl.java.JavaServiceContract;
-import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.model.Scope;
-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.Interceptor;
-import org.apache.tuscany.spi.wire.InvocationRuntimeException;
import org.apache.tuscany.spi.wire.Message;
import org.apache.tuscany.spi.wire.MessageImpl;
import org.apache.tuscany.spi.wire.OutboundInvocationChain;
import org.apache.tuscany.spi.wire.OutboundWire;
import org.apache.tuscany.spi.wire.TargetInvoker;
-import junit.framework.TestCase;
-import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
-import org.apache.tuscany.core.implementation.composite.ServiceImpl;
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.apache.tuscany.core.wire.SynchronousBridgingInterceptor;
import org.easymock.EasyMock;
/**
* @version $Rev$ $Date$
*/
-public class ConnectorImplTestCase extends TestCase {
- private static final String FOO_SERVICE = "FooService";
- private static final QualifiedName FOO_TARGET = new QualifiedName("target/FooService");
- private static final String RESPONSE = "response";
-
- private ConnectorImpl connector;
- private ServiceContract contract;
- private Operation<Type> operation;
-
- public void testConnectReferenceWires() throws Exception {
- InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
- InboundWire inboundWire = new InboundWireImpl();
- inboundWire.setServiceContract(contract);
- inboundWire.addInvocationChain(operation, inboundChain);
-
- OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
- outboundChain.addInterceptor(new LoopbackInterceptor());
- OutboundWire outboundWire = new OutboundWireImpl();
- outboundWire.setServiceContract(contract);
- outboundWire.setTargetName(FOO_TARGET);
- outboundWire.addInvocationChain(operation, outboundChain);
-
- ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class);
- referenceBinding.setReference(EasyMock.isA(Reference.class));
- EasyMock.expect(referenceBinding.createTargetInvoker(contract, operation)).andReturn(null);
- EasyMock.expect(referenceBinding.getInboundWire()).andReturn(inboundWire);
- EasyMock.expect(referenceBinding.getOutboundWire()).andReturn(outboundWire);
- EasyMock.expect(referenceBinding.isSystem()).andReturn(false);
- EasyMock.replay(referenceBinding);
- inboundWire.setContainer(referenceBinding);
- outboundWire.setContainer(referenceBinding);
-
- Reference reference = new ReferenceImpl("foo", null, contract);
- reference.addReferenceBinding(referenceBinding);
-
- connector.connect(reference);
-
- EasyMock.verify(referenceBinding);
- Interceptor interceptor = inboundChain.getHeadInterceptor();
- assertTrue(interceptor instanceof SynchronousBridgingInterceptor);
- Message resp = interceptor.invoke(new MessageImpl());
- assertEquals(RESPONSE, resp.getBody());
-
- }
-
- public void testConnectSynchronousServiceWiresToAtomicTarget() throws Exception {
- AtomicComponent target = createAtomicTarget();
-
- // create the parent composite
- CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
- EasyMock.expect(parent.getChild("target")).andReturn(target);
- EasyMock.replay(parent);
-
- InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
- InboundWire inboundWire = new InboundWireImpl();
- inboundWire.addInvocationChain(operation, inboundChain);
- inboundWire.setServiceContract(contract);
-
- OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
- OutboundWire outboundWire = new OutboundWireImpl();
- outboundWire.setTargetName(FOO_TARGET);
- outboundWire.addInvocationChain(operation, outboundChain);
- outboundWire.setServiceContract(contract);
-
- // create the binding
- ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
- EasyMock.expect(binding.getName()).andReturn("source");
- binding.setService(EasyMock.isA(Service.class));
- EasyMock.expect(binding.isSystem()).andReturn(false).atLeastOnce();
- EasyMock.expect(binding.getInboundWire()).andReturn(inboundWire).atLeastOnce();
- EasyMock.expect(binding.getOutboundWire()).andReturn(outboundWire);
- EasyMock.expect(binding.getScope()).andReturn(Scope.SYSTEM);
- EasyMock.replay(binding);
-
- outboundWire.setContainer(binding);
- inboundWire.setContainer(binding);
-
- Service service = new ServiceImpl("foo", parent, null);
- service.addServiceBinding(binding);
-
- connector.connect(service);
- MessageImpl msg = new MessageImpl();
- msg.setTargetInvoker(inboundChain.getTargetInvoker());
- Message resp = inboundChain.getHeadInterceptor().invoke(msg);
- assertEquals(RESPONSE, resp.getBody());
- EasyMock.verify(binding);
- }
-
- public void testConnectNonBlockingServiceWiresToAtomicTarget() throws Exception {
- // JFM FIXME
- }
-
- public void testConnectCallbackServiceWiresToAtomicTarget() throws Exception {
- // JFM FIXME
- }
-
- /**
- * Verifies connecting a wire from an atomic component to a target atomic component with one synchronous operation
- */
- public void testConnectAtomicComponentToAtomicComponentSyncWire() throws Exception {
-
- AtomicComponent target = createAtomicTarget();
- // create the parent composite
- CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
- EasyMock.expect(parent.getChild("target")).andReturn(target);
- EasyMock.replay(parent);
- AtomicComponent source = createAtomicSource(parent);
- connector.connect(source);
-
- MessageImpl msg = new MessageImpl();
- Map<String, List<OutboundWire>> wires = source.getOutboundWires();
- OutboundWire wire = wires.get(FOO_SERVICE).get(0);
- OutboundInvocationChain chain = wire.getInvocationChains().get(operation);
- msg.setTargetInvoker(chain.getTargetInvoker());
- Message resp = chain.getHeadInterceptor().invoke(msg);
- assertEquals(RESPONSE, resp.getBody());
- }
-
- public void testConnectInboundAtomicComponentWires() throws Exception {
- // create the inbound wire and chain
- InboundInvocationChain chain = new InboundInvocationChainImpl(operation);
- chain.addInterceptor(new InvokerInterceptor());
- InboundWire wire = new InboundWireImpl();
- wire.setServiceContract(contract);
- wire.addInvocationChain(operation, chain);
- wire.setServiceName(FOO_SERVICE);
- List<InboundWire> wires = new ArrayList<InboundWire>();
- wires.add(wire);
-
- AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
- EasyMock.expect(source.getParent()).andReturn(null);
- source.getOutboundWires();
- EasyMock.expectLastCall().andReturn(Collections.emptyMap());
- source.getInboundWires();
- EasyMock.expectLastCall().andReturn(wires);
- source.createTargetInvoker(EasyMock.eq(FOO_SERVICE), EasyMock.eq(operation), (InboundWire) EasyMock.isNull());
- EasyMock.expectLastCall().andReturn(new MockInvoker());
- EasyMock.replay(source);
-
- connector.connect(source);
- Message msg = new MessageImpl();
- msg.setTargetInvoker(chain.getTargetInvoker());
- Message resp = chain.getHeadInterceptor().invoke(msg);
- assertEquals(RESPONSE, resp.getBody());
- }
+public class ConnectorImplTestCase extends AbstractConnectorImplTestCase {
public void testConnectTargetNotFound() throws Exception {
CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
@@ -223,186 +59,73 @@
}
public void testOutboundToInboundOptimization() throws Exception {
+ AtomicComponent container = EasyMock.createNiceMock(AtomicComponent.class);
InboundWire inboundWire = new InboundWireImpl();
-
+ inboundWire.setContainer(container);
OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class);
outboundWire.getInvocationChains();
EasyMock.expectLastCall().andReturn(Collections.emptyMap());
outboundWire.setTargetWire(inboundWire);
- EasyMock.expect(outboundWire.getContainer()).andReturn(null);
EasyMock.expect(outboundWire.getServiceContract()).andReturn(null);
+ EasyMock.expect(outboundWire.getContainer()).andReturn(container);
EasyMock.replay(outboundWire);
connector.connect(outboundWire, inboundWire, true);
EasyMock.verify(outboundWire);
}
- public void testOutboundToInboundChainConnect() {
+ public void testOutboundToInboundChainConnect() throws Exception {
TargetInvoker invoker = new MockInvoker();
InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
- inboundChain.addInterceptor(new LoopbackInterceptor());
-
+ inboundChain.addInterceptor(new InvokerInterceptor());
OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
-
connector.connect(outboundChain, inboundChain, invoker, false);
Interceptor interceptor = outboundChain.getHeadInterceptor();
assertTrue(interceptor instanceof SynchronousBridgingInterceptor);
- Message resp = interceptor.invoke(new MessageImpl());
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(new MockInvoker());
+ Message resp = interceptor.invoke(msg);
assertEquals(RESPONSE, resp.getBody());
-
}
- public void testInboundToOutboundChainConnect() {
+ public void testOutboundToInboundChainConnectNoInboundInterceptor() {
+ TargetInvoker invoker = new MockInvoker();
InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
-
OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
- outboundChain.addInterceptor(new LoopbackInterceptor());
+ try {
+ connector.connect(outboundChain, inboundChain, invoker, false);
+ fail();
+ } catch (WireConnectException e) {
+ // expected
+ }
+ }
+ public void testInboundToOutboundChainConnect() throws Exception {
+ InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
+ OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
+ outboundChain.addInterceptor(new InvokerInterceptor());
connector.connect(inboundChain, outboundChain);
Interceptor interceptor = inboundChain.getHeadInterceptor();
assertTrue(interceptor instanceof SynchronousBridgingInterceptor);
- Message resp = interceptor.invoke(new MessageImpl());
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(new MockInvoker());
+ Message resp = interceptor.invoke(msg);
assertEquals(RESPONSE, resp.getBody());
}
- public void testOutboundWireToInboundReferenceTarget() throws Exception {
- AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
- EasyMock.expect(component.getName()).andReturn("foo");
- EasyMock.replay(component);
-
- ReferenceBinding target = EasyMock.createMock(ReferenceBinding.class);
- EasyMock.expect(target.createTargetInvoker(EasyMock.isA(ServiceContract.class), EasyMock.isA(Operation.class)))
- .andReturn(new MockInvoker());
- EasyMock.replay(target);
-
+ public void testInboundToOutboundChainConnectNoOutboundInterceptors() throws Exception {
InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
- inboundChain.addInterceptor(new LoopbackInterceptor());
- InboundWire targetWire = new InboundWireImpl();
- targetWire.setServiceContract(contract);
- targetWire.addInvocationChain(operation, inboundChain);
- targetWire.setContainer(target);
-
- // create the outbound wire and chain from the source component
- OutboundInvocationChain sourceChain = new OutboundInvocationChainImpl(operation);
- OutboundWire sourceWire = new OutboundWireImpl();
- sourceWire.setServiceContract(contract);
- sourceWire.setTargetName(FOO_TARGET);
- sourceWire.addInvocationChain(operation, sourceChain);
- sourceWire.setContainer(component);
-
- connector.connect(sourceWire, targetWire, false);
- Interceptor interceptor = sourceChain.getHeadInterceptor();
- assertTrue(interceptor instanceof SynchronousBridgingInterceptor);
- Message resp = interceptor.invoke(new MessageImpl());
- assertEquals(RESPONSE, resp.getBody());
+ OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
+ try {
+ connector.connect(inboundChain, outboundChain);
+ fail();
+ } catch (WireConnectException e) {
+ // expected
+ }
}
protected void setUp() throws Exception {
super.setUp();
- connector = new ConnectorImpl();
- contract = new JavaServiceContract(Foo.class);
- operation = new Operation<Type>("bar", null, null, null);
- }
-
- private interface Foo {
- String echo();
- }
-
- private AtomicComponent createAtomicTarget() throws Exception {
- InboundInvocationChain chain = new InboundInvocationChainImpl(operation);
- chain.addInterceptor(new InvokerInterceptor());
- InboundWire targetWire = new InboundWireImpl();
- targetWire.setServiceContract(contract);
- targetWire.addInvocationChain(operation, chain);
-
- // create the target
- AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
- EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE);
- EasyMock.expect(target.isSystem()).andReturn(false).atLeastOnce();
- target.getInboundWire(EasyMock.eq(FOO_SERVICE));
- EasyMock.expectLastCall().andReturn(targetWire).atLeastOnce();
- target.createTargetInvoker(EasyMock.eq(FOO_SERVICE), EasyMock.eq(operation), EasyMock.eq(targetWire));
- MockInvoker mockInvoker = new MockInvoker();
- EasyMock.expectLastCall().andReturn(mockInvoker);
- EasyMock.replay(target);
- targetWire.setContainer(target);
- return target;
- }
-
- private AtomicComponent createAtomicSource(CompositeComponent parent) throws Exception {
- // create the outbound wire and chain from the source component
- OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
-
- OutboundWire outboundWire = new OutboundWireImpl();
- outboundWire.setTargetName(FOO_TARGET);
- outboundWire.setServiceContract(contract);
- outboundWire.addInvocationChain(operation, outboundChain);
-
- Map<String, List<OutboundWire>> outboundWires = new HashMap<String, List<OutboundWire>>();
- List<OutboundWire> list = new ArrayList<OutboundWire>();
- list.add(outboundWire);
- outboundWires.put(FOO_SERVICE, list);
-
- // create the source
- AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
- EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce();
- EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
- EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce();
- EasyMock.expect(source.getOutboundWires()).andReturn(outboundWires).atLeastOnce();
- EasyMock.expect(source.getName()).andReturn("source").atLeastOnce();
- source.getInboundWires();
- EasyMock.expectLastCall().andReturn(Collections.emptyList());
- EasyMock.replay(source);
-
- outboundWire.setContainer(source);
- return source;
}
- private static class MockInvoker implements TargetInvoker {
- public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException {
- return null;
- }
-
- public Message invoke(Message msg) throws InvocationRuntimeException {
- Message resp = new MessageImpl();
- resp.setBody(RESPONSE);
- return resp;
- }
-
- public boolean isCacheable() {
- return false;
- }
-
- public void setCacheable(boolean cacheable) {
-
- }
-
- public boolean isOptimizable() {
- return false;
- }
-
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
-
- private static class LoopbackInterceptor implements Interceptor {
- public Message invoke(Message msg) {
- Message resp = new MessageImpl();
- resp.setBody(RESPONSE);
- return resp;
- }
-
- public void setNext(Interceptor next) {
-
- }
-
- public Interceptor getNext() {
- return null;
- }
-
- public boolean isOptimizable() {
- return false;
- }
- }
}
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java?view=diff&rev=491771&r1=491770&r2=491771
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java Tue Jan 2 02:33:16 2007
@@ -21,14 +21,14 @@
import java.util.HashMap;
import java.util.Map;
-import org.apache.tuscany.spi.wire.WirePostProcessorRegistry;
-import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.AtomicComponent;
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 org.apache.tuscany.spi.wire.WirePostProcessorRegistry;
import org.apache.tuscany.spi.wire.WireService;
import junit.framework.TestCase;
@@ -58,7 +58,7 @@
WireService wireService = createMock(WireService.class);
wireService.checkCompatibility((ServiceContract<?>) EasyMock.anyObject(),
(ServiceContract<?>) EasyMock.anyObject(), EasyMock.eq(false));
- expectLastCall().anyTimes();
+ expectLastCall().anyTimes();
replay(wireService);
ConnectorImpl connector = new ConnectorImpl(wireService, registry, null, null);
connector.connect(iwire, owire, false);
@@ -66,10 +66,14 @@
}
public void testOutboundToInboundPostProcessCalled() throws Exception {
- Component source = createNiceMock(Component.class);
+ AtomicComponent source = createNiceMock(AtomicComponent.class);
expect(source.getName()).andReturn("Component");
replay(source);
+ AtomicComponent target = createNiceMock(AtomicComponent.class);
+ expect(target.getName()).andReturn("Component");
+ replay(target);
+
OutboundWire owire = createNiceMock(OutboundWire.class);
EasyMock.expect(owire.getContainer()).andReturn(source);
@@ -80,6 +84,7 @@
replay(owire);
InboundWire iwire = createNiceMock(InboundWire.class);
expect(iwire.getSourceCallbackInvocationChains("Component")).andReturn(chains);
+ EasyMock.expect(iwire.getContainer()).andReturn(target);
replay(iwire);
WirePostProcessorRegistry registry = createMock(WirePostProcessorRegistry.class);
registry.process(EasyMock.eq(owire), EasyMock.eq(iwire));
Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java?view=auto&rev=491771
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java Tue Jan 2 02:33:16 2007
@@ -0,0 +1,59 @@
+package org.apache.tuscany.core.builder;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * Verifies various wiring "scenarios" or paths through the connector
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalReferenceWiringTestCase extends AbstractLocalWiringTestCase {
+ private Service service;
+ private Reference reference;
+
+ /**
+ * Verifies the case where inbound and outbound reference wires are connected followed by the outbound reference
+ * wire being connected to a target. This wiring scenario occurs when a reference is configured with the local
+ * binding.
+ */
+ public void testConnectLocalReferenceBindingToCompositeService() throws Exception {
+ connector.connect(reference);
+ InboundInvocationChain chain = referenceBinding.getInboundWire().getInvocationChains().get(operation);
+ Interceptor interceptor = chain.getHeadInterceptor();
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(new MockInvoker());
+ Message resp = interceptor.invoke(msg);
+ assertEquals(RESPONSE, resp.getBody());
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class);
+ topComposite.getChild(TARGET);
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ return service;
+ }
+ });
+ EasyMock.replay(topComposite);
+
+ CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(parent.getParent()).andReturn(topComposite);
+ EasyMock.replay(parent);
+
+ service = createLocalService(topComposite);
+ reference = createLocalReference(parent);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java?view=auto&rev=491771
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java Tue Jan 2 02:33:16 2007
@@ -0,0 +1,176 @@
+/*
+ * 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.builder;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+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.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
+
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
+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.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceConnectorTestCase extends AbstractConnectorImplTestCase {
+ private AtomicComponent source;
+ private AtomicComponent target;
+ private CompositeComponent parent;
+
+ public void testConnectReferenceWiresNoInboundInterceptors() throws Exception {
+ InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
+ InboundWire inboundWire = new InboundWireImpl();
+ inboundWire.setServiceContract(contract);
+ inboundWire.setContainer(source);
+ inboundWire.addInvocationChain(operation, inboundChain);
+
+ OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
+ // Outbound chains always contains at least one interceptor
+ outboundChain.addInterceptor(new InvokerInterceptor());
+ OutboundWire outboundWire = new OutboundWireImpl();
+ outboundWire.setServiceContract(contract);
+ outboundWire.setTargetName(FOO_TARGET);
+ outboundWire.setContainer(source);
+ outboundWire.addInvocationChain(operation, outboundChain);
+
+ ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class);
+ referenceBinding.setReference(EasyMock.isA(Reference.class));
+ EasyMock.expect(referenceBinding.createTargetInvoker(contract, operation)).andReturn(null);
+ EasyMock.expect(referenceBinding.getInboundWire()).andReturn(inboundWire);
+ EasyMock.expect(referenceBinding.getOutboundWire()).andReturn(outboundWire);
+ EasyMock.expect(referenceBinding.isSystem()).andReturn(false);
+ EasyMock.replay(referenceBinding);
+ inboundWire.setContainer(referenceBinding);
+ outboundWire.setContainer(referenceBinding);
+
+ Reference reference = new ReferenceImpl("foo", parent, contract);
+ reference.addReferenceBinding(referenceBinding);
+
+ connector.connect(reference);
+
+ EasyMock.verify(referenceBinding);
+ Interceptor interceptor = inboundChain.getHeadInterceptor();
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(new MockInvoker());
+ Message resp = interceptor.invoke(msg);
+ assertEquals(RESPONSE, resp.getBody());
+ }
+
+ public void testConnectReferenceWiresWithInboundInterceptors() throws Exception {
+ MockInterceptor inboundInterceptor = new MockInterceptor();
+ InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
+ inboundChain.addInterceptor(inboundInterceptor);
+ InboundWire inboundWire = new InboundWireImpl();
+ inboundWire.setContainer(source);
+ inboundWire.setServiceContract(contract);
+ inboundWire.addInvocationChain(operation, inboundChain);
+
+ OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
+ // Outbound always contains at lease one interceptor
+ outboundChain.addInterceptor(new InvokerInterceptor());
+ OutboundWire outboundWire = new OutboundWireImpl();
+ outboundWire.setServiceContract(contract);
+ outboundWire.setContainer(source);
+ outboundWire.setTargetName(FOO_TARGET);
+ outboundWire.addInvocationChain(operation, outboundChain);
+
+ ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class);
+ referenceBinding.setReference(EasyMock.isA(Reference.class));
+ EasyMock.expect(referenceBinding.createTargetInvoker(contract, operation)).andReturn(null);
+ EasyMock.expect(referenceBinding.getInboundWire()).andReturn(inboundWire);
+ EasyMock.expect(referenceBinding.getOutboundWire()).andReturn(outboundWire);
+ EasyMock.expect(referenceBinding.isSystem()).andReturn(false);
+ EasyMock.replay(referenceBinding);
+ inboundWire.setContainer(referenceBinding);
+ outboundWire.setContainer(referenceBinding);
+
+ Reference reference = new ReferenceImpl("foo", parent, contract);
+ reference.addReferenceBinding(referenceBinding);
+
+ connector.connect(reference);
+
+ EasyMock.verify(referenceBinding);
+ Interceptor interceptor = inboundChain.getHeadInterceptor();
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(new MockInvoker());
+ Message resp = interceptor.invoke(msg);
+ assertEquals(RESPONSE, resp.getBody());
+ assertTrue(inboundInterceptor.isInvoked());
+ }
+
+ public void testOutboundWireToInboundReferenceTarget() throws Exception {
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getName()).andReturn("foo");
+ EasyMock.replay(component);
+
+ ReferenceBinding target = EasyMock.createMock(ReferenceBinding.class);
+ EasyMock.expect(target.createTargetInvoker(EasyMock.isA(ServiceContract.class), EasyMock.isA(Operation.class)))
+ .andReturn(new MockInvoker());
+ EasyMock.replay(target);
+
+ InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
+ inboundChain.addInterceptor(new InvokerInterceptor());
+ InboundWire targetWire = new InboundWireImpl();
+ targetWire.setServiceContract(contract);
+ targetWire.addInvocationChain(operation, inboundChain);
+ targetWire.setContainer(source);
+ targetWire.setContainer(target);
+
+ // create the outbound wire and chain from the source component
+ OutboundInvocationChain sourceChain = new OutboundInvocationChainImpl(operation);
+ OutboundWire sourceWire = new OutboundWireImpl();
+ sourceWire.setServiceContract(contract);
+ sourceWire.setTargetName(FOO_TARGET);
+ sourceWire.addInvocationChain(operation, sourceChain);
+ sourceWire.setContainer(component);
+ sourceWire.setContainer(source);
+
+ connector.connect(sourceWire, targetWire, false);
+ Interceptor interceptor = sourceChain.getHeadInterceptor();
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(new MockInvoker());
+ Message resp = interceptor.invoke(msg);
+ assertEquals(RESPONSE, resp.getBody());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ parent = EasyMock.createNiceMock(CompositeComponent.class);
+ source = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(source);
+ target = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(target);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.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