From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/host/embedded/SCADomainBeanTestCase.java | 57 +++++++ .../sca/host/embedded/SCADomainTestCase.java | 56 ++++++ .../embedded/impl/DefaultSCADomainTestCase.java | 63 +++++++ .../embedded/impl/EmbeddedSCADomainTestCase.java | 189 +++++++++++++++++++++ .../sca/host/embedded/impl/TestModelResolver.java | 104 ++++++++++++ .../DefaultTestImplementationFactory.java | 47 +++++ .../test/extension/TestImplementation.java | 44 +++++ .../test/extension/TestImplementationFactory.java | 37 ++++ .../host/embedded/test/extension/TestService.java | 30 ++++ .../extension/impl/TestImplementationImpl.java | 117 +++++++++++++ .../impl/TestImplementationProcessor.java | 96 +++++++++++ .../test/extension/module/TestModuleActivator.java | 65 +++++++ .../provider/TestImplementationProvider.java | 64 +++++++ .../TestImplementationProviderFactory.java | 47 +++++ .../test/extension/provider/TestInvoker.java | 52 ++++++ 15 files changed, 1068 insertions(+) create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java create mode 100644 branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.java (limited to 'branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache') diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java new file mode 100644 index 0000000000..9252b114a1 --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.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.sca.host.embedded; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.test.extension.TestService; +import org.osoa.sca.ServiceReference; + + + +/** + * Test creation of an SCADomainBean and invocation of a service. + * + * @version $Rev$ $Date$ + */ +public class SCADomainBeanTestCase extends TestCase { + + private SCADomainBean domain; + + @Override + protected void setUp() throws Exception { + domain = new SCADomainBean(); + domain.setDeployableComposites("test.composite"); + } + + public void testInvoke() throws Exception { + ServiceReference serviceReference = domain.getServiceReference(TestService.class, "TestServiceComponent"); + assertNotNull(serviceReference); + TestService service = serviceReference.getService(); + String result = service.ping("Bob"); + assertEquals("Hello Bob", result); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java new file mode 100644 index 0000000000..c52c16d8e1 --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java @@ -0,0 +1,56 @@ +/* + * 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.sca.host.embedded; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.test.extension.TestService; +import org.osoa.sca.ServiceReference; + + + +/** + * Test SCADomain.newInstance and invocation of a service. + * + * @version $Rev$ $Date$ + */ +public class SCADomainTestCase extends TestCase { + + private SCADomain domain; + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("test.composite"); + } + + public void testInvoke() throws Exception { + ServiceReference serviceReference = domain.getServiceReference(TestService.class, "TestServiceComponent"); + assertNotNull(serviceReference); + TestService service = serviceReference.getService(); + String result = service.ping("Bob"); + assertEquals("Hello Bob", result); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java new file mode 100644 index 0000000000..087a75426b --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java @@ -0,0 +1,63 @@ +/* + * 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.sca.host.embedded.impl; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.management.ComponentManager; +import org.apache.tuscany.sca.host.embedded.test.extension.TestService; + + +/** + * Test creation of DefaultSCADomain. + * + * @version $Rev$ $Date$ + */ +public class DefaultSCADomainTestCase extends TestCase { + private DefaultSCADomain domain; + + @Override + protected void setUp() throws Exception { + domain = new DefaultSCADomain(getClass().getClassLoader(), getClass().getClassLoader(), + "http://localhost", ".", "test.composite"); + } + + public void testStart() throws Exception { + TestService service = domain.getService(TestService.class, "TestServiceComponent"); + assertNotNull(service); + } + + public void testComponentManager() throws Exception { + ComponentManager componentManager = domain.getComponentManager(); + assertEquals(1, componentManager.getComponentNames().size()); + assertEquals("TestServiceComponent", componentManager.getComponentNames().iterator().next()); + assertNotNull(componentManager.getComponent("TestServiceComponent")); + + assertTrue(componentManager.isComponentStarted("TestServiceComponent")); + componentManager.stopComponent("TestServiceComponent"); + assertFalse(componentManager.isComponentStarted("TestServiceComponent")); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java new file mode 100644 index 0000000000..2a59635a19 --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.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.sca.host.embedded.impl; + +import java.net.URL; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.service.ContributionService; +import org.apache.tuscany.sca.host.embedded.management.ComponentListener; +import org.apache.tuscany.sca.host.embedded.management.ComponentManager; +import org.apache.tuscany.sca.host.embedded.test.extension.TestService; + +/** + * Test creation of an EmbeddedSCADomain and invocation of a service. + * + * @version $Rev$ $Date$ + */ +public class EmbeddedSCADomainTestCase extends TestCase { + private EmbeddedSCADomain domain; + + @Override + protected void setUp() throws Exception { + + // Create a test embedded SCA domain + domain = new EmbeddedSCADomain(getClass().getClassLoader(), "http://localhost"); + } + + public void testDomain() throws Exception { + // Start the domain + domain.start(); + + // Determine my class loader and my test SCA contribution location + ClassLoader myClassLoader = getClass().getClassLoader(); + String url = myClassLoader.getResource("test.txt").toString(); + url = url.substring(0, url.length()-8); + + // Contribute the SCA contribution + TestModelResolver myResolver = new TestModelResolver(myClassLoader); + ContributionService contributionService = domain.getContributionService(); + Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false); + assertNotNull(contribution); + + // Decide which SCA composite I want to deploy + Composite myComposite = myResolver.getComposite(new QName("http://test", "test")); + + // Add the deployable composite to the domain + domain.getDomainComposite().getIncludes().add(myComposite); + + + domain.buildComposite(myComposite); + + // Start the composite + domain.getCompositeActivator().activate(myComposite); + domain.getCompositeActivator().start(myComposite); + + // At this point the domain contains my contribution, my composite and + // it's started, my application code can start using it + + // Get the TestServiceComponent service + TestService service = domain.getService(TestService.class, "TestServiceComponent"); + + // Invoke the service + String result = service.ping("Bob"); + assertEquals("Hello Bob", result); + + // Stop my composite + domain.getCompositeActivator().stop(myComposite); + domain.getCompositeActivator().deactivate(myComposite); + + // Remove my composite + domain.getDomainComposite().getIncludes().remove(myComposite); + + // Remove my contribution + contributionService.remove("http://test/contribution"); + + // Stop the domain + domain.stop(); + } + + public void testComponentManager() throws Exception { + // Start the domain + domain.start(); + + // Determine my class loader and my test SCA contribution location + ClassLoader myClassLoader = getClass().getClassLoader(); + String url = myClassLoader.getResource("test.txt").toString(); + url = url.substring(0, url.length()-8); + + // Contribute the SCA contribution + TestModelResolver myResolver = new TestModelResolver(myClassLoader); + ContributionService contributionService = domain.getContributionService(); + Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false); + assertNotNull(contribution); + + // Decide which SCA composite I want to deploy + Composite myComposite = myResolver.getComposite(new QName("http://test", "test")); + + // Add the deployable composite to the domain + domain.getDomainComposite().getIncludes().add(myComposite); + + domain.buildComposite(myComposite); + + // Start the composite + domain.getCompositeActivator().activate(myComposite); + domain.getCompositeActivator().start(myComposite); + + // At this point the domain contains my contribution, my composite and + // it's started, my application code can start using it + + ComponentManager componentManager = domain.getComponentManager(); + assertEquals(1, componentManager.getComponentNames().size()); + assertEquals("TestServiceComponent", componentManager.getComponentNames().iterator().next()); + + Component component = componentManager.getComponent("TestServiceComponent"); + assertNotNull(component); + assertEquals("TestServiceComponent", component.getName()); + + MyComponentListener cl = new MyComponentListener(); + componentManager.addComponentListener(cl); + + assertTrue(componentManager.isComponentStarted("TestServiceComponent")); + + assertFalse(cl.stopCalled); + componentManager.stopComponent("TestServiceComponent"); + assertTrue(cl.stopCalled); + assertFalse(componentManager.isComponentStarted("TestServiceComponent")); + + assertFalse(cl.startCalled); + componentManager.startComponent("TestServiceComponent"); + assertTrue(cl.startCalled); + assertTrue(componentManager.isComponentStarted("TestServiceComponent")); + + // Stop my composite + domain.getCompositeActivator().stop(myComposite); + domain.getCompositeActivator().deactivate(myComposite); + + // Remove my composite + domain.getDomainComposite().getIncludes().remove(myComposite); + + // Remove my contribution + contributionService.remove("http://test/contribution"); + + // Stop the domain + domain.stop(); + } + + class MyComponentListener implements ComponentListener { + boolean startCalled; + boolean stopCalled; + + public void componentStarted(String componentName) { + startCalled = true; + } + + public void componentStopped(String componentName) { + stopCalled = true; + } + + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java new file mode 100644 index 0000000000..1cfe5ed5d8 --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java @@ -0,0 +1,104 @@ +/* + * 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.sca.host.embedded.impl; + +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * A test model resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class TestModelResolver implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + private WeakReference classLoader; + + private Map composites = new HashMap(); + + public TestModelResolver(ClassLoader classLoader) { + this.classLoader = new WeakReference(classLoader); + } + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + if (resolved != null) { + + // Return the resolved object + return modelClass.cast(resolved); + + } else if (unresolved instanceof ClassReference) { + + // Load a class on demand + ClassReference classReference = (ClassReference)unresolved; + Class clazz; + try { + clazz = Class.forName(classReference.getClassName(), true, classLoader.get()); + } catch (ClassNotFoundException e) { + + // Return the unresolved object + return unresolved; + } + + // Store a new ClassReference wrapping the loaded class + resolved = new ClassReference(clazz); + map.put(resolved, resolved); + + // Return the resolved ClassReference + return modelClass.cast(resolved); + + } else { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + if (resolved instanceof Composite) { + Composite composite = (Composite)resolved; + composites.put(composite.getName(), composite); + } + } + + public Object removeModel(Object resolved) { + if (resolved instanceof Composite) { + Composite composite = (Composite)resolved; + composites.remove(composite.getName()); + } + return map.remove(resolved); + } + + public Composite getComposite(QName qname) { + return composites.get(qname); + } + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java new file mode 100644 index 0000000000..86e0cb6a8a --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java @@ -0,0 +1,47 @@ +/* + * 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.sca.host.embedded.test.extension; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.host.embedded.test.extension.impl.TestImplementationImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + + +/** + * Default factory for the test implementation model. + * + * @version $Rev$ $Date$ + */ +public class DefaultTestImplementationFactory implements TestImplementationFactory { + + private AssemblyFactory assemblyFactory; + private JavaInterfaceFactory javaFactory; + + public DefaultTestImplementationFactory(AssemblyFactory assemblyFactory, + JavaInterfaceFactory javaFactory) { + this.assemblyFactory = assemblyFactory; + this.javaFactory = javaFactory; + } + + public TestImplementation createTestImplementation() { + return new TestImplementationImpl(assemblyFactory, javaFactory); + } + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java new file mode 100644 index 0000000000..d9f1228307 --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java @@ -0,0 +1,44 @@ +/* + * 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.sca.host.embedded.test.extension; + +import org.apache.tuscany.sca.assembly.Implementation; + +/** + * The model representing a test implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public interface TestImplementation extends Implementation { + + /** + * Returns the greeting string that can be configured on test implementations. + * + * @return the greeting string that can be configured on test implementations + */ + String getGreeting(); + + /** + * Sets the greeting string that can be configured on test implementations. + * + * @param greeting the greeting string that can be configured on test implementations + */ + void setGreeting(String greeting); + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.java new file mode 100644 index 0000000000..9200d850bb --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.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.sca.host.embedded.test.extension; + + +/** + * A factory for the test implementation model. + * + * @version $Rev$ $Date$ + */ +public interface TestImplementationFactory { + + /** + * Creates a new test implementation. + * + * @return + */ + TestImplementation createTestImplementation(); + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java new file mode 100644 index 0000000000..4adec91151 --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java @@ -0,0 +1,30 @@ +/* + * 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.sca.host.embedded.test.extension; + +/** + * Service interface for test component implementations. + * + * @version $Rev$ $Date$ + */ +public interface TestService { + + String ping(String name); + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java new file mode 100644 index 0000000000..083b01167f --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java @@ -0,0 +1,117 @@ +/* + * 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.sca.host.embedded.test.extension.impl; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.host.embedded.test.extension.TestService; +import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementation; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + + +/** + * The model representing a test implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public class TestImplementationImpl implements TestImplementation { + + private Service testService; + private String greeting; + + /** + * Constructs a new test implementation. + */ + public TestImplementationImpl(AssemblyFactory assemblyFactory, + JavaInterfaceFactory javaFactory) { + + // Test implementations always provide a single service exposing + // the TestService interface, and have no references and properties + testService = assemblyFactory.createService(); + testService.setName("Test"); + JavaInterface javaInterface; + try { + javaInterface = javaFactory.createJavaInterface(TestService.class); + } catch (InvalidInterfaceException e) { + throw new IllegalArgumentException(e); + } + JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(javaInterface); + testService.setInterfaceContract(interfaceContract); + } + + public String getGreeting() { + return greeting; + } + + public void setGreeting(String greeting) { + this.greeting = greeting; + } + + public ConstrainingType getConstrainingType() { + // The test implementation does not support constrainingTypes + return null; + } + + public List getProperties() { + // The test implementation does not support properties + return Collections.emptyList(); + } + + public List getServices() { + // The test implementation provides a single fixed Test service + return Collections.singletonList(testService); + } + + public List getReferences() { + // The test implementation does not support properties + return Collections.emptyList(); + } + + public String getURI() { + // The test implementation does not have a URI + return null; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + // The test implementation does not support constrainingTypes + } + + public void setURI(String uri) { + // The test implementation does not have a URI + } + + public boolean isUnresolved() { + // The test implementation is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The test implementation is always resolved + } +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java new file mode 100644 index 0000000000..73feffad50 --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java @@ -0,0 +1,96 @@ +/* + * 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.sca.host.embedded.test.extension.impl; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementation; +import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementationFactory; + + + +/** + * Implements a StAX artifact processor for test implementations. + * + * @version $Rev$ $Date$ + */ +public class TestImplementationProcessor implements StAXArtifactProcessor { + private static final QName IMPLEMENTATION_TEST = new QName("http://test/extension", "implementation.test"); + + private TestImplementationFactory testFactory; + + public TestImplementationProcessor(TestImplementationFactory testFactory) { + this.testFactory = testFactory; + } + + public QName getArtifactType() { + // Returns the QName of the XML element processed by this processor + return IMPLEMENTATION_TEST; + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return TestImplementation.class; + } + + public TestImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + // Read an element + + // Read the message attribute. + String message = reader.getAttributeValue(null, "greeting"); + + // Create and initialize the test implementation model + TestImplementation implementation = testFactory.createTestImplementation(); + implementation.setGreeting(message); + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && IMPLEMENTATION_TEST.equals(reader.getName())) { + break; + } + } + + return implementation; + } + + public void resolve(TestImplementation impl, ModelResolver resolver) throws ContributionResolveException { + } + + public void write(TestImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + writer.writeStartElement(IMPLEMENTATION_TEST.getNamespaceURI(), IMPLEMENTATION_TEST.getLocalPart()); + + if (implementation.getGreeting() != null) { + writer.writeAttribute("greeting", implementation.getGreeting()); + } + + writer.writeEndElement(); + } +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java new file mode 100644 index 0000000000..f6f077e99b --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java @@ -0,0 +1,65 @@ +/* + * 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.sca.host.embedded.test.extension.module; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.host.embedded.test.extension.DefaultTestImplementationFactory; +import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementationFactory; +import org.apache.tuscany.sca.host.embedded.test.extension.impl.TestImplementationProcessor; +import org.apache.tuscany.sca.host.embedded.test.extension.provider.TestImplementationProviderFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; + + + +/** + * Implements a module activator for the test implementation extension module. + * + * @version $Rev$ $Date$ + */ +public class TestModuleActivator implements ModuleActivator { + + public void start(ExtensionPointRegistry registry) { + + // Create the test implementation factory + ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + TestImplementationFactory testFactory = new DefaultTestImplementationFactory(assemblyFactory, javaFactory); + modelFactories.addFactory(testFactory); + + // Add the test implementation extension to the StAXArtifactProcessor + // extension point + StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + TestImplementationProcessor implementationArtifactProcessor = new TestImplementationProcessor(testFactory); + processors.addArtifactProcessor(implementationArtifactProcessor); + + // Add the test provider factory to the ProviderFactory extension point + ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + providerFactories.addProviderFactory(new TestImplementationProviderFactory()); + } + + public void stop(ExtensionPointRegistry registry) { + } +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.java new file mode 100644 index 0000000000..1d27e08fee --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.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.sca.host.embedded.test.extension.provider; + +import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementation; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + + +/** + * Implementation provider for test implementations. + * + * @version $Rev$ $Date$ + */ +public class TestImplementationProvider implements ImplementationProvider { + + private RuntimeComponent component; + private TestImplementation implementation; + + /** + * Constructs a new test implementation provider. + */ + public TestImplementationProvider(RuntimeComponent component, TestImplementation implementation) { + this.component = component; + this.implementation = implementation; + } + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + TestInvoker invoker = new TestInvoker(operation, implementation.getGreeting()); + return invoker; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + System.out.println("Starting " + component.getName()); + } + + public void stop() { + System.out.println("Stopping " + component.getName()); + } + +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java new file mode 100644 index 0000000000..15d3618fdd --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java @@ -0,0 +1,47 @@ +/* + * 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.sca.host.embedded.test.extension.provider; + +import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementation; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + + +/** + * The model representing a test implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public class TestImplementationProviderFactory implements ImplementationProviderFactory { + + /** + * Constructs a new test implementation provider factory. + */ + public TestImplementationProviderFactory() { + } + + public ImplementationProvider createImplementationProvider(RuntimeComponent component, TestImplementation implementation) { + return new TestImplementationProvider(component, implementation); + } + + public Class getModelType() { + return TestImplementation.class; + } +} diff --git a/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.java b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.java new file mode 100644 index 0000000000..d49179dec0 --- /dev/null +++ b/branches/sca-java-1.3/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.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.sca.host.embedded.test.extension.provider; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + + +/** + * Implements an invoker for test component implementations. + * + * The target invoker is responsible for handling operation invocations. + * + * @version $Rev$ $Date$ + */ +public class TestInvoker implements Invoker { + private Operation operation; + private String greeting; + + public TestInvoker(Operation operation, String greeting) { + this.operation = operation; + this.greeting = greeting; + } + + public Message invoke(Message msg) { + Object[] args = msg.getBody(); + if (operation.getName().equals("ping")) { + msg.setBody(greeting + " " + args[0]); + } else { + msg.setFaultBody(new Exception("Operation " + operation.getName() + " is not supported")); + } + return msg; + } +} -- cgit v1.2.3