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 14:55:25 UTC
svn commit: r491795 - 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 05:55:23 2007
New Revision: 491795
URL: http://svn.apache.org/viewvc?view=rev&rev=491795
Log:
connector test cases
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.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=491795&r1=491794&r2=491795
==============================================================================
--- 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 05:55:23 2007
@@ -158,7 +158,7 @@
} else if (optimizable
&& sourceWire.getContainer() != null
&& sourceWire.getContainer().isSystem()
- && targetWire.getContainer() != null
+ && targetWire.getContainer() != null
&& targetWire.getContainer().isSystem()) {
// JFM FIXME test this
sourceWire.setTargetWire(targetWire);
@@ -413,7 +413,7 @@
// of the reference's parent composite.
parent = parent.getParent();
if (parent == null) {
- throw new TargetServiceNotFoundException("Reference target not found",
+ throw new TargetServiceNotFoundException("Reference target parent not found",
reference.getName(),
null,
targetName,
@@ -527,56 +527,50 @@
InboundWire targetWire = null;
// target is a composite service, connect to it
if (source.isSystem()) {
- for (Object child : composite.getSystemChildren()) {
- if (child instanceof Service) {
- Service service = (Service) child;
- 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());
- }
- Class<?> sourceInterface = sourceWire.getServiceContract().getInterfaceClass();
- Class<?> targetInterface = targetWire.getServiceContract().getInterfaceClass();
- if (sourceInterface.isAssignableFrom(targetInterface)) {
- target = service;
+ Service service = composite.getSystemService(targetName.getPortName());
+ if (service != null) {
+ for (ServiceBinding binding : service.getServiceBindings()) {
+ InboundWire candidate = binding.getInboundWire();
+ if (sourceWire.getBindingType().equals(candidate.getBindingType())) {
+ targetWire = candidate;
break;
- } else {
- targetWire = null;
}
}
+ if (targetWire == null) {
+ throw new NoCompatibleBindingsException(source.getName(),
+ targetName.getPartName(),
+ targetName.getPortName());
+ }
+ Class<?> sourceInterface = sourceWire.getServiceContract().getInterfaceClass();
+ Class<?> targetInterface = targetWire.getServiceContract().getInterfaceClass();
+ if (sourceInterface.isAssignableFrom(targetInterface)) {
+ target = service;
+ } else {
+ targetWire = null;
+ }
}
} else {
- for (Object child : composite.getChildren()) {
- if (child instanceof Service) {
- Service service = (Service) child;
- 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());
- }
- Class<?> sourceInterface = sourceWire.getServiceContract().getInterfaceClass();
- Class<?> targetInterface = targetWire.getServiceContract().getInterfaceClass();
- if (sourceInterface.isAssignableFrom(targetInterface)) {
- target = service;
+ Service service = composite.getService(targetName.getPortName());
+ if (service != null) {
+ for (ServiceBinding binding : service.getServiceBindings()) {
+ InboundWire candidate = binding.getInboundWire();
+ if (sourceWire.getBindingType().equals(candidate.getBindingType())) {
+ targetWire = candidate;
break;
- } else {
- targetWire = null;
}
}
+ if (targetWire == null) {
+ throw new NoCompatibleBindingsException(source.getName(),
+ targetName.getPartName(),
+ targetName.getPortName());
+ }
+ Class<?> sourceInterface = sourceWire.getServiceContract().getInterfaceClass();
+ Class<?> targetInterface = targetWire.getServiceContract().getInterfaceClass();
+ if (sourceInterface.isAssignableFrom(targetInterface)) {
+ target = service;
+ } else {
+ targetWire = null;
+ }
}
}
if (targetWire == null) {
@@ -591,7 +585,6 @@
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()) {
Modified: 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=diff&rev=491795&r1=491794&r2=491795
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java Tue Jan 2 05:55:23 2007
@@ -37,8 +37,10 @@
* @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 TARGET = "target";
+ protected static final QualifiedName TARGET_NAME = new QualifiedName(TARGET);
+ protected static final String TARGET_SERVICE = "FooService";
+ protected static final QualifiedName TARGET_SERVICE_NAME = new QualifiedName("target/FooService");
protected static final String RESPONSE = "response";
protected ConnectorImpl connector;
@@ -63,14 +65,15 @@
targetWire.setServiceContract(contract);
targetWire.addInvocationChain(operation, chain);
+ MockInvoker mockInvoker = new MockInvoker();
+
// 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));
+ target.getInboundWire(EasyMock.eq(TARGET_SERVICE));
EasyMock.expectLastCall().andReturn(targetWire).atLeastOnce();
- target.createTargetInvoker(EasyMock.eq(FOO_SERVICE), EasyMock.eq(operation), EasyMock.eq(targetWire));
- AbstractConnectorImplTestCase.MockInvoker mockInvoker = new AbstractConnectorImplTestCase.MockInvoker();
+ target.createTargetInvoker(EasyMock.eq(TARGET_SERVICE), EasyMock.eq(operation), EasyMock.eq(targetWire));
EasyMock.expectLastCall().andReturn(mockInvoker);
EasyMock.replay(target);
targetWire.setContainer(target);
@@ -82,14 +85,14 @@
OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
OutboundWire outboundWire = new OutboundWireImpl();
- outboundWire.setTargetName(FOO_TARGET);
+ outboundWire.setTargetName(TARGET_SERVICE_NAME);
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);
+ outboundWires.put(TARGET_SERVICE, list);
// create the source
AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
Modified: 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=diff&rev=491795&r1=491794&r2=491795
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractLocalWiringTestCase.java Tue Jan 2 05:55:23 2007
@@ -28,8 +28,6 @@
* @version $Rev$ $Date$
*/
public abstract class AbstractLocalWiringTestCase extends AbstractConnectorImplTestCase {
- protected static final String TARGET = "target";
- protected static final QualifiedName TARGET_NAME = new QualifiedName(TARGET);
protected ReferenceBinding referenceBinding;
@@ -70,14 +68,14 @@
return service;
}
- protected Reference createLocalReference(CompositeComponent parent) throws Exception {
- ReferenceBinding referenceBinding = createLocalReferenceBinding();
+ protected Reference createLocalReference(CompositeComponent parent, QualifiedName target) throws Exception {
+ ReferenceBinding referenceBinding = createLocalReferenceBinding(target);
Reference reference = new ReferenceImpl("foo", parent, contract);
reference.addReferenceBinding(referenceBinding);
return reference;
}
- protected ReferenceBinding createLocalReferenceBinding()
+ protected ReferenceBinding createLocalReferenceBinding(QualifiedName target)
throws TargetInvokerCreationException {
referenceBinding = new LocalReferenceBinding("local", null);
InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation);
@@ -91,7 +89,7 @@
outboundChain.addInterceptor(new SynchronousBridgingInterceptor());
OutboundWire outboundWire = new OutboundWireImpl();
outboundWire.setServiceContract(contract);
- outboundWire.setTargetName(TARGET_NAME);
+ outboundWire.setTargetName(target);
outboundWire.addInvocationChain(operation, outboundChain);
outboundWire.setContainer(referenceBinding);
Modified: 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=diff&rev=491795&r1=491794&r2=491795
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java Tue Jan 2 05:55:23 2007
@@ -63,7 +63,7 @@
OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation);
OutboundWire outboundWire = new OutboundWireImpl();
- outboundWire.setTargetName(FOO_TARGET);
+ outboundWire.setTargetName(TARGET_SERVICE_NAME);
outboundWire.addInvocationChain(operation, outboundChain);
outboundWire.setServiceContract(contract);
@@ -114,7 +114,7 @@
MessageImpl msg = new MessageImpl();
Map<String, List<OutboundWire>> wires = source.getOutboundWires();
- OutboundWire wire = wires.get(FOO_SERVICE).get(0);
+ OutboundWire wire = wires.get(TARGET_SERVICE).get(0);
OutboundInvocationChain chain = wire.getInvocationChains().get(operation);
msg.setTargetInvoker(chain.getTargetInvoker());
Message resp = chain.getHeadInterceptor().invoke(msg);
@@ -129,7 +129,7 @@
InboundWire wire = new InboundWireImpl();
wire.setServiceContract(contract);
wire.addInvocationChain(operation, chain);
- wire.setServiceName(FOO_SERVICE);
+ wire.setServiceName(TARGET_SERVICE);
List<InboundWire> wires = new ArrayList<InboundWire>();
wires.add(wire);
@@ -139,7 +139,8 @@
EasyMock.expectLastCall().andReturn(Collections.emptyMap());
source.getInboundWires();
EasyMock.expectLastCall().andReturn(wires);
- source.createTargetInvoker(EasyMock.eq(FOO_SERVICE), EasyMock.eq(operation), (InboundWire) EasyMock.isNull());
+ source
+ .createTargetInvoker(EasyMock.eq(TARGET_SERVICE), EasyMock.eq(operation), (InboundWire) EasyMock.isNull());
EasyMock.expectLastCall().andReturn(new MockInvoker());
EasyMock.replay(source);
Modified: 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=diff&rev=491795&r1=491794&r2=491795
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java Tue Jan 2 05:55:23 2007
@@ -6,6 +6,7 @@
import org.apache.tuscany.spi.component.Reference;
import org.apache.tuscany.spi.component.Service;
import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.wire.InboundInvocationChain;
import org.apache.tuscany.spi.wire.Interceptor;
import org.apache.tuscany.spi.wire.Message;
@@ -31,6 +32,23 @@
public class LocalReferenceWiringTestCase extends AbstractLocalWiringTestCase {
private Service service;
private Reference reference;
+ private AtomicComponent atomicComponent;
+
+ /**
+ * Verifies the case where inbound and outbound reference wires are connected followed by the outbound reference
+ * wire being connected to a target that is an atomic component and child of the reference's parent composite. This
+ * wiring scenario occurs when a reference is configured with the local binding.
+ */
+ public void testConnectLocalReferenceBindingToAtomicComponentService() throws Exception {
+ createLocalReferenceToSiblingAtomicConfiguration();
+ 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());
+ }
/**
* Verifies the case where inbound and outbound reference wires are connected followed by the outbound reference
@@ -58,6 +76,31 @@
}
}
+ /**
+ * Verifies a connection to a service offered by a sibling composite of the reference's parent
+ *
+ * @throws Exception
+ */
+ public void testConnectLocalReferenceBindingToSiblingCompositeService() throws Exception {
+ createLocalReferenceToSiblingCompositeServiceConfiguration();
+ 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());
+ }
+
+ public void testConnectLocalReferenceBindingToSiblingCompositeServiceNoMatchingBinding() throws Exception {
+ createLocalReferenceToSiblingCompositeServiceConfigurationNoMatchingBinding();
+ try {
+ connector.connect(reference);
+ fail();
+ } catch (NoCompatibleBindingsException e) {
+ // expected
+ }
+ }
protected void setUp() throws Exception {
super.setUp();
@@ -78,7 +121,7 @@
EasyMock.replay(parent);
service = createLocalService(topComposite);
- reference = createLocalReference(parent);
+ reference = createLocalReference(parent, AbstractLocalWiringTestCase.TARGET_NAME);
}
private void createLocalReferenceToInvalidServiceConfiguration() throws Exception {
@@ -95,11 +138,82 @@
EasyMock.expect(parent.getParent()).andReturn(topComposite);
EasyMock.replay(parent);
- service = createService(topComposite);
- reference = createLocalReference(parent);
+ service = createService();
+ reference = createLocalReference(parent, AbstractLocalWiringTestCase.TARGET_NAME);
+ }
+
+ private void createLocalReferenceToSiblingCompositeServiceConfiguration() throws Exception {
+ final CompositeComponent sibling = EasyMock.createMock(CompositeComponent.class);
+ sibling.getService(TARGET_SERVICE);
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ return service;
+ }
+ });
+ EasyMock.replay(sibling);
+
+ CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class);
+ topComposite.getChild(TARGET);
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ return sibling;
+ }
+ });
+ EasyMock.replay(topComposite);
+
+ CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(parent.getParent()).andReturn(topComposite);
+ EasyMock.replay(parent);
+
+ service = createLocalService(topComposite);
+ reference = createLocalReference(parent, TARGET_SERVICE_NAME);
+ }
+
+ private void createLocalReferenceToSiblingCompositeServiceConfigurationNoMatchingBinding() throws Exception {
+ final CompositeComponent sibling = EasyMock.createMock(CompositeComponent.class);
+ sibling.getService(TARGET_SERVICE);
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ return service;
+ }
+ });
+ EasyMock.replay(sibling);
+
+ CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class);
+ topComposite.getChild(TARGET);
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ return sibling;
+ }
+ });
+ EasyMock.replay(topComposite);
+
+ CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(parent.getParent()).andReturn(topComposite);
+ EasyMock.replay(parent);
+
+ service = createService();
+ reference = createLocalReference(parent, TARGET_SERVICE_NAME);
+ }
+
+ private void createLocalReferenceToSiblingAtomicConfiguration() throws Exception {
+ final CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class);
+ topComposite.getChild(TARGET);
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ return atomicComponent;
+ }
+ });
+ EasyMock.replay(topComposite);
+
+ CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(parent.getParent()).andReturn(topComposite).atLeastOnce();
+ EasyMock.replay(parent);
+ atomicComponent = createAtomicTarget();
+ reference = createLocalReference(parent, TARGET_SERVICE_NAME);
}
- protected Service createService(CompositeComponent parent) throws WireConnectException {
+ private Service createService() throws WireConnectException {
QName qName = new QName("foo", "bar");
ServiceBinding serviceBinding = new MockServiceBinding();
InboundInvocationChain targetInboundChain = new InboundInvocationChainImpl(operation);
Modified: 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=diff&rev=491795&r1=491794&r2=491795
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java Tue Jan 2 05:55:23 2007
@@ -60,7 +60,7 @@
outboundChain.addInterceptor(new InvokerInterceptor());
OutboundWire outboundWire = new OutboundWireImpl();
outboundWire.setServiceContract(contract);
- outboundWire.setTargetName(FOO_TARGET);
+ outboundWire.setTargetName(TARGET_SERVICE_NAME);
outboundWire.setContainer(source);
outboundWire.addInvocationChain(operation, outboundChain);
@@ -102,7 +102,7 @@
OutboundWire outboundWire = new OutboundWireImpl();
outboundWire.setServiceContract(contract);
outboundWire.setContainer(source);
- outboundWire.setTargetName(FOO_TARGET);
+ outboundWire.setTargetName(TARGET_SERVICE_NAME);
outboundWire.addInvocationChain(operation, outboundChain);
ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class);
@@ -151,7 +151,7 @@
OutboundInvocationChain sourceChain = new OutboundInvocationChainImpl(operation);
OutboundWire sourceWire = new OutboundWireImpl();
sourceWire.setServiceContract(contract);
- sourceWire.setTargetName(FOO_TARGET);
+ sourceWire.setTargetName(TARGET_SERVICE_NAME);
sourceWire.addInvocationChain(operation, sourceChain);
sourceWire.setContainer(component);
sourceWire.setContainer(source);
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org