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 /tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test |
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 'tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test')
18 files changed, 951 insertions, 0 deletions
diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java new file mode 100644 index 0000000000..13b2c684d7 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/SpringConfigSchemaTestCase.java @@ -0,0 +1,52 @@ +/* + * 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; + +/** + * 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")); +// } +// + 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/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java new file mode 100644 index 0000000000..4a73b6628b --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/SpringTestUtils.java @@ -0,0 +1,73 @@ +/* + * 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 java.net.URI; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.builder.WiringException; +import org.apache.tuscany.spi.component.ServiceBinding; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.extension.ServiceBindingExtension; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.wire.TargetInvoker; + +import org.apache.tuscany.container.spring.mock.TestBeanImpl; +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> ServiceBinding createService(URI uri, Class<T> serviceInterface) + throws InvalidServiceContractException, WiringException { + return new ServiceBindingExtension(uri) { + public QName getBindingType() { + return null; + } + + public TargetInvoker createTargetInvoker(String targetName, Operation operation) + throws TargetInvokerCreationException { + return null; + } + + public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation) + throws TargetInvokerCreationException { + return null; + } + }; + } + + + public static GenericApplicationContext createContext() { + GenericApplicationContext ctx = new GenericApplicationContext(); + BeanDefinition definition = new RootBeanDefinition(TestBeanImpl.class); + ctx.registerBeanDefinition("foo", definition); + return ctx; + } + +} diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/TestClassResource.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/TestClassResource.java new file mode 100644 index 0000000000..f93957cb8b --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/TestClassResource.java @@ -0,0 +1,45 @@ +/* + * 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 java.io.InputStream; +import java.io.IOException; + +import org.springframework.core.io.AbstractResource; + +/** + * @version $Rev$ $Date$ + */ +public class TestClassResource extends AbstractResource { + private Class<?> clazz; + private String fileName; + + public TestClassResource(Class<?> clazz, String fileName) { + this.clazz = clazz; + this.fileName = fileName; + } + + public String getDescription() { + return "test resource"; + } + + public InputStream getInputStream() throws IOException { + return clazz.getResourceAsStream(fileName); + } +} diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceWiringTestCase.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceWiringTestCase.java new file mode 100644 index 0000000000..b1e5733cd8 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/ReferenceWiringTestCase.java @@ -0,0 +1,151 @@ +/* + * 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.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.osoa.sca.CallableReference; + +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.ReferenceBinding; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.wire.ChainHolder; +import org.apache.tuscany.spi.wire.IncompatibleServiceContractException; +import org.apache.tuscany.spi.wire.ProxyCreationException; +import org.apache.tuscany.spi.wire.ProxyService; +import org.apache.tuscany.spi.wire.Wire; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.extension.ReferenceBindingExtension; + +import junit.framework.TestCase; +import org.apache.tuscany.container.spring.mock.TestBean; +import org.easymock.EasyMock; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; + +/** + * Verifies wiring from a Spring bean to an SCA composite reference + * + * @version $$Rev$$ $$Date$$ + */ +public class ReferenceWiringTestCase extends TestCase { + + public void testInvocation() throws Exception { + ClassLoader loader = getClass().getClassLoader(); + URL url = loader.getResource("META-INF/sca/testReferenceContext.xml"); + Resource resource = new UrlResource(url); + URI uri = URI.create("spring"); + ProxyService proxyService = new MockProxyService(); + SpringCompositeComponent parent = new SpringCompositeComponent(uri, resource, proxyService, null, loader); + Wire wire = EasyMock.createMock(Wire.class); + ServiceContract<?> contract = new ServiceContract(TestBean.class) { + }; + EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce(); + EasyMock.replay(wire); + ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class); + EasyMock.expect(referenceBinding.getWire()).andStubReturn(wire); + referenceBinding.start(); + EasyMock.replay(referenceBinding); + + URI referenceUri = URI.create("spring#testReference"); + ReferenceBinding binding = new ReferenceBindingExtension(referenceUri, null){ + + public QName getBindingType() { + return null; + } + + public TargetInvoker createTargetInvoker(String targetName, Operation operation) + throws TargetInvokerCreationException { + throw new UnsupportedOperationException(); + } + + public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation) + throws TargetInvokerCreationException { + return null; + } + }; + binding.setWire(wire); + List<ReferenceBinding> bindings = new ArrayList<ReferenceBinding>(); + bindings.add(binding); + Reference reference = EasyMock.createMock(Reference.class); + EasyMock.expect(reference.getUri()).andReturn(referenceUri).anyTimes(); + EasyMock.expect(reference.getReferenceBindings()).andReturn(bindings).atLeastOnce(); + reference.start(); + EasyMock.replay(reference); + parent.register(reference); + parent.start(); + TestBean bean = parent.getBean(TestBean.class, "testBean"); + assertNotNull(bean.getBean()); + EasyMock.verify(reference); + } + + private class MockInvocationHandler implements InvocationHandler { + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return null; + } + } + + private class MockProxyService implements ProxyService { + + public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException { + ClassLoader cl = interfaze.getClassLoader(); + Class[] interfaces = new Class[]{interfaze}; + MockInvocationHandler handler = new MockInvocationHandler(); + return interfaze.cast(Proxy.newProxyInstance(cl, interfaces, handler)); + } + + public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping) + throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException { + throw new UnsupportedOperationException(); + } + + public boolean checkCompatibility(ServiceContract<?> source, + ServiceContract<?> target, + boolean ignoreCallback, + boolean silent) throws IncompatibleServiceContractException { + throw new UnsupportedOperationException(); + } + } + +} diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java new file mode 100644 index 0000000000..fb9d107b71 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java @@ -0,0 +1,131 @@ +/* + * 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.URL; + +import org.apache.tuscany.spi.builder.BuilderRegistry; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.Property; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ServiceDefinition; + +import junit.framework.TestCase; +import org.apache.tuscany.container.spring.model.SpringComponentType; +import org.apache.tuscany.container.spring.model.SpringImplementation; +import org.easymock.EasyMock; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class SpringCompositeBuilderTestCase extends TestCase { + + /** + * Verifies that the builder calls back into the registry to load services and references when no + * <code>sca:service</code> tag is specified in the Spring application.xml + */ + public void testImplicitServiceWiring() throws Exception { + Service service = EasyMock.createMock(Service.class); + // Configure the mock builder registry + BuilderRegistry registry = EasyMock.createMock(BuilderRegistry.class); + EasyMock.expect(registry.build( + EasyMock.isA(ServiceDefinition.class), + EasyMock.isA(DeploymentContext.class))).andStubReturn(service); + EasyMock.replay(registry); + SpringCompositeBuilder builder = new SpringCompositeBuilder(); + builder.setBuilderRegistry(registry); + ComponentDefinition<SpringImplementation> definition = createDefinitionWithService(); + Component component = builder.build(definition, null); + assertNotNull(component); + EasyMock.verify(registry); + } + + /** + * Verifies that the builder calls back into the registry to load services and references when no + * <code>sca:reference</code> tag is specified in the Spring application.xml + */ + public void testImplicitReferenceWiring() throws Exception { + Service service = EasyMock.createMock(Service.class); + // Configure the mock builder registry + BuilderRegistry registry = EasyMock.createMock(BuilderRegistry.class); + EasyMock.expect(registry.build( + EasyMock.isA(ServiceDefinition.class), + EasyMock.isA(DeploymentContext.class))).andStubReturn(service); + EasyMock.replay(registry); + SpringCompositeBuilder builder = new SpringCompositeBuilder(); + builder.setBuilderRegistry(registry); + ComponentDefinition<SpringImplementation> definition = createDefinitionWithReference(); + Component component = builder.build(definition, null); + assertNotNull(component); + EasyMock.verify(registry); + } + + protected ComponentDefinition<SpringImplementation> createDefinitionWithService() throws Exception { + super.setUp(); + ClassLoader loader = getClass().getClassLoader(); + URL url = loader.getResource("META-INF/sca/testServiceContext.xml"); + Resource resource = new UrlResource(url); + SpringComponentType<Property<?>> type = createComponentTypeWithService(); + SpringImplementation impl = new SpringImplementation(loader); + impl.setComponentType(type); + URI uri = URI.create("composite"); + ComponentDefinition<SpringImplementation> definition = new ComponentDefinition<SpringImplementation>(uri, impl); + impl.setApplicationResource(resource); + return definition; + } + + protected ComponentDefinition<SpringImplementation> createDefinitionWithReference() throws Exception { + super.setUp(); + ClassLoader loader = getClass().getClassLoader(); + URL url = loader.getResource("META-INF/sca/testServiceContext.xml"); + Resource resource = new UrlResource(url); + SpringComponentType<Property<?>> type = createComponentTypeWithReference(); + SpringImplementation impl = new SpringImplementation(loader); + impl.setComponentType(type); + URI uri = URI.create("composite"); + ComponentDefinition<SpringImplementation> definition = new ComponentDefinition<SpringImplementation>(uri, impl); + impl.setApplicationResource(resource); + return definition; + } + + private SpringComponentType<Property<?>> createComponentTypeWithService() { + SpringComponentType<Property<?>> componentType = new SpringComponentType<Property<?>>(); + ServiceDefinition serviceDefinition = new ServiceDefinition(); + serviceDefinition.setUri(URI.create("fooService")); + serviceDefinition.setTarget(URI.create("testBean")); + componentType.add(serviceDefinition); + return componentType; + } + + private SpringComponentType<Property<?>> createComponentTypeWithReference() { + SpringComponentType<Property<?>> componentType = new SpringComponentType<Property<?>>(); + ReferenceDefinition referenceDefinition = new ReferenceDefinition(); + referenceDefinition.setUri(URI.create("fooReference")); + componentType.add(referenceDefinition); + return componentType; + } + + +} diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.java new file mode 100644 index 0000000000..d014d99ad7 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeComponentTestCase.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 java.lang.reflect.Type; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; + +import junit.framework.TestCase; +import org.easymock.classextension.EasyMock; +import org.springframework.context.support.AbstractApplicationContext; + +/** + * @version $Rev$ $Date$ + */ +public class SpringCompositeComponentTestCase extends TestCase { + private SpringCompositeComponent component; + + public void testChildStart() throws Exception { + AbstractApplicationContext appContext = EasyMock.createNiceMock(AbstractApplicationContext.class); + EasyMock.replay(appContext); + Service service = EasyMock.createMock(Service.class); + URI uri = URI.create("composite#service"); + EasyMock.expect(service.getUri()).andReturn(uri).atLeastOnce(); + service.start(); + EasyMock.replay(service); + component.setSpringContext(appContext); + component.register(service); + component.start(); + EasyMock.verify(service); + } + + public void testTargetInvokerCreation() throws Exception { + ServiceContract<Type> contract = new ServiceContract<Type>(Foo.class) { + }; + Operation<Type> operation = new Operation<Type>("operation", null, null, null); + Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(); + operations.put("operation", operation); + contract.setOperations(operations); + operation.setServiceContract(contract); + component.createTargetInvoker("bean", operation); + } + + + protected void setUp() throws Exception { + super.setUp(); + URI compositeUri = URI.create("composite"); + component = new SpringCompositeComponent(compositeUri, null, null, null, null); + + } + + private interface Foo { + void operation(); + } +} diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.java new file mode 100644 index 0000000000..e4a6ad0eb7 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringInvocationTestCase.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.impl; + +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; + +import junit.framework.TestCase; +import org.easymock.classextension.EasyMock; + +/** + * 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 = EasyMock.createMock(TestBean.class); + bean.test("bar"); + EasyMock.expectLastCall(); + EasyMock.replay(bean); + SpringCompositeComponent context = EasyMock.createMock(SpringCompositeComponent.class); + EasyMock.expect(context.getBean(Object.class, "foo")).andReturn(bean); + EasyMock.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); + EasyMock.verify(context); + EasyMock.verify(bean); + } + + + private interface TestBean { + void test(String msg); + } +} diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBean.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBean.java new file mode 100644 index 0000000000..1c768e53cc --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-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/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBeanImpl.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/mock/TestBeanImpl.java new file mode 100644 index 0000000000..db04d8bcad --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-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/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.java b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.java new file mode 100644 index 0000000000..618c0d60cc --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/java/org/apache/tuscany/container/spring/mock/TestReference.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.spring.mock; + +/** + * @version $$Rev$$ $$Date$$ + */ +public interface TestReference { + String echo(String msg); +} diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/application-context.xml b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/application-context.xml new file mode 100644 index 0000000000..6ccd3963a9 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/application-context.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:sca="http://www.springframework.org/schema/sca" + xsi:schemaLocation=" +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd"> + + <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl" lazy-init="true"> + <property name="bean" ref="testReference"/> + </bean> + <!-- <sca:reference name="testReference" type="org.apache.tuscany.container.spring.mock.TestReference"/> --> + +</beans> diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/default.scdl b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..0b2c92c667 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/default.scdl @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. + --> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + name="spring.test"> + + <component name="Spring"> + <implementation.spring location="META-INF/sca/application-context.xml"> + <service name="fooService"> + <binding.test/> + <interface.java class="org.apache.tuscany.container.spring.mock.TestBean"/> + <reference>testBean</reference> + </service> + <reference name="testReference"> + <interface.java class="org.apache.tuscany.container.spring.mock.TestBean"/> + <binding.test/> + </reference> + </implementation.spring> + </component> + +</composite> diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/testReferenceContext.xml b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/testReferenceContext.xml new file mode 100644 index 0000000000..282c8c50fa --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/testReferenceContext.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:sca="http://www.springframework.org/schema/sca" + xsi:schemaLocation=" +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd"> + + <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl"> + <property name="bean" ref="testReference"/> + </bean> + + <sca:reference name="testReference" type="org.apache.tuscany.container.spring.mock.TestBean"/> + +</beans> diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/testServiceContext.xml b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/testServiceContext.xml new file mode 100644 index 0000000000..0a3e597fc1 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/sca/testServiceContext.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:sca="http://www.springframework.org/schema/sca" + xsi:schemaLocation=" +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd"> + + <sca:service name="fooService" type="org.apache.tuscany.container.spring.mock.TestBeanImpl" target="testBean"/> + + <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl"/> + +</beans> diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/tuscany/xsystem.scdl b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/tuscany/xsystem.scdl new file mode 100644 index 0000000000..0ef2781492 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/META-INF/tuscany/xsystem.scdl @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. + --> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + name="spring.test"> + <!-- + <component name="Spring"> + <implementation.spring location="META-INF/sca/application-context.xml"> + <service name="fooService"> + <binding.test/> + <interface.java class="org.apache.tuscany.container.spring.mock.TestBean"/> + <reference>testBean</reference> + </service> + <reference name="testReference"> + <interface.java class="org.apache.tuscany.container.spring.mock.TestBean"/> + <binding.test/> + </reference> + </implementation.spring> + </component> --> + +</composite> diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/org/apache/tuscany/container/spring/ExplicitSpring.xml b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/org/apache/tuscany/container/spring/ExplicitSpring.xml new file mode 100644 index 0000000000..211211511b --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/org/apache/tuscany/container/spring/ExplicitSpring.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:sca="http://www.springframework.org/schema/sca" + xsi:schemaLocation=" +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd"> + + <sca:service name="fooBean" type="org.apache.tuscany.container.spring.mock.TestBeanImpl" target="testBean"/> + + <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl"> + </bean> + +</beans> diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/org/apache/tuscany/container/spring/SpringConfigSchemaTest.xml b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/org/apache/tuscany/container/spring/SpringConfigSchemaTest.xml new file mode 100644 index 0000000000..96a3e1ed46 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/org/apache/tuscany/container/spring/SpringConfigSchemaTest.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:sca="http://www.springframework.org/schema/sca" + xsi:schemaLocation=" +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd"> + + <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl"> + </bean> + + <sca:service name="fooService" type="org.apache.tuscany.container.spring.mock.TestBean" target="testBean"/> + + <sca:reference name="fooReference" type="org.apache.tuscany.container.spring.mock.TestReference"/> + + +</beans> diff --git a/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/test.xml b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/test.xml new file mode 100644 index 0000000000..d438b88577 --- /dev/null +++ b/tags/java/sca/0.90-rc1-incubating/modules/implementation-spring/src/test/resources/test.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:sca="http://www.springframework.org/schema/sca" + xsi:schemaLocation=" +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +http://www.springframework.org/schema/sca http://www.springframework.org/schema/sca/spring-sca.xsd"> + + <bean id="testBean" class="org.apache.tuscany.container.spring.mock.TestBeanImpl"/> + +</beans> |