From 6d0e93c68d3aeaeb4bb6d96ac0460eec40ef786e Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:13:23 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835143 13f79535-47bb-0310-9956-ffa450edef68 --- .../container/groovy/AsyncInvokerTestCase.java | 77 +++++++++ .../groovy/GroovyComponentTypeLoaderTestCase.java | 37 ++++ .../groovy/ImplementationLoaderTestCase.java | 102 +++++++++++ .../tuscany/container/groovy/PropertyTestCase.java | 90 ++++++++++ .../container/groovy/ScriptInvokeTestCase.java | 79 +++++++++ .../tuscany/container/groovy/WireTestCase.java | 189 +++++++++++++++++++++ .../tuscany/container/groovy/mock/AsyncTarget.java | 27 +++ .../tuscany/container/groovy/mock/Greeting.java | 25 +++ 8 files changed, 626 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/AsyncInvokerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/ImplementationLoaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/PropertyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/ScriptInvokeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/WireTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/AsyncTarget.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/Greeting.java (limited to 'sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org') diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/AsyncInvokerTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/AsyncInvokerTestCase.java new file mode 100644 index 0000000000..a27bb25484 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/AsyncInvokerTestCase.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.groovy; + +import java.lang.reflect.Method; + +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.services.work.WorkScheduler; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; + +import groovy.lang.GroovyObject; +import junit.framework.TestCase; +import org.apache.tuscany.container.groovy.mock.AsyncTarget; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.getCurrentArguments; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import org.easymock.IAnswer; +import org.easymock.classextension.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AsyncInvokerTestCase extends TestCase { + + public void testInvoke() throws Exception { + GroovyObject instance = createMock(GroovyObject.class); + expect(instance.invokeMethod("invoke", null)).andReturn(null).once(); + replay(instance); + GroovyAtomicComponent component = EasyMock.createMock(GroovyAtomicComponent.class); + expect(component.getTargetInstance()).andReturn(instance); + EasyMock.replay(component); + AsyncMonitor monitor = createMock(AsyncMonitor.class); + replay(monitor); + + WorkScheduler scheduler = createMock(WorkScheduler.class); + scheduler.scheduleWork(isA(Runnable.class)); + expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + Runnable runnable = (Runnable) getCurrentArguments()[0]; + runnable.run(); + return null; + } + }); + replay(scheduler); + WorkContext context = createMock(WorkContext.class); + Method method = AsyncTarget.class.getMethod("invoke"); + method.setAccessible(true); + InboundWire wire = createMock(InboundWire.class); + AsyncGroovyInvoker invoker = new AsyncGroovyInvoker("invoke", wire, component, monitor, context); + Message msg = new MessageImpl(); + invoker.invoke(msg); + verify(instance); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoaderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoaderTestCase.java new file mode 100644 index 0000000000..bfff4bdef7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoaderTestCase.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.groovy; + +import org.apache.tuscany.spi.model.Scope; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class GroovyComponentTypeLoaderTestCase extends TestCase { + + public void testLoad() throws Exception { + GroovyComponentTypeLoader loader = new GroovyComponentTypeLoader(); + GroovyImplementation impl = new GroovyImplementation(); + loader.load(null, impl, null); + GroovyComponentType type = impl.getComponentType(); + assertEquals(Scope.MODULE, type.getLifecycleScope()); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/ImplementationLoaderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/ImplementationLoaderTestCase.java new file mode 100644 index 0000000000..2af0611757 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/ImplementationLoaderTestCase.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.groovy; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.MissingResourceException; + +import junit.framework.TestCase; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.expect; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + +/** + * @version $Rev$ $Date$ + */ +public class ImplementationLoaderTestCase extends TestCase { + private CompositeComponent parent; + private XMLStreamReader reader; + private DeploymentContext deploymentContext; + private ClassLoader classLoader; + private LoaderRegistry registry; + private ImplementationLoader loader; + + public void testNoScriptAttribute() throws LoaderException, XMLStreamException { + expect(reader.getAttributeValue(null, "script")).andReturn(null); + replay(reader); + replay(deploymentContext); + + try { + loader.load(parent, reader, deploymentContext); + fail(); + } catch (MissingResourceException e) { + // ok + } + verify(reader); + verify(deploymentContext); + } + + public void testNoScriptPresent() throws LoaderException, XMLStreamException { + expect(reader.getAttributeValue(null, "script")).andReturn("foo.groovy"); + expect(deploymentContext.getClassLoader()).andReturn(classLoader); + + replay(reader); + replay(deploymentContext); + + ImplementationLoader mockLoader = new ImplementationLoader(registry) { + protected String loadSource(ClassLoader cl, String resource) throws LoaderException { + assertSame(classLoader, cl); + assertEquals("foo.groovy", resource); + throw new MissingResourceException(resource); + } + }; + try { + mockLoader.load(parent, reader, deploymentContext); + fail(); + } catch (MissingResourceException e) { + assertEquals("foo.groovy", e.getMessage()); + } + verify(reader); + verify(deploymentContext); + } + + public void testLoadScript() throws LoaderException { + String script = loader.loadSource(getClass().getClassLoader(), + "org/apache/tuscany/container/groovy/mock/TestScript.groovy"); + assertEquals("Test Script", script); + } + + protected void setUp() throws Exception { + super.setUp(); + registry = createMock(LoaderRegistry.class); + loader = new ImplementationLoader(registry); + + parent = createMock(CompositeComponent.class); + reader = createMock(XMLStreamReader.class); + deploymentContext = createMock(DeploymentContext.class); + classLoader = createMock(ClassLoader.class); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/PropertyTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/PropertyTestCase.java new file mode 100644 index 0000000000..9b828db7eb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/PropertyTestCase.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.groovy; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.spi.ObjectFactory; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.ScopeContainer; + +import groovy.lang.GroovyClassLoader; +import groovy.lang.GroovyObject; +import junit.framework.TestCase; +import org.apache.tuscany.container.groovy.mock.Greeting; +import static org.apache.tuscany.test.ArtifactFactory.createWireService; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.getCurrentArguments; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import org.easymock.IAnswer; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class PropertyTestCase extends TestCase { + + private static final String SCRIPT = "import org.apache.tuscany.container.groovy.mock.Greeting;" + + "class Foo implements Greeting{" + + " String property;" + + " public String greet(String name){" + + " return property; " + + " }" + + "}"; + + private ScopeContainer scopeContainer; + private Class implClass; + + /** + * Tests injecting a simple property type on a Groovy implementation instance + */ + public void testPropertyInjection() throws Exception { + List> services = new ArrayList>(); + services.add(Greeting.class); + GroovyConfiguration configuration = new GroovyConfiguration(); + configuration.setName("source"); + configuration.setGroovyClass(implClass); + configuration.setServices(services); + configuration.setScopeContainer(scopeContainer); + configuration.setWireService(createWireService()); + GroovyAtomicComponent component = new GroovyAtomicComponent(configuration, null); + ObjectFactory factory = createMock(ObjectFactory.class); + expect((String) factory.getInstance()).andReturn("bar"); + replay(factory); + component.addPropertyFactory("property", factory); + Greeting greeting = (Greeting) component.getServiceInstance(); + assertEquals("bar", greeting.greet("foo")); + } + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + GroovyClassLoader cl = new GroovyClassLoader(getClass().getClassLoader()); + implClass = cl.parseClass(SCRIPT); + scopeContainer = createMock(ScopeContainer.class); + expect(scopeContainer.getInstance(isA(AtomicComponent.class))).andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + return ((AtomicComponent) getCurrentArguments()[0]).createInstance(); + } + }); + replay(scopeContainer); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/ScriptInvokeTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/ScriptInvokeTestCase.java new file mode 100644 index 0000000000..f0ae7deb33 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/ScriptInvokeTestCase.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.groovy; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.ScopeContainer; + +import groovy.lang.GroovyClassLoader; +import groovy.lang.GroovyObject; +import junit.framework.TestCase; +import org.apache.tuscany.container.groovy.mock.Greeting; +import static org.apache.tuscany.test.ArtifactFactory.createWireService; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.getCurrentArguments; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import org.easymock.IAnswer; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class ScriptInvokeTestCase extends TestCase { + + private static final String SCRIPT = "def greet(name) { return name }"; + + private Class implClass; + private ScopeContainer scopeContainer; + + /** + * Tests the invocation of a Groovy "script" as opposed to a class + */ + public void testBasicScriptInvocation() throws Exception { + List> services = new ArrayList>(); + services.add(Greeting.class); + GroovyConfiguration configuration = new GroovyConfiguration(); + configuration.setName("source"); + configuration.setGroovyClass(implClass); + configuration.setServices(services); + configuration.setScopeContainer(scopeContainer); + configuration.setWireService(createWireService()); + GroovyAtomicComponent context = new GroovyAtomicComponent(configuration, null); + GroovyObject object = (GroovyObject) context.getServiceInstance(); + assertEquals("foo", object.invokeMethod("greet", "foo")); + } + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + GroovyClassLoader cl = new GroovyClassLoader(getClass().getClassLoader()); + implClass = cl.parseClass(SCRIPT); + scopeContainer = createMock(ScopeContainer.class); + expect(scopeContainer.getInstance(isA(AtomicComponent.class))).andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + return ((AtomicComponent) getCurrentArguments()[0]).createInstance(); + } + }); + replay(scopeContainer); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/WireTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/WireTestCase.java new file mode 100644 index 0000000000..79f37f514c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/WireTestCase.java @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.groovy; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.model.Operation; +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 groovy.lang.GroovyClassLoader; +import groovy.lang.GroovyObject; +import junit.framework.TestCase; +import org.apache.tuscany.container.groovy.mock.Greeting; +import static org.apache.tuscany.test.ArtifactFactory.createInboundWire; +import static org.apache.tuscany.test.ArtifactFactory.createOutboundWire; +import static org.apache.tuscany.test.ArtifactFactory.createWireService; +import static org.apache.tuscany.test.ArtifactFactory.terminateWire; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.getCurrentArguments; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.reportMatcher; +import static org.easymock.EasyMock.verify; +import org.easymock.IAnswer; +import org.easymock.IArgumentMatcher; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class WireTestCase extends TestCase { + + private static final String SCRIPT = "import org.apache.tuscany.container.groovy.mock.Greeting;" + + "class Foo implements Greeting{" + + " Greeting wire;" + + " " + + " 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;" + + "class Foo implements Greeting{" + + " public String greet(String name){" + + " return name; " + + " }" + + "}"; + + private Class implClass1; + private Class implClass2; + private ScopeContainer scopeContainer; + + /** + * Tests a basic invocation down a source wire + */ + public void testReferenceWireInvocation() throws Exception { + List> services = new ArrayList>(); + services.add(Greeting.class); + GroovyConfiguration configuration = new GroovyConfiguration(); + configuration.setName("source"); + configuration.setGroovyClass(implClass1); + configuration.setServices(services); + configuration.setScopeContainer(scopeContainer); + configuration.setWireService(createWireService()); + GroovyAtomicComponent component = new GroovyAtomicComponent(configuration, null); + OutboundWire wire = createOutboundWire("wire", Greeting.class); + terminateWire(wire); + + TargetInvoker invoker = createMock(TargetInvoker.class); + expect(invoker.isCacheable()).andReturn(false); + Message response = new MessageImpl(); + response.setBody("foo"); + expect(invoker.invoke(eqMessage())).andReturn(response); + replay(invoker); + + for (OutboundInvocationChain chain : wire.getInvocationChains().values()) { + chain.setTargetInvoker(invoker); + } + component.addOutboundWire(wire); + Greeting greeting = (Greeting) component.getServiceInstance(); + assertEquals("foo", greeting.greet("foo")); + verify(invoker); + } + + // todo this could be generalized and moved to test module + public static Message eqMessage() { + reportMatcher(new IArgumentMatcher() { + public boolean matches(Object object) { + if (!(object instanceof Message)) { + return false; + } + final Message msg = (Message) object; + Object[] body = (Object[]) msg.getBody(); + return "foo".equals(body[0]); + } + + public void appendTo(StringBuffer stringBuffer) { + } + }); + return null; + } + + + /** + * Tests a basic invocation to a target + */ + public void testTargetInvocation() throws Exception { + List> services = new ArrayList>(); + services.add(Greeting.class); + GroovyConfiguration configuration = new GroovyConfiguration(); + configuration.setName("source"); + configuration.setGroovyClass(implClass2); + configuration.setServices(services); + configuration.setScopeContainer(scopeContainer); + configuration.setWireService(createWireService()); + GroovyAtomicComponent component = new GroovyAtomicComponent(configuration, null); + Operation operation = new Operation("greet", null, null, null, false, null); + TargetInvoker invoker = component.createTargetInvoker(null, operation); + assertEquals("foo", invoker.invokeTarget(new String[]{"foo"})); + } + + + /** + * Tests a basic invocation down a target wire + */ + public void testTargetWireInvocation() throws Exception { + List> services = new ArrayList>(); + services.add(Greeting.class); + GroovyConfiguration configuration = new GroovyConfiguration(); + configuration.setName("source"); + configuration.setGroovyClass(implClass2); + configuration.setServices(services); + configuration.setScopeContainer(scopeContainer); + configuration.setWireService(createWireService()); + GroovyAtomicComponent component = new GroovyAtomicComponent(configuration, null); + InboundWire wire = createInboundWire("Greeting", Greeting.class); + terminateWire(wire); + for (InboundInvocationChain chain : wire.getInvocationChains().values()) { + chain.setTargetInvoker(component.createTargetInvoker(null, chain.getOperation())); + } + component.addInboundWire(wire); + Greeting greeting = (Greeting) component.getServiceInstance("Greeting"); + assertEquals("foo", greeting.greet("foo")); + } + + protected void setUp() throws Exception { + super.setUp(); + GroovyClassLoader cl = new GroovyClassLoader(getClass().getClassLoader()); + implClass1 = cl.parseClass(SCRIPT); + implClass2 = cl.parseClass(SCRIPT2); + scopeContainer = createMock(ScopeContainer.class); + expect(scopeContainer.getInstance(isA(AtomicComponent.class))).andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + return ((AtomicComponent) getCurrentArguments()[0]).createInstance(); + } + }); + replay(scopeContainer); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/AsyncTarget.java b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/AsyncTarget.java new file mode 100644 index 0000000000..8918c3dfd5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/AsyncTarget.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.groovy.mock; + +/** + * @version $Rev$ $Date$ + */ +public interface AsyncTarget { + + void invoke(); +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/Greeting.java b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/Greeting.java new file mode 100644 index 0000000000..b975491f16 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/mock/Greeting.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.groovy.mock; + +public interface Greeting { + + String setWire(Greeting ref); + String greet(String name); +} -- cgit v1.2.3