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/01 19:16:12 UTC
svn commit: r491605 - in /incubator/tuscany/java/sca/kernel:
core/src/main/java/org/apache/tuscany/core/wire/
core/src/test/java/org/apache/tuscany/core/wire/
spi/src/main/java/org/apache/tuscany/spi/wire/
Author: jmarino
Date: Mon Jan 1 10:16:11 2007
New Revision: 491605
URL: http://svn.apache.org/viewvc?view=rev&rev=491605
Log:
start to improve unit test coverage in core
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java?view=diff&rev=491605&r1=491604&r2=491605
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java Mon Jan 1 10:16:11 2007
@@ -109,7 +109,8 @@
callbackSourceChainMaps.put(targetAddr, chains);
}
- public void addSourceCallbackInvocationChain(Object targetAddr, Operation operation,
+ public void addSourceCallbackInvocationChain(Object targetAddr,
+ Operation operation,
OutboundInvocationChain chain) {
Map<Operation<?>, OutboundInvocationChain> chains = callbackSourceChainMaps.get(targetAddr);
if (chains == null) {
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java?view=diff&rev=491605&r1=491604&r2=491605
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java Mon Jan 1 10:16:11 2007
@@ -65,40 +65,6 @@
return new InboundInvocationChainImpl(operation);
}
- public OutboundWire createWire(ReferenceTarget reference, ReferenceDefinition def) {
- if (!def.isAutowire() && reference.getTargets().size() != 1) {
- //TODO multiplicity
- throw new UnsupportedOperationException();
- }
- ServiceContract<?> contract = def.getServiceContract();
- OutboundWire wire = new OutboundWireImpl();
- if (!def.isAutowire()) {
- QualifiedName qName = new QualifiedName(reference.getTargets().get(0).toString());
- wire.setTargetName(qName);
- } else {
- wire.setAutowire(true);
- }
- wire.setServiceContract(contract);
- wire.setReferenceName(reference.getReferenceName());
- for (Operation<?> operation : contract.getOperations().values()) {
- //TODO handle policy
- OutboundInvocationChain chain = createOutboundChain(operation);
- wire.addInvocationChain(operation, chain);
-
- }
- if (contract.getCallbackName() != null) {
- wire.setCallbackInterface(contract.getCallbackClass());
- for (Operation<?> operation : contract.getCallbackOperations().values()) {
- InboundInvocationChain callbackTargetChain = createInboundChain(operation);
- // TODO handle policy
- //TODO statement below could be cleaner
- callbackTargetChain.addInterceptor(new InvokerInterceptor());
- wire.addTargetCallbackInvocationChain(operation, callbackTargetChain);
- }
- }
- return wire;
- }
-
public InboundWire createWire(ServiceDefinition service) {
InboundWire wire = new InboundWireImpl();
ServiceContract<?> contract = service.getServiceContract();
@@ -119,12 +85,13 @@
public void createWires(Component component, ComponentDefinition<?> definition) {
Implementation<?> implementation = definition.getImplementation();
ComponentType<?, ?, ?> componentType = implementation.getComponentType();
+ // create incoming service wires
for (ServiceDefinition service : componentType.getServices().values()) {
InboundWire wire = createWire(service);
wire.setContainer(component);
component.addInboundWire(wire);
}
-
+ // create outgoing reference wires
for (ReferenceTarget referenceTarget : definition.getReferenceTargets().values()) {
Map<String, ? extends ReferenceDefinition> references = componentType.getReferences();
ReferenceDefinition mappedReference = references.get(referenceTarget.getReferenceName());
@@ -178,7 +145,6 @@
public void createWires(ServiceBinding serviceBinding, String targetName, ServiceContract<?> contract) {
InboundWire inboundWire = new InboundWireImpl();
-
// [rfeng] Check if the Reference has the serviceBinding contract
ServiceContract<?> bindingContract = serviceBinding.getBindingServiceContract();
if (bindingContract == null) {
@@ -274,6 +240,47 @@
targetOperation);
}
}
+ }
+
+ /**
+ * Creates a wire for flowing outbound invocations from a reference
+ *
+ * @param target the reference definition
+ * @param definition the reference target configuration
+ * @return the wire the outbound wire
+ */
+ protected OutboundWire createWire(ReferenceTarget target, ReferenceDefinition definition) {
+ if (!definition.isAutowire() && target.getTargets().size() != 1) {
+ //TODO multiplicity
+ throw new UnsupportedOperationException();
+ }
+ ServiceContract<?> contract = definition.getServiceContract();
+ OutboundWire wire = new OutboundWireImpl();
+ if (!definition.isAutowire()) {
+ QualifiedName qName = new QualifiedName(target.getTargets().get(0).toString());
+ wire.setTargetName(qName);
+ } else {
+ wire.setAutowire(true);
+ }
+ wire.setServiceContract(contract);
+ wire.setReferenceName(target.getReferenceName());
+ for (Operation<?> operation : contract.getOperations().values()) {
+ //TODO handle policy
+ OutboundInvocationChain chain = createOutboundChain(operation);
+ wire.addInvocationChain(operation, chain);
+
+ }
+ if (contract.getCallbackName() != null) {
+ wire.setCallbackInterface(contract.getCallbackClass());
+ for (Operation<?> operation : contract.getCallbackOperations().values()) {
+ InboundInvocationChain callbackTargetChain = createInboundChain(operation);
+ // TODO handle policy
+ //TODO statement below could be cleaner
+ callbackTargetChain.addInterceptor(new InvokerInterceptor());
+ wire.addTargetCallbackInvocationChain(operation, callbackTargetChain);
+ }
+ }
+ return wire;
}
}
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java?view=diff&rev=491605&r1=491604&r2=491605
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java Mon Jan 1 10:16:11 2007
@@ -386,10 +386,6 @@
throw new UnsupportedOperationException();
}
- public OutboundWire createWire(ReferenceTarget reference, ReferenceDefinition def) {
- throw new UnsupportedOperationException();
- }
-
public void createWires(Component component, ComponentDefinition<?> definition) {
throw new UnsupportedOperationException();
}
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java?view=diff&rev=491605&r1=491604&r2=491605
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java Mon Jan 1 10:16:11 2007
@@ -20,31 +20,45 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import java.net.URI;
import java.util.HashMap;
import java.util.Map;
+import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Implementation;
import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
import org.apache.tuscany.spi.model.ServiceContract;
import org.apache.tuscany.spi.model.ServiceDefinition;
import 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.OutboundChainHolder;
import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
import org.apache.tuscany.spi.wire.ProxyCreationException;
+import org.apache.tuscany.spi.wire.TargetInvoker;
import org.apache.tuscany.spi.wire.Wire;
import org.apache.tuscany.spi.wire.WireInvocationHandler;
-import org.apache.tuscany.spi.wire.WireService;
import junit.framework.TestCase;
import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
/**
* @version $Rev$ $Date$
*/
public class WireServiceExtensionTestCase extends TestCase {
- private WireService wireService;
+ private TestWireService wireService;
private Operation<Type> operation;
+ private ServiceContract<Type> contract;
+ private Operation<Type> callbackOperation;
public void testCreateInboundChain() throws Exception {
InboundInvocationChain chain = wireService.createInboundChain(operation);
@@ -56,27 +70,116 @@
assertEquals(operation, chain.getOperation());
}
- public void testCreateWireServiceDefinition() throws Exception {
- ServiceDefinition definition = new ServiceDefinition();
- definition.setName("foo");
- ServiceContract<Type> contract = new ServiceContract<Type>() {
- };
- Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
- operations.put("foo", operation);
- contract.setOperations(operations);
- definition.setServiceContract(contract);
+ public void testCreateServiceWire() throws Exception {
+ ServiceDefinition definition = new ServiceDefinition("foo", contract, false);
+ TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class);
+ MessageImpl resp = new MessageImpl();
+ EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(resp);
+ EasyMock.replay(invoker);
InboundWire wire = wireService.createWire(definition);
assertEquals("foo", wire.getServiceName());
assertEquals(1, wire.getInvocationChains().size());
assertEquals(contract, wire.getServiceContract());
InboundInvocationChain chain = wire.getInvocationChains().get(operation);
assertEquals(operation, chain.getOperation());
+ // verify the chain is invokable
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(invoker);
+ assertNotNull(chain.getHeadInterceptor().invoke(msg));
+ EasyMock.verify(invoker);
+ }
+
+ public void testCreateReferenceWire() throws Exception {
+ ReferenceDefinition definition = new ReferenceDefinition("foo", contract);
+ ReferenceTarget target = new ReferenceTarget();
+ target.addTarget(new URI("bar"));
+ target.setReferenceName("refName");
+
+ OutboundWire wire = wireService.createWire(target, definition);
+ assertEquals("refName", wire.getReferenceName());
+ assertEquals("bar", wire.getTargetName().toString());
+ assertFalse(wire.isAutowire());
+ assertEquals(1, wire.getInvocationChains().size());
+ assertEquals(contract, wire.getServiceContract());
+ OutboundInvocationChain chain = wire.getInvocationChains().get(operation);
+ assertEquals(operation, chain.getOperation());
+ assertNull(chain.getHeadInterceptor());
+ assertEquals(Callback.class, wire.getCallbackInterface());
+ assertEquals(1, wire.getTargetCallbackInvocationChains().size());
+ InboundInvocationChain callbackChain = wire.getTargetCallbackInvocationChains().get(callbackOperation);
+ assertEquals(callbackOperation, callbackChain.getOperation());
+
+ TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class);
+ MessageImpl resp = new MessageImpl();
+ EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(resp);
+ EasyMock.replay(invoker);
+ // verify the callback chain is invokable
+ MessageImpl msg = new MessageImpl();
+ msg.setTargetInvoker(invoker);
+ assertNotNull(callbackChain.getHeadInterceptor().invoke(msg));
+ EasyMock.verify(invoker);
+ }
+
+ public void testCreateAutowireReferenceWire() throws Exception {
+ ReferenceDefinition definition = new ReferenceDefinition("foo", contract);
+ definition.setAutowire(true);
+ ReferenceTarget target = new ReferenceTarget();
+ target.setReferenceName("refName");
+ OutboundWire wire = wireService.createWire(target, definition);
+ assertTrue(wire.isAutowire());
+ assertEquals("refName", wire.getReferenceName());
+ assertEquals(contract, wire.getServiceContract());
+ assertEquals(Callback.class, wire.getCallbackInterface());
+ }
+
+ public void testCreateComponentWires() throws Exception {
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition("refName", contract);
+ type.add(referenceDefinition);
+ ServiceDefinition serviceDefinition = new ServiceDefinition("foo", contract, false);
+ type.add(serviceDefinition);
+
+ Implementation<ComponentType> impl = new Implementation<ComponentType>() {
+ };
+ impl.setComponentType(type);
+
+ ComponentDefinition<Implementation<ComponentType>> definition =
+ new ComponentDefinition<Implementation<ComponentType>>("Foo", impl);
+ ReferenceTarget target = new ReferenceTarget();
+ target.addTarget(new URI("bar"));
+ target.setReferenceName("refName");
+ definition.add(target);
+
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addInboundWire(EasyMock.isA(InboundWire.class));
+ component.addOutboundWire(EasyMock.isA(OutboundWire.class));
+ EasyMock.replay(component);
+
+ wireService.createWires(component, definition);
+ EasyMock.verify(component);
}
protected void setUp() throws Exception {
super.setUp();
wireService = new TestWireService(new WorkContextImpl());
+
operation = new Operation<Type>("foo", null, null, null);
+ callbackOperation = new Operation<Type>("foo", null, null, null);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("foo", operation);
+ Map<String, Operation<Type>> callbackOperations = new HashMap<String, Operation<Type>>();
+ callbackOperations.put("foo", callbackOperation);
+ contract = new ServiceContract<Type>() {
+ };
+ contract.setOperations(operations);
+ contract.setCallbackClass(Callback.class);
+ contract.setCallbackName(Callback.class.getName());
+ contract.setCallbackOperations(callbackOperations);
+ }
+
+ private interface Callback {
+
}
private class TestWireService extends WireServiceExtension {
@@ -99,6 +202,11 @@
public WireInvocationHandler createHandler(Class<?> interfaze, Wire wire) {
return null;
+ }
+
+
+ public OutboundWire createWire(ReferenceTarget reference, ReferenceDefinition def) {
+ return super.createWire(reference, def);
}
}
}
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java?view=diff&rev=491605&r1=491604&r2=491605
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireService.java Mon Jan 1 10:16:11 2007
@@ -94,21 +94,13 @@
InboundInvocationChain createInboundChain(Operation<?> operation);
/**
- * Creates a wire for flowing inbound invocations to a service
+ * Creates a wire for flowing inbound invocations to a service. The returned inbound chain will always contain at
+ * least one interceptor in order for outbound wires to connect to it.
*
* @param service the model representation of the service
* @return the wire for flowing inbound invocations to a service
*/
InboundWire createWire(ServiceDefinition service);
-
- /**
- * Creates a wire for flowing outbound invocations to a reference
- *
- * @param reference the model artifact representing the reference on the source side
- * @param def the model artifact representing the target reference
- * @return the wire for flowing outbound invocations to a reference
- */
- //OutboundWire createWire(ReferenceTarget reference, ReferenceDefinition def);
/**
* Creates wires for a component and injects them on the component
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org