tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmar...@apache.org
Subject svn commit: r410780 - in /incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy: WireTestCase.java mock/Greeting.java
Date Thu, 01 Jun 2006 07:37:10 GMT
Author: jmarino
Date: Thu Jun  1 00:37:10 2006
New Revision: 410780

URL: http://svn.apache.org/viewvc?rev=410780&view=rev
Log:
fix groovy component to pass tests with wire changes

Modified:
    incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/WireTestCase.java
    incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/Greeting.java

Modified: incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/WireTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/WireTestCase.java?rev=410780&r1=410779&r2=410780&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/WireTestCase.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/WireTestCase.java
Thu Jun  1 00:37:10 2006
@@ -6,9 +6,13 @@
 import org.apache.tuscany.container.groovy.mock.Greeting;
 import org.apache.tuscany.core.context.scope.ModuleScopeContext;
 import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
 import org.apache.tuscany.spi.wire.OutboundWire;
 import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.spi.wire.InboundWire;
 import org.apache.tuscany.test.ArtifactFactory;
 import org.jmock.Mock;
 import org.jmock.MockObjectTestCase;
@@ -23,9 +27,14 @@
     private static final String SCRIPT = "import org.apache.tuscany.container.groovy.mock.Greeting;"
+
             "class Foo implements Greeting{" +
             "   Greeting wire;" +
-            "   public String greet(String name){" +
+            "   " +
+            "   void setWire(Greeting ref){" +
+            "       wire = ref;" +
+            "   };" +
+            "   " +
+            "   String greet(String name){" +
             "       return wire.greet(name);  " +
-            "   }" +
+            "   };" +
             "}";
 
     private static final String SCRIPT2 = "import org.apache.tuscany.container.groovy.mock.Greeting;"
+
@@ -41,20 +50,31 @@
     public void testReferenceWireInvocation() throws Exception {
         ModuleScopeContext scope = new ModuleScopeContext(null);
         scope.start();
+
         List<Class<?>> services = new ArrayList<Class<?>>();
         services.add(Greeting.class);
-        GroovyAtomicContext<Greeting> context = new GroovyAtomicContext<Greeting>("source",
SCRIPT, services,
-                Scope.MODULE, null, null, scope, ArtifactFactory.createWireService());
+        GroovyAtomicContext<Greeting> context = new GroovyAtomicContext<Greeting>("source",
SCRIPT,
+                services, Scope.MODULE, null, null, scope, ArtifactFactory.createWireService());
+        OutboundWire<?> wire = ArtifactFactory.createOutboundWire("wire", Greeting.class);
+        ArtifactFactory.terminateWire(wire);
+        Mock mock = mock(TargetInvoker.class);
+        mock.expects(atLeastOnce()).method("isCacheable").will(returnValue(false));
+        mock.expects(atLeastOnce()).method("invoke").will(new Stub() {
+            public Object invoke(Invocation invocation) throws Throwable {
+                Message msg = new MessageImpl();
+                msg.setBody("foo");
+                return msg;
+            }
+
+            public StringBuffer describeTo(StringBuffer stringBuffer) {
+                return null;
+            }
+        });
+        TargetInvoker invoker = (TargetInvoker) mock.proxy();
+        for (OutboundInvocationChain chain : wire.getInvocationChains().values()) {
+            chain.setTargetInvoker(invoker);
+        }
         scope.register(context);
-        Mock mock = mock(OutboundWire.class);
-        mock.expects(atLeastOnce()).method("getTargetService").will(
-                returnValue(new Greeting() {
-                    public String greet(String name) {
-                        return name;
-                    }
-                }));
-        mock.expects(atLeastOnce()).method("getReferenceName").will(returnValue("wire"));
-        OutboundWire<Greeting> wire = (OutboundWire<Greeting>) mock.proxy();
         context.addOutboundWire(wire);
         Greeting greeting = context.getService();
         assertEquals("foo", greeting.greet("foo"));
@@ -71,7 +91,7 @@
         List<Class<?>> services = new ArrayList<Class<?>>();
         services.add(Greeting.class);
         GroovyAtomicContext<Greeting> context = new GroovyAtomicContext<Greeting>("source",
SCRIPT2, services,
-                Scope.MODULE, null, null, scope,ArtifactFactory.createWireService());
+                Scope.MODULE, null, null, scope, ArtifactFactory.createWireService());
         scope.register(context);
         TargetInvoker invoker = context.createTargetInvoker("greeting", Greeting.class.getMethod("greet",
String.class));
         assertEquals("foo", invoker.invokeTarget(new String[]{"foo"}));
@@ -87,23 +107,15 @@
         scope.start();
         List<Class<?>> services = new ArrayList<Class<?>>();
         services.add(Greeting.class);
-        final GroovyAtomicContext<Greeting> context = new GroovyAtomicContext<Greeting>("source",
SCRIPT2,
-                services, Scope.MODULE, null, null, scope,ArtifactFactory.createWireService());
+        GroovyAtomicContext<Greeting> context = new GroovyAtomicContext<Greeting>("source",
SCRIPT2,
+                services, Scope.MODULE, null, null, scope, ArtifactFactory.createWireService());
         scope.register(context);
-        Mock mock = mock(InboundWire.class);
-        mock.stubs().method("getServiceName").will(returnValue("Greeting"));
-        mock.expects(atLeastOnce()).method("getTargetService").will(
-                new Stub() {
-                    public Object invoke(Invocation invocation) throws Throwable {
-                        return context.getTargetInstance();
-                    }
-
-                    public StringBuffer describeTo(StringBuffer buff) {
-                        return buff.append("returns the target instance");
-                    }
-                });
 
-        InboundWire<Greeting> wire = (InboundWire<Greeting>) mock.proxy();
+        InboundWire<?> wire = ArtifactFactory.createInboundWire("Greeting", Greeting.class);
+        ArtifactFactory.terminateWire(wire);
+        for (InboundInvocationChain chain : wire.getInvocationChains().values()) {
+            chain.setTargetInvoker(context.createTargetInvoker("Greeting", chain.getMethod()));
+        }
         context.addInboundWire(wire);
         Greeting greeting = (Greeting) context.getService("Greeting");
         assertEquals("foo", greeting.greet("foo"));

Modified: incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/Greeting.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/Greeting.java?rev=410780&r1=410779&r2=410780&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/Greeting.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/Greeting.java
Thu Jun  1 00:37:10 2006
@@ -2,5 +2,6 @@
 
 public interface Greeting {
 
+    String setWire(Greeting ref);
     String greet(String name);
 }



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


Mime
View raw message