diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /branches/sca-java-M2/sca/services/containers/container.spring/src/test/java |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-M2/sca/services/containers/container.spring/src/test/java')
11 files changed, 691 insertions, 0 deletions
diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java new file mode 100644 index 0000000000..80b22d6784 --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java @@ -0,0 +1,58 @@ +/* + * 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.spring; + +import junit.framework.TestCase; +import org.apache.tuscany.container.spring.config.ScaApplicationContext; +import org.apache.tuscany.container.spring.mock.TestReference; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.io.ClassPathResource; +import org.springframework.sca.ScaServiceExporter; +import org.springframework.sca.ScaServiceProxyFactoryBean; + +/** + * Tests the SCA extensible schema elements for Spring's XML configuration files + * + * @version $$Rev$$ $$Date$$ + */ + +public class SpringConfigSchemaTestCase extends TestCase { + + private ConfigurableApplicationContext applicationContext; + + public void setUp() { + applicationContext = + new ScaApplicationContext(null, + new ClassPathResource("org/apache/tuscany/container/spring/SpringConfigSchemaTest.xml"), null); + } + + public void testSCAService() { + ScaServiceExporter service = (ScaServiceExporter) applicationContext.getBean("fooService"); + // FIXME andyp -- this is not really right. +// TestBean service = (TestBean) applicationContext.getBean("fooService"); +// assertEquals("call me", service.echo("call me")); + } + + public void testSCAReference() { + ScaServiceProxyFactoryBean pf = (ScaServiceProxyFactoryBean) applicationContext.getBean("&fooReference"); + assertEquals("fooReference", pf.getReferenceName()); + TestReference ref = (TestReference) applicationContext.getBean("fooReference"); +// assertNotNull(ref); + } +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java new file mode 100644 index 0000000000..3d07c753de --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java @@ -0,0 +1,70 @@ +/* + * 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.spring; + +import org.apache.tuscany.spi.QualifiedName; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.builder.Connector; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.extension.ServiceExtension; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.OutboundWire; +import org.apache.tuscany.spi.wire.WireService; + +import org.apache.tuscany.container.spring.mock.TestBeanImpl; +import org.apache.tuscany.test.ArtifactFactory; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.context.support.GenericApplicationContext; + +/** + * @version $$Rev$$ $$Date$$ + */ + +public final class SpringTestUtils { + private SpringTestUtils() { + } + + public static <T> Service createService(String name, + Class<T> serviceInterface, + CompositeComponent parent, + WireService wireService) throws InvalidServiceContractException { + Service service = new ServiceExtension(name, serviceInterface, parent, wireService); + InboundWire inboundWire = ArtifactFactory.createInboundWire(name, serviceInterface); + OutboundWire outboundWire = ArtifactFactory.createOutboundWire(name, serviceInterface); + ArtifactFactory.terminateWire(outboundWire); + service.setInboundWire(inboundWire); + service.setOutboundWire(outboundWire); + outboundWire.setTargetName(new QualifiedName("foo")); + Connector connector = ArtifactFactory.createConnector(); + connector.connect(service); + ArtifactFactory.terminateWire(inboundWire); + return service; + } + + + public static GenericApplicationContext createContext() { + GenericApplicationContext ctx = new GenericApplicationContext(); + BeanDefinition definition = new RootBeanDefinition(TestBeanImpl.class); + ctx.registerBeanDefinition("foo", definition); + return ctx; + } + +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceInvocationTestCase.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceInvocationTestCase.java new file mode 100644 index 0000000000..ff5a564ee8 --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceInvocationTestCase.java @@ -0,0 +1,68 @@ +/* + * 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.spring.impl; + +import org.apache.tuscany.spi.component.Reference; + +import junit.framework.TestCase; +import org.apache.tuscany.container.spring.mock.TestBean; +import org.apache.tuscany.container.spring.mock.TestBeanImpl; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import org.springframework.beans.PropertyValue; +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.StaticApplicationContext; + +/** + * Verifies wiring from a Spring bean to an SCA composite reference + * + * @version $$Rev$$ $$Date$$ + */ +public class ReferenceInvocationTestCase extends TestCase { + + public void testInvocation() throws Exception { + AbstractApplicationContext ctx = createSpringContext(); + SpringCompositeComponent parent = new SpringCompositeComponent("spring", ctx, null, null, null); + parent.start(); + TestBean referenceTarget = new TestBeanImpl(); + Reference reference = createMock(Reference.class); + expect(reference.getName()).andReturn("bar").anyTimes(); + expect(reference.isSystem()).andReturn(false).atLeastOnce(); + expect(reference.getInterface()).andStubReturn(TestBean.class); + expect(reference.getServiceInstance()).andStubReturn(referenceTarget); + replay(reference); + parent.register(reference); + ctx.getBean("foo"); + } + + private AbstractApplicationContext createSpringContext() { + StaticApplicationContext beanFactory = new StaticApplicationContext(); + RootBeanDefinition definition = new RootBeanDefinition(TestBeanImpl.class); + //REVIEW we need to figure out how to handle eager init components + definition.setLazyInit(true); + RuntimeBeanReference ref = new RuntimeBeanReference("bar"); + PropertyValue val = new PropertyValue("bean", ref); + definition.getPropertyValues().addPropertyValue(val); + beanFactory.registerBeanDefinition("foo", definition); + return beanFactory; + } +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ServiceInvocationTestCase.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ServiceInvocationTestCase.java new file mode 100644 index 0000000000..596d9f1181 --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ServiceInvocationTestCase.java @@ -0,0 +1,76 @@ +/* + * 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.spring.impl; + +import org.apache.tuscany.spi.builder.Connector; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.extension.ServiceExtension; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.wire.InboundInvocationChain; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.OutboundWire; +import org.apache.tuscany.spi.QualifiedName; + +import junit.framework.TestCase; +import org.apache.tuscany.container.spring.mock.TestBean; +import org.apache.tuscany.container.spring.mock.TestBeanImpl; +import org.apache.tuscany.test.ArtifactFactory; +import static org.apache.tuscany.test.ArtifactFactory.createWireService; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.StaticApplicationContext; + +/** + * Tests a simple invocation through a service to a Spring bean + * + * @version $$Rev$$ $$Date$$ + */ +public class ServiceInvocationTestCase extends TestCase { + + public void testInvocation() throws InvalidServiceContractException { + AbstractApplicationContext springContext = createSpringContext(); + SpringCompositeComponent composite = new SpringCompositeComponent("parent", springContext, null, null, null); + InboundWire inboundWire = ArtifactFactory.createInboundWire("fooService", TestBean.class); + OutboundWire outboundWire = ArtifactFactory.createOutboundWire("fooService", TestBean.class); + outboundWire.setTargetName(new QualifiedName("foo")); + ArtifactFactory.terminateWire(outboundWire); + Service service = + new ServiceExtension("fooService", TestBean.class, composite, createWireService()); + service.setInboundWire(inboundWire); + service.setOutboundWire(outboundWire); + Connector connector = ArtifactFactory.createConnector(); + connector.connect(inboundWire, outboundWire, true); + for (InboundInvocationChain chain : inboundWire.getInvocationChains().values()) { + chain.setTargetInvoker(composite.createTargetInvoker("foo", chain.getOperation())); + } + composite.register(service); + TestBean serviceInstance = (TestBean) composite.getService("fooService").getServiceInstance(); + assertEquals("bar", serviceInstance.echo("bar")); + } + + + private AbstractApplicationContext createSpringContext() { + StaticApplicationContext beanFactory = new StaticApplicationContext(); + RootBeanDefinition definition = new RootBeanDefinition(TestBeanImpl.class); + definition.setLazyInit(true); + beanFactory.registerBeanDefinition("foo", definition); + return beanFactory; + } + +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java new file mode 100644 index 0000000000..50ce9a7b75 --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java @@ -0,0 +1,137 @@ +/* + * 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.spring.impl; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.apache.tuscany.spi.builder.BuilderRegistry; +import org.apache.tuscany.spi.builder.Connector; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.ServiceExtension; +import org.apache.tuscany.spi.model.BoundServiceDefinition; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.OutboundWire; +import org.apache.tuscany.spi.wire.WireService; + +import junit.framework.TestCase; +import static org.apache.tuscany.container.spring.SpringTestUtils.createContext; +import org.apache.tuscany.container.spring.mock.TestBean; +import org.apache.tuscany.container.spring.model.SpringComponentType; +import org.apache.tuscany.container.spring.model.SpringImplementation; +import org.apache.tuscany.test.ArtifactFactory; +import org.apache.tuscany.test.binding.TestBinding; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.createNiceMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class SpringCompositeBuilderTestCase extends TestCase { + + /** + * Verfies basic build of a spring context + */ + @SuppressWarnings("unchecked") + public void testBuild() throws Exception { + // Create an assembly model consisting of a component implemented by Spring + SpringImplementation impl = new SpringImplementation(new SpringComponentType(createContext())); + ComponentDefinition<SpringImplementation> componentDefinition = + new ComponentDefinition<SpringImplementation>("spring", impl); + + // Configure the mock builder registry + BuilderRegistry registry = createNiceMock(BuilderRegistry.class); + + // Test the SpringCompositeBuilder + SpringCompositeBuilder builder = new SpringCompositeBuilder(); + builder.setBuilderRegistry(registry); + CompositeComponent parent = createNiceMock(CompositeComponent.class); + DeploymentContext context = createNiceMock(DeploymentContext.class); + SpringCompositeComponent component = + (SpringCompositeComponent) builder.build(parent, componentDefinition, context); + TestBean bean = (TestBean) component.getApplicationContext().getBean("foo"); + assertEquals("call foo", bean.echo("call foo")); + } + + /** + * Verifies that the builder calls back into the registry to load services and wires them to bean targets when no + * <code>sca:service</code> tag is specified in the Spring application.xml + */ + @SuppressWarnings("unchecked") + public void testImplicitServiceWiring() throws Exception { + // Create an assembly model consisting of a component implemented by Spring + SpringImplementation impl = new SpringImplementation(createComponentType()); + ComponentDefinition<SpringImplementation> componentDefinition = + new ComponentDefinition<SpringImplementation>("spring", impl); + + // Create a service instance that the mock builder registry will return + WireService wireService = ArtifactFactory.createWireService(); + ServiceExtension serviceContext = + new ServiceExtension("fooService", TestBean.class, null, wireService); + InboundWire inboundWire = ArtifactFactory.createInboundWire("fooService", TestBean.class); + OutboundWire outboundWire = ArtifactFactory.createOutboundWire("fooService", TestBean.class); + ArtifactFactory.terminateWire(outboundWire); + serviceContext.setInboundWire(inboundWire); + serviceContext.setOutboundWire(outboundWire); + Connector connector = ArtifactFactory.createConnector(); + connector.connect(inboundWire, outboundWire, true); + + // Configure the mock builder registry + BuilderRegistry registry = createMock(BuilderRegistry.class); + expect(registry.build(isA(CompositeComponent.class), + isA(BoundServiceDefinition.class), + isA(DeploymentContext.class))).andStubReturn(serviceContext); + replay(registry); + + // Test the SpringCompositeBuilder + SpringCompositeBuilder builder = new SpringCompositeBuilder(); + builder.setWireService(wireService); + builder.setBuilderRegistry(registry); + CompositeComponent parent = createNiceMock(CompositeComponent.class); + DeploymentContext context = createNiceMock(DeploymentContext.class); + CompositeComponent component = (CompositeComponent) builder.build(parent, componentDefinition, context); + Service service = component.getService("fooService"); + TestBean bean = (TestBean) service.getServiceInstance(); + assertEquals("call foo", bean.echo("call foo")); + verify(registry); + } + + @SuppressWarnings("unchecked") + private SpringComponentType createComponentType() { + SpringComponentType componentType = new SpringComponentType(createContext()); + BoundServiceDefinition<TestBinding> serviceDefinition = new BoundServiceDefinition<TestBinding>(); + serviceDefinition.setName("fooService"); + serviceDefinition.setBinding(new TestBinding()); + try { + serviceDefinition.setTarget(new URI("foo")); + } catch (URISyntaxException e) { + throw new AssertionError(); + } + componentType.add(serviceDefinition); + return componentType; + } + +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.java new file mode 100644 index 0000000000..f3ac13d030 --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.java @@ -0,0 +1,64 @@ +/* + * 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.spring.impl; + +import org.apache.tuscany.spi.component.Service; + +import junit.framework.TestCase; +import static org.easymock.EasyMock.expect; +import org.easymock.classextension.EasyMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.AbstractApplicationContext; + +/** + * @version $Rev$ $Date$ + */ +public class SpringCompositeComponentTestCase extends TestCase { + + public void testAppContextStart() { + AbstractApplicationContext appContext = EasyMock.createMock(AbstractApplicationContext.class); + appContext.refresh(); + appContext.setParent(EasyMock.isA(ApplicationContext.class)); + appContext.start(); + replay(appContext); + SpringCompositeComponent component = new SpringCompositeComponent("spring", appContext, null, null, null); + component.start(); + verify(appContext); + } + + public void testChildStart() { + AbstractApplicationContext appContext = EasyMock.createNiceMock(AbstractApplicationContext.class); + replay(appContext); + Service service = EasyMock.createMock(Service.class); + EasyMock.expect(service.getName()).andReturn("foo").anyTimes(); + service.start(); + service.getInterface(); + EasyMock.expectLastCall().andReturn(Object.class); + expect(service.isSystem()).andReturn(false).atLeastOnce(); + replay(service); + SpringCompositeComponent component = new SpringCompositeComponent("spring", appContext, null, null, null); + component.register(service); + component.start(); + verify(service); + } + + +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.java new file mode 100644 index 0000000000..b110852a54 --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.java @@ -0,0 +1,62 @@ +/* + * 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.spring.impl; + +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; + +import junit.framework.TestCase; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import org.springframework.context.ApplicationContext; + +/** + * Verifies a simple invocation on a Spring bean + * + * @version $$Rev$$ $$Date$$ + */ +public class SpringInvocationTestCase extends TestCase { + + /** + * Verifies the invoker can resolve a bean in an application context and call a method l + */ + public void testInvocation() throws Exception { + TestBean bean = createMock(TestBean.class); + bean.test("bar"); + expectLastCall(); + replay(bean); + ApplicationContext context = createMock(ApplicationContext.class); + expect(context.getBean("foo")).andReturn(bean); + replay(context); + SpringInvoker invoker = new SpringInvoker("foo", TestBean.class.getMethod("test", String.class), context); + Message msg = new MessageImpl(); + msg.setBody(new String[]{"bar"}); + invoker.invoke(msg); + verify(context); + verify(bean); + } + + + private interface TestBean { + void test(String msg); + } +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/integration/BootstrapTestCase.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/integration/BootstrapTestCase.java new file mode 100644 index 0000000000..c5758cb2ac --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/integration/BootstrapTestCase.java @@ -0,0 +1,57 @@ +/* + * 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.spring.integration; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +import org.apache.tuscany.spi.component.Service; + +import org.apache.tuscany.container.spring.impl.SpringCompositeComponent; +import org.apache.tuscany.container.spring.mock.TestBean; +import org.apache.tuscany.test.Bootstrapper; + +/** + * Bootstraps a simple scenario where a service can invoke a Spring bean. This test case is intended to be temporary and + * replaced when the SPI test harness is finished. + * <p/> + * <bold>PLEASE DO NOT EMULATE</bold> + * + * @version $Rev$ $Date$ + */ +public class BootstrapTestCase extends Bootstrapper { + + private CompositeContext context; + + public void testDemoBoot() { + SpringCompositeComponent comp = (SpringCompositeComponent) component.getChild("Spring"); + Service service = (Service) comp.getChild("fooService"); + TestBean bean = (TestBean) service.getServiceInstance(); + bean.echo("foo"); + bean.getBean().echo("foo"); + } + + protected void setUp() throws Exception { + addExtension("spring.extension", getClass().getClassLoader().getResource("META-INF/sca/spring.system.scdl")); + super.setUp(); + context = CurrentCompositeContext.getContext(); + } + + +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBean.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBean.java new file mode 100644 index 0000000000..1c768e53cc --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBean.java @@ -0,0 +1,31 @@ +/* + * 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.spring.mock; + +/** + * @version $$Rev$$ $$Date$$ + */ +public interface TestBean { + String echo(String msg); + + TestBean getBean(); + + void setBean(TestBean bean); + +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBeanImpl.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBeanImpl.java new file mode 100644 index 0000000000..db04d8bcad --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBeanImpl.java @@ -0,0 +1,42 @@ +/* + * 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.spring.mock; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class TestBeanImpl implements TestBean { + + private TestBean bean; + + public TestBeanImpl() { + } + + public String echo(String msg) { + return msg; + } + + public TestBean getBean() { + return bean; + } + + public void setBean(TestBean bean) { + this.bean = bean; + } +} diff --git a/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.java b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.java new file mode 100644 index 0000000000..7d1a519be6 --- /dev/null +++ b/branches/sca-java-M2/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.java @@ -0,0 +1,26 @@ +/* + * 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.spring.mock; + +/** + * @version $$Rev$$ $$Date$$ + */ +public interface TestReference { + String echo(String msg); +} |