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/05/28 20:50:24 UTC
svn commit: r409976 - in /incubator/tuscany/sandbox/jboynes/sca:
core2/src/main/java/org/apache/tuscany/core/builder/
core2/src/main/java/org/apache/tuscany/core/composite/builder/
core2/src/main/java/org/apache/tuscany/core/wire/ core2/src/test/java/o...
Author: jmarino
Date: Sun May 28 11:50:23 2006
New Revision: 409976
URL: http://svn.apache.org/viewvc?rev=409976&view=rev
Log:
connector and testcase refactorings
Added:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/SourceToTargetConnectTestCase.java
- copied, changed from r409936, incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/ConnectorTestCase.java
Removed:
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/ConnectorTestCase.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/mock/factories/MockWireFactory.java
Modified:
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/composite/builder/CompositeBuilder.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingHandler.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingResponseInterceptor.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/CompositeContext.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeContextExtension.java
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java?rev=409976&r1=409975&r2=409976&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java Sun May 28 11:50:23 2006
@@ -182,6 +182,7 @@
source.setTargetWire(targetWire);
return;
}
+ String serviceName = targetWire.getServiceName();
for (SourceInvocationChain sourceChain : source.getInvocationChains().values()) {
// match wire chains
TargetInvocationChain targetChain = targetInvocationConfigs.get(sourceChain.getMethod());
@@ -190,66 +191,57 @@
e.setIdentifier(source.getReferenceName());
throw e;
}
- // if handlers are configured, add them
- if (targetChain.getRequestHandlers() != null || targetChain.getResponseHandlers() != null) {
- if (targetChain.getRequestHandlers() == null) {
- // the target may not have request handlers, so bridge it on the source
- if (targetChain.getHeadInterceptor() != null) {
- List<MessageHandler> handlers = new ArrayList<MessageHandler>();
- handlers.add(new MessageDispatcher(targetChain.getHeadInterceptor()));
- MessageChannel channel = new MessageChannelImpl(handlers);
- sourceChain.setTargetRequestChannel(channel);
- } else {
- BuilderConfigException e = new BuilderConfigException("Target chain must have an interceptor");
- e.setIdentifier(targetChain.getMethod().getName());
- throw e;
- }
- } else {
- sourceChain.setTargetRequestChannel(new MessageChannelImpl(targetChain
- .getRequestHandlers()));
- }
- sourceChain.setTargetResponseChannel(new MessageChannelImpl(targetChain
- .getResponseHandlers()));
+ if (target instanceof ReferenceContext) {
+ ReferenceContext referenceContext = (ReferenceContext)target;
+ TargetInvoker invoker = referenceContext.createTargetInvoker(serviceName, sourceChain.getMethod());
+ connect(sourceChain,targetChain, invoker);
} else {
- // no handlers, just connect interceptors
- if (targetChain.getHeadInterceptor() == null) {
- BuilderConfigException e = new BuilderConfigException("No chain handler or interceptor for operation");
+ ComponentContext componentContext = (ComponentContext)target;
+ TargetInvoker invoker = componentContext.createTargetInvoker(serviceName, sourceChain.getMethod());
+ connect(sourceChain,targetChain,invoker);
+ }
+ }
+ }
+
+ public void connect(SourceInvocationChain sourceChain, TargetInvocationChain targetChain, TargetInvoker invoker) {
+ // if handlers are configured, add them
+ if (targetChain.getRequestHandlers() != null || targetChain.getResponseHandlers() != null) {
+ if (targetChain.getRequestHandlers() == null) {
+ // the target may not have request handlers, so bridge it on the source
+ if (targetChain.getHeadInterceptor() != null) {
+ List<MessageHandler> handlers = new ArrayList<MessageHandler>();
+ handlers.add(new MessageDispatcher(targetChain.getHeadInterceptor()));
+ MessageChannel channel = new MessageChannelImpl(handlers);
+ sourceChain.setTargetRequestChannel(channel);
+ } else {
+ BuilderConfigException e = new BuilderConfigException("Target chain must have an interceptor");
e.setIdentifier(targetChain.getMethod().getName());
throw e;
}
- if (!(sourceChain.getTailInterceptor() instanceof InvokerInterceptor && targetChain
- .getHeadInterceptor() instanceof InvokerInterceptor)) {
- // check that we do not have the case where the only interceptors are invokers since we just need one
- sourceChain.setTargetInterceptor(targetChain.getHeadInterceptor());
- }
+ } else {
+ sourceChain.setTargetRequestChannel(new MessageChannelImpl(targetChain
+ .getRequestHandlers()));
}
- sourceChain.build();
- }
-
- if (target instanceof ReferenceContext) {
- attachInvoker(targetWire.getServiceName(), source.getInvocationChains().values(), (ReferenceContext) target);
+ sourceChain.setTargetResponseChannel(new MessageChannelImpl(targetChain
+ .getResponseHandlers()));
} else {
- attachInvoker(targetWire.getServiceName(), source.getInvocationChains().values(), (ComponentContext) target);
+ // no handlers, just connect interceptors
+ if (targetChain.getHeadInterceptor() == null) {
+ BuilderConfigException e = new BuilderConfigException("No chain handler or interceptor for operation");
+ e.setIdentifier(targetChain.getMethod().getName());
+ throw e;
+ }
+ if (!(sourceChain.getTailInterceptor() instanceof InvokerInterceptor && targetChain
+ .getHeadInterceptor() instanceof InvokerInterceptor)) {
+ // check that we do not have the case where the only interceptors are invokers since we just need one
+ sourceChain.setTargetInterceptor(targetChain.getHeadInterceptor());
+ }
}
- }
+ sourceChain.build();
+ sourceChain.setTargetInvoker(invoker);
- private void attachInvoker(String serviceName, Collection<SourceInvocationChain> chains, ComponentContext<?> target) {
- for (SourceInvocationChain chain : chains) {
- TargetInvoker invoker = target.createTargetInvoker(serviceName, chain.getMethod());
- // TODO fix cacheable attrivute
- //invoker.setCacheable(cacheable);
- chain.setTargetInvoker(invoker);
- }
}
- private void attachInvoker(String serviceName, Collection<SourceInvocationChain> chains, ReferenceContext<?> target) {
- for (SourceInvocationChain chain : chains) {
- TargetInvoker invoker = target.createTargetInvoker(serviceName, chain.getMethod());
- // TODO fix cacheable attribute
- //invoker.setCacheable(cacheable);
- chain.setTargetInvoker(invoker);
- }
- }
private boolean isOptimizable(Scope pReferrer, Scope pReferee) {
if (pReferrer == Scope.UNDEFINED || pReferee == Scope.UNDEFINED) {
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/composite/builder/CompositeBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/composite/builder/CompositeBuilder.java?rev=409976&r1=409975&r2=409976&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/composite/builder/CompositeBuilder.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/composite/builder/CompositeBuilder.java Sun May 28 11:50:23 2006
@@ -16,21 +16,60 @@
*/
package org.apache.tuscany.core.composite.builder;
-import org.apache.tuscany.spi.model.Component;
-import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.core.context.CompositeContextImpl;
import org.apache.tuscany.spi.builder.BuilderConfigException;
-import org.apache.tuscany.spi.builder.ComponentBuilder;
import org.apache.tuscany.spi.context.ComponentContext;
import org.apache.tuscany.spi.context.CompositeContext;
+import org.apache.tuscany.spi.context.Context;
import org.apache.tuscany.spi.deployer.DeploymentContext;
-import org.apache.tuscany.core.context.CompositeContextImpl;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.model.BoundReference;
+import org.apache.tuscany.spi.model.BoundService;
+import org.apache.tuscany.spi.model.Component;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Reference;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Service;
/**
* @version $Rev$ $Date$
*/
-public class CompositeBuilder implements ComponentBuilder<CompositeImplementation> {
- public ComponentContext build(CompositeContext parent, Component<CompositeImplementation> component, DeploymentContext deploymentContext) throws BuilderConfigException {
+public class CompositeBuilder extends ComponentBuilderExtension<CompositeImplementation> {
+
+ public ComponentContext build(CompositeContext parent,
+ Component<CompositeImplementation> component,
+ DeploymentContext deploymentContext) throws BuilderConfigException {
+ CompositeImplementation implementation = component.getImplementation();
+ CompositeComponentType componentType = implementation.getComponentType();
CompositeContextImpl<?> context = new CompositeContextImpl(component.getName(), parent, null);
+ for (ReferenceTarget target : component.getReferenceTargets().values()) {
+ Reference reference = target.getReference();
+ if (reference instanceof BoundReference) {
+ Context<?> refereceContext = builderRegistry.build(context, (BoundReference) reference,
+ deploymentContext);
+ context.registerContext(refereceContext);
+ }
+ }
+ for (Component<? extends Implementation> child : componentType.getComponents().values()) {
+ Context<?> childContext = builderRegistry.build(context, child, deploymentContext);
+ context.registerContext(childContext);
+ }
+ for (Service service : componentType.getServices().values()) {
+ if (service instanceof BoundService) {
+ Context<?> serviceContext = builderRegistry.build(context, (BoundService) service,
+ deploymentContext);
+ context.registerContext(serviceContext);
+ }
+ }
+ for (Context child : context.getContexts()) {
+ //child.prepare();
+ }
return context;
+ }
+
+ protected Class<CompositeImplementation> getImplementationType() {
+ return CompositeImplementation.class;
}
}
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingHandler.java?rev=409976&r1=409975&r2=409976&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingHandler.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingHandler.java Sun May 28 11:50:23 2006
@@ -4,7 +4,9 @@
import org.apache.tuscany.spi.wire.Message;
/**
- * @version $$Rev$$ $$Date$$
+ * Bridges between handlers in two {@link org.apache.tuscany.spi.wire.TargetInvocationChain}s
+ *
+ * @version $$Rev$$ $$Date$$
*/
public class BridgingHandler implements MessageHandler {
private MessageHandler next;
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java?rev=409976&r1=409975&r2=409976&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java Sun May 28 11:50:23 2006
@@ -4,6 +4,8 @@
import org.apache.tuscany.spi.wire.Message;
/**
+ * Bridges between interceptors in two {@link org.apache.tuscany.spi.wire.TargetInvocationChain}s
+ *
* @version $$Rev$$ $$Date$$
*/
public class BridgingInterceptor implements Interceptor {
@@ -12,7 +14,6 @@
public BridgingInterceptor(Interceptor next) {
this.next = next;
}
-
public Message invoke(Message msg) {
return next.invoke(msg);
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingResponseInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingResponseInterceptor.java?rev=409976&r1=409975&r2=409976&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingResponseInterceptor.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/BridgingResponseInterceptor.java Sun May 28 11:50:23 2006
@@ -5,6 +5,9 @@
import org.apache.tuscany.spi.wire.MessageChannel;
/**
+ * Bridges between two {@link org.apache.tuscany.spi.wire.TargetInvocationChain}s where the destination chain
+ * has an interceptor and response handler chain but no request handlers
+ *
* @version $$Rev$$ $$Date$$
*/
public class BridgingResponseInterceptor implements Interceptor {
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java?rev=409976&r1=409975&r2=409976&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java Sun May 28 11:50:23 2006
@@ -13,11 +13,9 @@
*/
package org.apache.tuscany.core.wire;
-import java.lang.reflect.InvocationTargetException;
-
import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.Message;
import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
import org.apache.tuscany.spi.wire.TargetInvoker;
/**
@@ -38,15 +36,7 @@
if (invoker == null) {
throw new InvocationRuntimeException("No target invoker specified on message");
}
- try {
- Object resp = invoker.invokeTarget(msg.getBody());
- msg.setBody(resp);
- } catch (InvocationTargetException e) {
- msg.setBody(e.getCause());
- } catch (Throwable e) {
- msg.setBody(e);
- }
- return msg;
+ return invoker.invoke(msg);
}
public void setNext(Interceptor next) {
Copied: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/SourceToTargetConnectTestCase.java (from r409936, incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/ConnectorTestCase.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/SourceToTargetConnectTestCase.java?p2=incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/SourceToTargetConnectTestCase.java&p1=incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/ConnectorTestCase.java&r1=409936&r2=409976&rev=409976&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/ConnectorTestCase.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/SourceToTargetConnectTestCase.java Sun May 28 11:50:23 2006
@@ -1,50 +1,45 @@
package org.apache.tuscany.core.builder;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
-import org.apache.tuscany.core.context.event.ModuleStart;
-import org.apache.tuscany.core.context.event.ModuleStop;
-import org.apache.tuscany.core.context.scope.ModuleScopeContext;
-import org.apache.tuscany.core.mock.component.SimpleSource;
import org.apache.tuscany.core.mock.component.SimpleTarget;
-import org.apache.tuscany.core.mock.context.MockAtomicContext;
-import org.apache.tuscany.core.mock.factories.MockWireFactory;
import org.apache.tuscany.core.mock.wire.MockHandler;
import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.SourceInvocationChainImpl;
+import org.apache.tuscany.core.wire.TargetInvocationChainImpl;
import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
import org.apache.tuscany.spi.wire.MessageHandler;
-import org.apache.tuscany.spi.wire.SourceWire;
-import org.apache.tuscany.spi.wire.TargetWire;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.SourceInvocationChain;
+import org.apache.tuscany.spi.wire.TargetInvocationChain;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
/**
+ * Verifies connection strategies between {@link org.apache.tuscany.spi.wire.SourceInvocationChain}s and
+ * {@link org.apache.tuscany.spi.wire.TargetInvocationChain}s
+ *
* @version $$Rev$$ $$Date$$
*/
-public class ConnectorTestCase extends TestCase {
+public class SourceToTargetConnectTestCase extends MockObjectTestCase {
@SuppressWarnings("unchecked")
public void testNoInterceptorsNoHandlers() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, null, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
+ TargetInvocationChain targetChain = setupTarget(null, null, null);
+ SourceInvocationChain sourceChain = setupSource(null, null, null);
+ String[] val = new String[]{"foo"};
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invokeTarget").with(eq(val)).will(returnValue(val));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ assertEquals(val, sourceChain.getTargetInvoker().invokeTarget(val));
}
@@ -54,30 +49,22 @@
@SuppressWarnings("unchecked")
public void testSourceInterceptor() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockSyncInterceptor interceptor = new MockSyncInterceptor();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(interceptor);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, interceptors, null, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
+
+ SourceInvocationChain sourceChain = setupSource(interceptors, null, null);
+ TargetInvocationChain targetChain = setupTarget(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
assertEquals(0, interceptor.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, interceptor.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
}
/**
@@ -86,30 +73,22 @@
@SuppressWarnings("unchecked")
public void testTargetInterceptor() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockSyncInterceptor interceptor = new MockSyncInterceptor();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(interceptor);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, null, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, interceptors, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
+
+ SourceInvocationChain sourceChain = setupSource(null, null, null);
+ TargetInvocationChain targetChain = setupTarget(interceptors, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
assertEquals(0, interceptor.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, interceptor.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
}
/**
@@ -118,35 +97,27 @@
@SuppressWarnings("unchecked")
public void testSourceTargetInterceptor() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext();
- scopeContext.start();
-
MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
List<Interceptor> sourceInterceptors = new ArrayList<Interceptor>();
sourceInterceptors.add(sourceInterceptor);
MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
List<Interceptor> targetInterceptors = new ArrayList<Interceptor>();
targetInterceptors.add(targetInterceptor);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, sourceInterceptors, null, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, targetInterceptors, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
+
+ SourceInvocationChain sourceChain = setupSource(sourceInterceptors, null, null);
+ TargetInvocationChain targetChain = setupTarget(targetInterceptors, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
assertEquals(0, sourceInterceptor.getCount());
assertEquals(0, targetInterceptor.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, sourceInterceptor.getCount());
assertEquals(1, targetInterceptor.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
}
/**
@@ -155,35 +126,27 @@
@SuppressWarnings("unchecked")
public void testSourceInterceptorSourceRequestHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockSyncInterceptor interceptor = new MockSyncInterceptor();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(interceptor);
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, interceptors, handlers, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
+
+ SourceInvocationChain sourceChain = setupSource(interceptors, handlers, null);
+ TargetInvocationChain targetChain = setupTarget(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
assertEquals(0, interceptor.getCount());
assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
- assertEquals(1, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, interceptor.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
+ assertEquals(1, handler.getCount());
}
/**
@@ -192,35 +155,27 @@
@SuppressWarnings("unchecked")
public void testTargetInterceptorTargetRequestHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockSyncInterceptor interceptor = new MockSyncInterceptor();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(interceptor);
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, null, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, interceptors, handlers, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
+
+ SourceInvocationChain sourceChain = setupSource(null, null, null);
+ TargetInvocationChain targetChain = setupTarget(interceptors, handlers, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
assertEquals(0, interceptor.getCount());
assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
- assertEquals(1, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, interceptor.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
+ assertEquals(1, handler.getCount());
}
@@ -230,35 +185,27 @@
@SuppressWarnings("unchecked")
public void testSourceInterceptorSourceResponseHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockSyncInterceptor interceptor = new MockSyncInterceptor();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(interceptor);
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, interceptors, null, handlers);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
+
+ SourceInvocationChain sourceChain = setupSource(interceptors, null, handlers);
+ TargetInvocationChain targetChain = setupTarget(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
assertEquals(0, interceptor.getCount());
assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
- assertEquals(1, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, interceptor.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
+ assertEquals(1, handler.getCount());
}
/**
@@ -267,35 +214,27 @@
@SuppressWarnings("unchecked")
public void testTargetInterceptorTargetResponseHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockSyncInterceptor interceptor = new MockSyncInterceptor();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(interceptor);
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, null, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, interceptors, null, handlers);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
+
+ SourceInvocationChain sourceChain = setupSource(null, null, null);
+ TargetInvocationChain targetChain = setupTarget(interceptors, null, handlers);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
assertEquals(0, interceptor.getCount());
assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
- assertEquals(1, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, interceptor.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
+ assertEquals(1, handler.getCount());
}
/**
@@ -304,35 +243,27 @@
@SuppressWarnings("unchecked")
public void testSourceInterceptorSourceRequestResponseHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockSyncInterceptor interceptor = new MockSyncInterceptor();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(interceptor);
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, interceptors, handlers, handlers);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
+
+ SourceInvocationChain sourceChain = setupSource(interceptors, handlers, handlers);
+ TargetInvocationChain targetChain = setupTarget(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
assertEquals(0, interceptor.getCount());
assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
- assertEquals(2, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, interceptor.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
+ assertEquals(2, handler.getCount());
}
/**
@@ -341,35 +272,27 @@
@SuppressWarnings("unchecked")
public void testTargetInterceptorTargetRequestResponseHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockSyncInterceptor interceptor = new MockSyncInterceptor();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(interceptor);
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, null, handlers);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, interceptors, handlers, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
+
+ SourceInvocationChain sourceChain = setupSource(null, null, handlers);
+ TargetInvocationChain targetChain = setupTarget(interceptors, handlers, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
assertEquals(0, interceptor.getCount());
assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
- assertEquals(2, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, interceptor.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
+ assertEquals(2, handler.getCount());
}
/**
@@ -378,30 +301,22 @@
@SuppressWarnings("unchecked")
public void testSourceRequestResponseHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, handlers, handlers);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
- assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
+
+ SourceInvocationChain sourceChain = setupSource(null, handlers, handlers);
+ TargetInvocationChain targetChain = setupTarget(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(2, handler.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
}
/**
@@ -410,30 +325,22 @@
@SuppressWarnings("unchecked")
public void testTargetRequestResponseHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, null, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, handlers, handlers);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
- assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
+
+ SourceInvocationChain sourceChain = setupSource(null, null, null);
+ TargetInvocationChain targetChain = setupTarget(null, handlers, handlers);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(2, handler.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
}
/**
@@ -442,30 +349,22 @@
@SuppressWarnings("unchecked")
public void testSourceRequestHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, handlers, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
- assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
+
+ SourceInvocationChain sourceChain = setupSource(null, handlers, null);
+ TargetInvocationChain targetChain = setupTarget(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, handler.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
}
/**
@@ -474,30 +373,22 @@
@SuppressWarnings("unchecked")
public void testTargetRequestHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, null, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, handlers, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
- assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
+
+ SourceInvocationChain sourceChain = setupSource(null, null, null);
+ TargetInvocationChain targetChain = setupTarget(null, handlers, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, handler.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
}
/**
@@ -506,30 +397,22 @@
@SuppressWarnings("unchecked")
public void testSourceResponseHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, null, handlers);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, null, null);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
- }
- }
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
- assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
+
+ SourceInvocationChain sourceChain = setupSource(null, null, handlers);
+ TargetInvocationChain targetChain = setupTarget(null, null, null);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
assertEquals(1, handler.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
}
/**
@@ -538,30 +421,82 @@
@SuppressWarnings("unchecked")
public void testTargetResponseHandler() throws Exception {
ConnectorImpl connector = new ConnectorImpl();
- ModuleScopeContext scopeContext = new ModuleScopeContext(null);
- scopeContext.start();
-
MockHandler handler = new MockHandler();
List<MessageHandler> handlers = new ArrayList<MessageHandler>();
handlers.add(handler);
- MockAtomicContext<SimpleSource> sourceContext = MockWireFactory.setupSource(scopeContext, null, null, null);
- MockAtomicContext<SimpleTarget> targetContext = MockWireFactory.setupTarget(scopeContext, null, null, handlers);
- for (List<SourceWire> sourceWires : sourceContext.getSourceWires().values()) {
- for (SourceWire<?> sourceWire : sourceWires) {
- TargetWire<SimpleTarget> targetWire = targetContext.getTargetWire(sourceWire.getTargetName().getPortName());
- connector.connect((SourceWire<SimpleTarget>) sourceWire, targetWire, targetContext, false);
+
+ SourceInvocationChain sourceChain = setupSource(null, null, null);
+ TargetInvocationChain targetChain = setupTarget(null, null, handlers);
+ Message msg = new MessageImpl();
+ Mock mock = mock(TargetInvoker.class);
+ mock.expects(once()).method("invoke").with(eq(msg)).will(returnValue(msg));
+ TargetInvoker invoker = (TargetInvoker) mock.proxy();
+ assertEquals(0, handler.getCount());
+ connector.connect(sourceChain, targetChain, invoker);
+ targetChain.build();
+ msg.setTargetInvoker(sourceChain.getTargetInvoker());
+ assertEquals(msg, sourceChain.getHeadInterceptor().invoke(msg));
+ assertEquals(1, handler.getCount());
+ }
+
+
+ public TargetInvocationChain setupTarget(List<Interceptor> interceptors,
+ List<MessageHandler> requestHandlers,
+ List<MessageHandler> responseHandlers) {
+
+ Method echo;
+ try {
+ echo = SimpleTarget.class.getMethod("echo", String.class);
+ } catch (NoSuchMethodException e) {
+ throw new AssertionError();
+ }
+ TargetInvocationChainImpl chain = new TargetInvocationChainImpl(echo);
+ if (interceptors != null) {
+ for (Interceptor interceptor : interceptors) {
+ chain.addInterceptor(interceptor);
}
}
- targetContext.prepare();
- sourceContext.start();
- targetContext.start();
- scopeContext.onEvent(new ModuleStart(this, null));
- assertEquals(0, handler.getCount());
- SimpleSource source = sourceContext.getService();
- assertEquals("foo", source.getTarget().echo("foo"));
- assertEquals(1, handler.getCount());
- scopeContext.onEvent(new ModuleStop(this, null));
- scopeContext.stop();
+ if (requestHandlers != null) {
+ for (MessageHandler handler : requestHandlers) {
+ chain.addRequestHandler(handler);
+ }
+ }
+ if (responseHandlers != null) {
+ for (MessageHandler handler : responseHandlers) {
+ chain.addResponseHandler(handler);
+ }
+ }
+ chain.addInterceptor(new InvokerInterceptor()); // add tail interceptor
+ return chain;
+ }
+
+ public SourceInvocationChain setupSource(List<Interceptor> interceptors,
+ List<MessageHandler> requestHandlers,
+ List<MessageHandler> responseHandlers) {
+
+ Method echo;
+ try {
+ echo = SimpleTarget.class.getMethod("echo", String.class);
+ } catch (NoSuchMethodException e) {
+ throw new AssertionError();
+ }
+ SourceInvocationChainImpl chain = new SourceInvocationChainImpl(echo);
+ if (interceptors != null) {
+ for (Interceptor interceptor : interceptors) {
+ chain.addInterceptor(interceptor);
+ }
+ }
+ if (requestHandlers != null) {
+ for (MessageHandler handler : requestHandlers) {
+ chain.addRequestHandler(handler);
+ }
+ }
+ if (responseHandlers != null) {
+ for (MessageHandler handler : responseHandlers) {
+ chain.addResponseHandler(handler);
+ }
+ }
+ return chain;
}
}
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/CompositeContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/CompositeContext.java?rev=409976&r1=409975&r2=409976&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/CompositeContext.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/CompositeContext.java Sun May 28 11:50:23 2006
@@ -41,6 +41,11 @@
Context getContext(String name);
/**
+ * Returns the child contexts contained by the composite
+ */
+ List<Context> getContexts();
+
+ /**
* Returns the service contexts contained by the composite
*/
List<ServiceContext> getServiceContexts();
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeContextExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeContextExtension.java?rev=409976&r1=409975&r2=409976&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeContextExtension.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeContextExtension.java Sun May 28 11:50:23 2006
@@ -78,6 +78,10 @@
return children.get(name);
}
+ public List<Context> getContexts() {
+ return Collections.unmodifiableList(new ArrayList<Context>(children.values()));
+ }
+
public List<ServiceContext> getServiceContexts() {
return Collections.unmodifiableList(services);
}
@@ -154,6 +158,12 @@
throw new ContextNotFoundException(serviceName);
}
return ((ServiceContext) context).getTargetWire();
+ }
+
+ public void prepare(){
+ for (Context context : children.values()) {
+ context.prepare();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org