diff options
Diffstat (limited to 'tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system')
12 files changed, 0 insertions, 1445 deletions
diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/MonitorInjectionTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/MonitorInjectionTestCase.java deleted file mode 100644 index fe6bff635a..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/MonitorInjectionTestCase.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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.core.system.builder; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.common.monitor.MonitorFactory; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.system.annotation.Monitor; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.Scope; - -/** - * @version $Rev$ $Date$ - */ -public class MonitorInjectionTestCase extends TestCase { - private SystemContextFactoryBuilder builder; - private Component component; - - public static interface TestService { - } - - public static class TestComponent implements TestService { - @Monitor - protected Monitor1 monitor1; - Monitor2 monitor2; - - @Monitor - public void setMonitor2(Monitor2 monitor2) { - this.monitor2 = monitor2; - } - } - - public static interface Monitor1 { - } - - public static interface Monitor2 { - } - - public void testMonitorInjection() { - builder.build(component); - ContextFactory<?> contextFactory = (ContextFactory<?>) component.getContextFactory(); - Assert.assertNotNull(contextFactory); - contextFactory.prepare(createContext()); - Context ctx = contextFactory.createContext(); - - ctx.start(); - TestComponent instance = (TestComponent) ctx.getInstance(null); - assertSame(MONITOR1, instance.monitor1); - assertSame(MONITOR2, instance.monitor2); - } - - protected void setUp() throws Exception { - super.setUp(); - SystemAssemblyFactory factory = new SystemAssemblyFactoryImpl(); - MockMonitorFactory monitorFactory = new MockMonitorFactory(); - builder = new SystemContextFactoryBuilder(monitorFactory); - component = factory.createSystemComponent("test", TestService.class, TestComponent.class, Scope.MODULE); - component.getImplementation().setComponentType(MockFactory.getIntrospector().introspect(TestComponent.class)); - } - - private static final Monitor1 MONITOR1 = new Monitor1() { - }; - private static final Monitor2 MONITOR2 = new Monitor2() { - }; - - public static class MockMonitorFactory implements MonitorFactory { - public <T> T getMonitor(Class<T> monitorInterface) { - if (Monitor1.class.equals(monitorInterface)) { - return monitorInterface.cast(MONITOR1); - } else if (Monitor2.class.equals(monitorInterface)) { - return monitorInterface.cast(MONITOR2); - } else { - throw new AssertionError(); - } - } - } - - private static CompositeContext createContext() { - return new CompositeContextImpl("test.parent", null, new DefaultScopeStrategy(), new EventContextImpl(), new MockConfigContext(null)); - } -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java deleted file mode 100644 index 3398a010e9..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.core.system.builder; - -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.AutowireContext; -import org.apache.tuscany.core.context.ConfigurationContext; -import org.apache.tuscany.core.system.annotation.Autowire; -import org.apache.tuscany.core.system.annotation.ParentContext; -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Scope; - -/** - * A system component used for unit testing - * - * @version $Rev$ $Date$ - */ -@Scope("MODULE") -public class SystemComponentImpl { - - @Autowire - protected ConfigurationContext ctx; - - @ParentContext - protected CompositeContext parent; - - @Autowire - protected AutowireContext autowireCtx; - - private ConfigurationContext ctxSetter; - - private CompositeContext parentSetter; - - private AutowireContext autowireCtxSetter; - - public ConfigurationContext getConfigContext() { - return ctx; - } - - public CompositeContext getParentContext() { - return parent; - } - - public AutowireContext getAutowireContext() { - return autowireCtx; - } - - @Autowire - public void setConfigContext(ConfigurationContext configCtx) { - ctxSetter = configCtx; - } - - public ConfigurationContext getConfigContextSetter() { - return ctxSetter; - } - - @ParentContext - public void setParentContex(CompositeContext ctx) { - parentSetter = ctx; - } - - public CompositeContext getParentContextSetter() { - return parentSetter; - } - - @Autowire - public void setAutowireContext(AutowireContext ctx) { - autowireCtxSetter = ctx; - } - - public AutowireContext getAutowireContextSetter() { - return autowireCtx; - } - - private boolean inited; - - @Init - public void init(){ - inited=true; - } - - public boolean initialized(){ - return (inited); - } - - private boolean destroyed; - - @Destroy - public void destroy(){ - destroyed=true; - } - - public boolean destroyed(){ - return (destroyed); - } - - @Property - protected int testInt; - - public int getTestInt(){ - return testInt; - } - - @Property - protected double testDouble; - - public double getTestDouble(){ - return testDouble; - } - - @Property - protected float testFloat; - - public float getTestFloat(){ - return testFloat; - } - - @Property - protected short testShort; - - public short getTestShort(){ - return testShort; - } - - @Property - protected boolean testBoolean; - - public boolean getTestBoolean(){ - return testBoolean; - } - - @Property - protected byte testByte; - - public byte getTestByte(){ - return testByte; - } - - @Property - protected char testChar; - - public char getTestChar(){ - return testChar; - } - - @Property - protected String testString; - - public String getTestString(){ - return testString; - } - - -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilderTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilderTestCase.java deleted file mode 100644 index f7543911a6..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilderTestCase.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.core.system.builder; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.SystemImplementation; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.ConfiguredProperty; -import org.apache.tuscany.model.assembly.Property; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * Tests to system components are built properly - * - * @version $Rev$ $Date$ - */ -public class SystemContextFactoryBuilderTestCase extends TestCase { - - private SystemAssemblyFactory factory = new SystemAssemblyFactoryImpl(); - - public void testComponentContextBuilder() throws Exception { - SystemContextFactoryBuilder builder = new SystemContextFactoryBuilder(null); - Component component = factory.createSystemComponent("test", null, SystemComponentImpl.class, Scope.AGGREGATE); - component.getImplementation().setComponentType(MockFactory.getIntrospector().introspect(SystemComponentImpl.class)); - ConfiguredProperty cProp = factory.createConfiguredProperty(); - Property prop = factory.createProperty(); - prop.setName("testInt"); - cProp.setValue(1); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testString"); - cProp.setValue("test"); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testDouble"); - cProp.setValue(1d); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testFloat"); - cProp.setValue(1f); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testShort"); - cProp.setValue((short) 1); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testByte"); - cProp.setValue((byte) 1); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testBoolean"); - cProp.setValue(Boolean.TRUE); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - cProp = factory.createConfiguredProperty(); - prop = factory.createProperty(); - prop.setName("testChar"); - cProp.setValue('1'); - cProp.setProperty(prop); - component.getConfiguredProperties().add(cProp); - - builder.build(component); - ContextFactory<AtomicContext> contextFactory = (ContextFactory<AtomicContext>) component.getContextFactory(); - Assert.assertNotNull(contextFactory); - contextFactory.prepare(createContext()); - AtomicContext ctx = contextFactory.createContext(); - - ctx.start(); - SystemComponentImpl instance = (SystemComponentImpl) ctx.getInstance(null); - Assert.assertNotNull(instance.getConfigContext()); - Assert.assertNotNull(instance.getParentContext()); - Assert.assertNotNull(instance.getAutowireContext()); - Assert.assertNotNull(instance.getConfigContextSetter()); - Assert.assertNotNull(instance.getParentContextSetter()); - Assert.assertNotNull(instance.getAutowireContextSetter()); - Assert.assertEquals(1, instance.getTestInt()); - Assert.assertEquals(1d, instance.getTestDouble()); - Assert.assertEquals(1f, instance.getTestFloat()); - Assert.assertEquals((short) 1, instance.getTestShort()); - Assert.assertTrue(instance.getTestBoolean()); - Assert.assertEquals('1', instance.getTestChar()); - Assert.assertEquals((byte) 1, instance.getTestByte()); - Assert.assertEquals("test", instance.getTestString()); - - Assert.assertTrue(instance.initialized()); - ctx.destroy(); - ctx.stop(); - Assert.assertTrue(instance.destroyed()); - } - - - public void testDefaultScopeIsModuleScope() throws Exception { - SystemContextFactoryBuilder builder = new SystemContextFactoryBuilder(null); - Component component = createSystemComponentWithNoScope("test", null, SystemComponentImpl.class); - builder.build(component); - ContextFactory<AtomicContext> contextFactory = (ContextFactory<AtomicContext>) component.getContextFactory(); - Assert.assertEquals(Scope.MODULE, contextFactory.getScope()); - } - - - - - private static CompositeContext createContext() { - return new CompositeContextImpl("test.parent", null, new DefaultScopeStrategy(), new EventContextImpl(), - new MockConfigContext(null)); - } - - private <T> Component createSystemComponentWithNoScope(String name, Class<T> service, Class<? extends T> impl) { - JavaServiceContract jsc = factory.createJavaServiceContract(); - jsc.setInterface(service); - Service s = factory.createService(); - s.setServiceContract(jsc); - - ComponentType componentType = factory.createComponentType(); - componentType.getServices().add(s); - - SystemImplementation sysImpl = factory.createSystemImplementation(); - sysImpl.setImplementationClass(impl); - sysImpl.setComponentType(componentType); - - Component sc = factory.createSimpleComponent(); - sc.setName(name); - sc.setImplementation(sysImpl); - return sc; - } - - -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java deleted file mode 100644 index 3d63664848..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.core.system.builder.impl; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.builder.impl.AssemblyVisitorImpl; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.SystemBinding; -import org.apache.tuscany.core.system.assembly.SystemImplementation; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.AssemblyObject; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.ConfiguredPort; -import org.apache.tuscany.model.assembly.ConfiguredReference; -import org.apache.tuscany.model.assembly.ConfiguredService; -import org.apache.tuscany.model.assembly.ContextFactoryHolder; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.Reference; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * Tests decorating a logical configuration model - * - * @version $Rev$ $Date$ - */ -public class AssemblyVisitorTestCase extends TestCase { - - private static final Object MARKER = new Object(); - - private SystemAssemblyFactory factory = new SystemAssemblyFactoryImpl(); - private AssemblyContext assemblyContext = new AssemblyContextImpl(factory, null, null); - - public void testModelVisit() throws Exception { - ComponentType componentType; - Service service; - SystemImplementation impl; - Component component; - - Module module = factory.createModule(); - - // create target component - componentType = factory.createComponentType(); - service = factory.createService(); - service.setName("target"); - componentType.getServices().add(service); - impl = factory.createSystemImplementation(); - impl.setComponentType(componentType); - component = factory.createSimpleComponent(); - component.setName("target"); - component.setImplementation(impl); - component.initialize(assemblyContext); - module.getComponents().add(component); - - // create source component - componentType = factory.createComponentType(); - Reference ref = factory.createReference(); - ref.setName("ref"); - componentType.getReferences().add(ref); - impl = factory.createSystemImplementation(); - impl.setComponentType(componentType); - component = factory.createSimpleComponent(); - component.setName("source"); - component.setImplementation(impl); - ConfiguredReference cRef = factory.createConfiguredReference("ref", "target"); - component.getConfiguredReferences().add(cRef); - component.initialize(assemblyContext); - module.getComponents().add(component); - - EntryPoint ep = factory.createEntryPoint(); - JavaServiceContract contract = factory.createJavaServiceContract(); - contract.setInterface(ModuleScopeSystemComponent.class); - service = factory.createService(); - service.setServiceContract(contract); - ConfiguredService cService = factory.createConfiguredService(); - cService.setPort(service); - cService.initialize(assemblyContext); - ep.setConfiguredService(cService); - SystemBinding binding = factory.createSystemBinding(); - ep.getBindings().add(binding); - ConfiguredReference cEpRef = factory.createConfiguredReference(); - Reference epRef = factory.createReference(); - cEpRef.setPort(epRef); - ep.setConfiguredReference(cEpRef); - ep.initialize(assemblyContext); - module.getEntryPoints().add(ep); - - List<ContextFactoryBuilder> builders = new ArrayList<ContextFactoryBuilder>(); - builders.add(new TestBuilder()); - AssemblyVisitorImpl visitor = new AssemblyVisitorImpl(builders); - module.initialize(assemblyContext); - visitor.start(module); - - Assert.assertSame(MARKER, component.getContextFactory()); - Assert.assertSame(MARKER, cRef.getProxyFactory()); - Assert.assertSame(MARKER, ep.getContextFactory()); - Assert.assertSame(MARKER, cEpRef.getProxyFactory()); - - } - - private static class TestBuilder implements ContextFactoryBuilder { - public void build(AssemblyObject model) throws BuilderException { - if (model instanceof ConfiguredPort) { - ((ConfiguredPort) model).setProxyFactory(MARKER); - } - if (model instanceof ContextFactoryHolder) { - ((ContextFactoryHolder) model).setContextFactory(MARKER); - } - } - - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/AutowireTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/AutowireTestCase.java deleted file mode 100644 index 6316fe3a67..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/AutowireTestCase.java +++ /dev/null @@ -1,310 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.core.system.context; - -import junit.framework.TestCase; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.SystemCompositeContext; -import org.apache.tuscany.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.AutowireSourceImpl; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.mock.component.TargetImpl; -import org.apache.tuscany.core.runtime.RuntimeContext; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Module; -import org.apache.tuscany.model.assembly.ModuleComponent; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.Service; -import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; - -/** - * Tests autowiring for serveral scenarios according to the following runtime scheme: - * - * <code> - * tuscany.runtime - * | - * + tuscany.system - * | | - * | + system1 - * | | | - * | | + system1a - * | | - * | + system2 - * | - * + tuscany.root - * | - * + app1 - * | - * + app1a - * | - * + app1b - * </code> - * - * @version $Rev$ $Date$ - */ -public class AutowireTestCase extends TestCase { - - private static SystemAssemblyFactory systemFactory = new SystemAssemblyFactoryImpl(); - - /** - * Covers the case where a component in app1a requests autowire, which is resolved by the runtime to a service - * exposed on an entry point in tuscany.system. The entry point is wired to an entry point on system1, which itself - * is wired to a component in system1 - */ - public void testScenario1() throws Exception { - RuntimeContext runtime = createScenario1Runtime(); - CompositeContext root = runtime.getRootContext(); - SystemCompositeContext system = runtime.getSystemContext(); - CompositeContext system1 = (CompositeContext) system.getContext("system1"); - system1.publish(new ModuleStart(this)); - Target target = (Target) system.getContext("target.system.ep").getInstance(null); - assertNotNull(target); - CompositeContext app1 = (CompositeContext) root.getContext("app1"); - app1.publish(new ModuleStart(this)); - CompositeContext app1a = (CompositeContext) app1.getContext("app1a"); - app1a.publish(new ModuleStart(this)); - app1a.publish(new ModuleStop(this)); - app1.publish(new ModuleStop(this)); - Source source = (Source) app1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - /** - * Covers the case where a component in app1a requests autowire, which is resolved to service exposed as an entry - * point on app1b. The entry point is wired to a component in app1b. - */ - public void testScenario2() throws Exception { - RuntimeContext runtime = createScenario2Runtime(); - CompositeContext root = runtime.getRootContext(); - CompositeContext app1 = (CompositeContext) root.getContext("app1"); - app1.publish(new ModuleStart(this)); - CompositeContext app1b = (CompositeContext) app1.getContext("app1b"); - app1b.publish(new ModuleStart(this)); - CompositeContext app1a = (CompositeContext) app1.getContext("app1a"); - app1a.publish(new ModuleStart(this)); - Target target = (Target) app1b.getContext("target.ep").getInstance(null); - assertNotNull(target); - Source source = (Source) app1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - /** - * Covers the case where a component in system1a requests autowire, which is resolved to an entry point exposed on - * system2. The entry point is wired to a component in system2. - */ - public void testScenario3() throws Exception { - RuntimeContext runtime = createScenario3Runtime(); - SystemCompositeContext system = runtime.getSystemContext(); - - CompositeContext system2 = (CompositeContext) system.getContext("system2"); - system2.publish(new ModuleStart(this)); - Target target = (Target) system2.getContext("target.ep").getInstance(null); - assertNotNull(target); - - CompositeContext system1 = (CompositeContext) system.getContext("system1"); - system1.publish(new ModuleStart(this)); - CompositeContext system1a = (CompositeContext) system1.getContext("system1a"); - system1a.publish(new ModuleStart(this)); - - Source source = (Source) system1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - /** - * Covers the case where a component in system1a requests autowire, which is resolved to component in its parent, - * system1. - */ - public void testScenario4() throws Exception { - RuntimeContext runtime = createScenario4Runtime(); - SystemCompositeContext system = runtime.getSystemContext(); - CompositeContext system1 = (CompositeContext) system.getContext("system1"); - system1.publish(new ModuleStart(this)); - Target target = (Target) system1.getContext("target").getInstance(null); - assertNotNull(target); - CompositeContext system1a = (CompositeContext) system1.getContext("system1a"); - system1a.publish(new ModuleStart(this)); - - Source source = (Source) system1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - /** - * Covers the case where a component in system1a requests autowire, which is resolved to component in the parent of - * its parent (grandparent), system. - */ - public void testScenario5() throws Exception { - RuntimeContext runtime = createScenario5Runtime(); - SystemCompositeContext system = runtime.getSystemContext(); - CompositeContext system1 = (CompositeContext) system.getContext("system1"); - system1.publish(new ModuleStart(this)); - Target target = (Target) system.getContext("target").getInstance(null); - assertNotNull(target); - CompositeContext system1a = (CompositeContext) system1.getContext("system1a"); - system1a.publish(new ModuleStart(this)); - - Source source = (Source) system1a.getContext("source").getInstance(null); - assertEquals(target, source.getTarget()); - source.getTarget().getString(); - runtime.stop(); - } - - private RuntimeContext createScenario1Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - SystemCompositeContext system = runtime.getSystemContext(); - ModuleComponent system1Component = MockFactory.createSystemCompositeComponent("system1"); - ModuleComponent system1aComponent = MockFactory.createSystemCompositeComponent("system1a"); - system1Component.getImplementation().getComponents().add(system1aComponent); - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - system1Component.getImplementation().getComponents().add(target); - - EntryPoint ep = MockFactory.createEPSystemBinding("target.ep", Target.class, "target", target); - system1Component.getImplementation().getEntryPoints().add(ep); - system.registerModelObject(system1Component); - EntryPoint systemEp = MockFactory.createEPSystemBinding("target.system.ep", Target.class, "ref"); - - systemEp.getBindings().add(systemFactory.createSystemBinding()); - Service service = systemFactory.createService(); - service.setName("system1/target.ep"); - (systemEp.getConfiguredReference().getTargetConfiguredServices().get(0)).setPort(service); - - system.registerModelObject(systemEp); - ModuleComponent app1Component = createAppModuleComponent("app1"); - ModuleComponent app1aComponent = createAppModuleComponent("app1a"); - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - app1aComponent.getImplementation().getComponents().add(source); - app1Component.getImplementation().getComponents().add(app1aComponent); - CompositeContext root = runtime.getRootContext(); - root.registerModelObject(app1Component); - system.publish(new ModuleStart(this)); - return runtime; - } - - private RuntimeContext createScenario2Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - - ModuleComponent app1Component = createAppModuleComponent("app1"); - ModuleComponent app1aComponent = createAppModuleComponent("app1a"); - ModuleComponent app1bComponent = createAppModuleComponent("app1b"); - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - app1aComponent.getImplementation().getComponents().add(source); - app1Component.getImplementation().getComponents().add(app1aComponent); - app1Component.getImplementation().getComponents().add(app1bComponent); - - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - app1bComponent.getImplementation().getComponents().add(target); - - EntryPoint ep = MockFactory.createEPSystemBinding("target.ep", Target.class, "target", target); - ep.getBindings().add(systemFactory.createSystemBinding()); - Service service = systemFactory.createService(); - service.setName("target.ep"); - ep.getConfiguredReference().getTargetConfiguredServices().get(0).setPort(service); - app1bComponent.getImplementation().getEntryPoints().add(ep); - - CompositeContext root = runtime.getRootContext(); - root.registerModelObject(app1Component); - return runtime; - } - - private RuntimeContext createScenario3Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - SystemCompositeContext system = runtime.getSystemContext(); - ModuleComponent system1Component = MockFactory.createSystemCompositeComponent("system1"); - ModuleComponent system2Component = MockFactory.createSystemCompositeComponent("system2"); - ModuleComponent system1aComponent = MockFactory.createSystemCompositeComponent("system1a"); - system1Component.getImplementation().getComponents().add(system1aComponent); - - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - system2Component.getImplementation().getComponents().add(target); - EntryPoint ep = MockFactory.createEPSystemBinding("target.ep", Target.class, "target", target); - system2Component.getImplementation().getEntryPoints().add(ep); - system.registerModelObject(system2Component); - - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - system1aComponent.getImplementation().getComponents().add(source); - system.registerModelObject(system1Component); - system.publish(new ModuleStart(this)); - return runtime; - } - - private RuntimeContext createScenario4Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - SystemCompositeContext system = runtime.getSystemContext(); - ModuleComponent system1Component = MockFactory.createSystemCompositeComponent("system1"); - ModuleComponent system1aComponent = MockFactory.createSystemCompositeComponent("system1a"); - system1Component.getImplementation().getComponents().add(system1aComponent); - - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - system1Component.getImplementation().getComponents().add(target); - - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - system1aComponent.getImplementation().getComponents().add(source); - system.registerModelObject(system1Component); - system.publish(new ModuleStart(this)); - return runtime; - } - - private RuntimeContext createScenario5Runtime() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - runtime.start(); - SystemCompositeContext system = runtime.getSystemContext(); - ModuleComponent system1Component = MockFactory.createSystemCompositeComponent("system1"); - ModuleComponent system1aComponent = MockFactory.createSystemCompositeComponent("system1a"); - system1Component.getImplementation().getComponents().add(system1aComponent); - - Component target = MockFactory.createSystemComponent("target", Target.class, TargetImpl.class, Scope.MODULE); - system.registerModelObject(target); - - Component source = MockFactory.createSystemComponent("source", Source.class, AutowireSourceImpl.class, Scope.MODULE); - system1aComponent.getImplementation().getComponents().add(source); - system.registerModelObject(system1Component); - system.publish(new ModuleStart(this)); - return runtime; - } - - private ModuleComponent createAppModuleComponent(String name) throws ConfigurationLoadException { - AssemblyContext assemblyContext = new AssemblyContextImpl(systemFactory, null, null); - ModuleComponent mc = systemFactory.createModuleComponent(); - mc.setName(name); - Module module = systemFactory.createModule(); - module.setImplementationClass(CompositeContextImpl.class); - module.setComponentType(MockFactory.getComponentType()); - module.setName(name); - module.initialize(assemblyContext); - mc.setImplementation(module); - return mc; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/CompositeNestingTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/CompositeNestingTestCase.java deleted file mode 100644 index 27ffc5794e..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/CompositeNestingTestCase.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.core.system.context; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.runtime.RuntimeContext; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.ModuleComponent; -import org.apache.tuscany.model.assembly.Scope; - -/** - * Tests registering arbirarily deep child composite contexts - * - * @version $Rev$ $Date$ - */ -public class CompositeNestingTestCase extends TestCase { - - /** - * Tests registration of a 3-level deep hierarchy under the top-level system composite context - */ - public void testSystemContext() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - ModuleComponent child1 = createHierarchy(); - runtime.getSystemContext().registerModelObject(child1); - CompositeContext child1Ctx = (CompositeContext) runtime.getSystemContext().getContext("child1"); - Assert.assertNotNull(child1Ctx); - child1Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child1Ctx); - CompositeContext child2Ctx = (CompositeContext) child1Ctx.getContext("child2"); - Assert.assertNotNull(child2Ctx); - child2Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child2Ctx); - CompositeContext child3Ctx = (CompositeContext) child2Ctx.getContext("child3"); - Assert.assertNotNull(child3Ctx); - child3Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child3Ctx); - - Assert.assertNull(child1Ctx.getContext("child3")); // sanity check - } - - /** - * Tests registration of a 3-level deep hierarchy under the root application composite context - */ - public void testRootContext() throws Exception { - RuntimeContext runtime = MockFactory.createCoreRuntime(); - ModuleComponent child1 = createHierarchy(); - runtime.getRootContext().registerModelObject(child1); - CompositeContext child1Ctx = (CompositeContext) runtime.getRootContext().getContext("child1"); - Assert.assertNotNull(child1Ctx); - child1Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child1Ctx); - CompositeContext child2Ctx = (CompositeContext) child1Ctx.getContext("child2"); - Assert.assertNotNull(child2Ctx); - child2Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child2Ctx); - CompositeContext child3Ctx = (CompositeContext) child2Ctx.getContext("child3"); - Assert.assertNotNull(child3Ctx); - child3Ctx.publish(new ModuleStart(this)); - analyzeLeafComponents(child3Ctx); - - Assert.assertNull(child1Ctx.getContext("child3")); // sanity check - child1Ctx.publish(new ModuleStop(this)); - } - - private ModuleComponent createHierarchy() throws ConfigurationLoadException { - ModuleComponent child3 = MockFactory.createSystemModuleComponentWithWiredComponents("child3", Scope.MODULE, Scope.MODULE); - ModuleComponent child2 = MockFactory.createSystemModuleComponentWithWiredComponents("child2", Scope.MODULE, Scope.MODULE); - child2.getImplementation().getComponents().add(child3); - ModuleComponent child1 = MockFactory.createSystemModuleComponentWithWiredComponents("child1", Scope.MODULE, Scope.MODULE); - child1.getImplementation().getComponents().add(child2); - return child1; - } - - private void analyzeLeafComponents(CompositeContext ctx) throws Exception { - Source source = (Source) ctx.getContext("source").getInstance(null); - Assert.assertNotNull(source); - Target target = source.getTarget(); - Assert.assertNotNull(target); - } -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/IntraCompositeWireTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/IntraCompositeWireTestCase.java deleted file mode 100644 index a956263cc8..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/IntraCompositeWireTestCase.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.core.system.context; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.context.SystemCompositeContext; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.List; - -/** - * Tests intra-composite system component wiring scenarios - * - * @version $Rev$ $Date$ - */ -public class IntraCompositeWireTestCase extends TestCase { - - public void testModuleToModuleScope() throws Exception { - SystemCompositeContext context = createContext(); - context.start(); - context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE, Scope.MODULE)); - context.publish(new ModuleStart(this)); - Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target targetRef = source.getTarget(); - Assert.assertNotNull(targetRef); - Target target = (Target) ((AtomicContext) context.getContext("target")).getTargetInstance(); - Assert.assertSame(target, targetRef); - Assert.assertSame(target, source.getTarget()); - context.publish(new ModuleStop(this)); - context.stop(); - } - - public void testStatelessToModuleScope() throws Exception { - SystemCompositeContext context = createContext(); - context.start(); - context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.INSTANCE, Scope.MODULE)); - context.publish(new ModuleStart(this)); - Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target targetRef = source.getTarget(); - Assert.assertNotNull(targetRef); - source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Target target = (Target) ((AtomicContext) context.getContext("target")).getTargetInstance(); - Assert.assertSame(target, targetRef); - Assert.assertSame(target, source.getTarget()); - context.publish(new ModuleStop(this)); - context.stop(); - } - - public void testModuleToStatelessScope() throws Exception { - SystemCompositeContext context = createContext(); - context.start(); - context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE, Scope.INSTANCE)); - context.publish(new ModuleStart(this)); - Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target targetRef = source.getTarget(); - Assert.assertNotNull(targetRef); - Target target = (Target) ((AtomicContext) context.getContext("target")).getTargetInstance(); - Assert.assertNotSame(target, targetRef); - Source source2 = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - // should be the same since the module scope component was alreadyy created and the stateless - // component will be "attached" to it - Assert.assertSame(source.getTarget(), source2.getTarget()); - context.publish(new ModuleStop(this)); - context.stop(); - } - - public void testMultiplicity() throws Exception { - SystemCompositeContext context = createContext(); - context.start(); - context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE, Scope.MODULE)); - context.publish(new ModuleStart(this)); - Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance(); - Assert.assertNotNull(source); - Target target = (Target) ((AtomicContext) context.getContext("target")).getTargetInstance(); - Assert.assertNotNull(target); - // test setter injection - List<Target> targets = source.getTargets(); - Assert.assertEquals(1,targets.size()); - assertSame(target,targets.get(0)); - - // test field injection - targets = source.getTargetsThroughField(); - Assert.assertEquals(1,targets.size()); - assertSame(target,targets.get(0)); - - // test array injection - Target[] targetArray = source.getArrayOfTargets(); - Assert.assertEquals(1,targetArray.length); - assertSame(target,targetArray[0]); - - - } - - private SystemCompositeContext createContext() { - SystemCompositeContextImpl context = new SystemCompositeContextImpl(); - context.setName("system.context"); - context.setConfigurationContext(new MockConfigContext(MockFactory.createSystemBuilders())); - return context; - } - - - -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeComponentContextTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeComponentContextTestCase.java deleted file mode 100644 index 75208f47b6..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeComponentContextTestCase.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.core.system.context; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.context.event.ModuleStop; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent; -import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.List; - -/** - * Tests the system composite context - * - * @version $Rev$ $Date$ - */ -public class SystemCompositeComponentContextTestCase extends TestCase { - private SystemAssemblyFactory factory; - private SystemCompositeContextImpl system; - - public void testChildLocate() throws Exception { - system.start(); - Component compositeComponent = MockFactory.createCompositeComponent("system.child"); - system.registerModelObject(compositeComponent); - CompositeContext childContext = (CompositeContext) system.getContext("system.child"); - Assert.assertNotNull(childContext); - - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - childContext.registerModelObject(component); - childContext.registerModelObject(ep); - childContext.publish(new ModuleStart(this)); - Assert.assertNotNull(system.getContext("system.child").getInstance(new QualifiedName("./TestService1EP"))); - childContext.publish(new ModuleStop(this)); - } - - public void testAutowireRegisterBeforeStart() throws Exception { - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - system.registerModelObject(component); - system.registerModelObject(ep); - system.start(); - system.publish(new ModuleStart(this)); - Assert.assertSame(system.getContext("TestService1EP").getInstance(null), system.resolveInstance(ModuleScopeSystemComponent.class)); - } - - public void testAutowireRegisterAfterStart() throws Exception { - Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE); - system.registerModelObject(component); - system.start(); - system.publish(new ModuleStart(this)); - EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component); - system.registerModelObject(ep); - Assert.assertSame(system.getContext("TestService1EP").getInstance(null), system.resolveInstance(ModuleScopeSystemComponent.class)); - } - - public void testAutowireModuleRegisterBeforeStart() throws Exception { - system.registerModelObject(MockFactory.createSystemModule()); - system.start(); - system.publish(new ModuleStart(this)); - Assert.assertSame(system.getContext("TestService1EP").getInstance(null), system.resolveInstance(ModuleScopeSystemComponent.class)); - } - - public void testAutowireModuleRegisterAfterStart() throws Exception { - system.start(); - system.publish(new ModuleStart(this)); - system.registerModelObject(MockFactory.createSystemModule()); - Assert.assertSame(system.getContext("TestService1EP").getInstance(null), system.resolveInstance(ModuleScopeSystemComponent.class)); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new SystemAssemblyFactoryImpl(); - List<ContextFactoryBuilder> builders = MockFactory.createSystemBuilders(); - - system = new SystemCompositeContextImpl("system", null, null, new SystemScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders)); - } - - protected void tearDown() throws Exception { - system.publish(new ModuleStop(this)); - system.stop(); - super.tearDown(); - } -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeContextRegisterTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeContextRegisterTestCase.java deleted file mode 100644 index 4397e39bec..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeContextRegisterTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.core.system.context; - -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.context.CompositeContextRegisterTestCase; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; - -import java.util.List; - -/** - * Tests registration of model objects for an system composite context - * - * @version $Rev$ $Date$ - */ -public class SystemCompositeContextRegisterTestCase extends CompositeContextRegisterTestCase { - - protected CompositeContext createContext() { - List<ContextFactoryBuilder> builders = MockFactory.createSystemBuilders(); - return new SystemCompositeContextImpl("test.context", null, null, new DefaultScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders)); - } -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeHierarchyTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeHierarchyTestCase.java deleted file mode 100644 index ba7a3ba5da..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemCompositeHierarchyTestCase.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.core.system.context; - -import junit.framework.Assert; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.context.AbstractCompositeHierarchyTests; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.DefaultScopeStrategy; -import org.apache.tuscany.core.mock.MockConfigContext; -import org.apache.tuscany.core.mock.MockFactory; - -import java.util.List; - -/** - * Performs testing of various hierarchical scenarios - * - * @version $Rev$ $Date$ - */ -public class SystemCompositeHierarchyTestCase extends AbstractCompositeHierarchyTests { - - - - protected CompositeContext createContextHierachy() throws Exception { - List<ContextFactoryBuilder> mockBuilders = MockFactory.createSystemBuilders(); - CompositeContext parent = new SystemCompositeContextImpl("test.parent", null, null, new DefaultScopeStrategy(), new EventContextImpl(), new MockConfigContext(mockBuilders)); - parent.registerModelObject(MockFactory.createCompositeComponent("test.child")); - parent.start(); - CompositeContext child = (CompositeContext) parent.getContext("test.child"); - Assert.assertNotNull(child); - return parent; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java deleted file mode 100644 index 241346e24f..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.core.system.context; - -import junit.framework.TestCase; -import org.apache.tuscany.core.config.ConfigurationException; -import org.apache.tuscany.core.context.SystemCompositeContext; -import org.apache.tuscany.core.context.DuplicateNameException; -import org.apache.tuscany.core.context.event.ModuleStart; -import org.apache.tuscany.core.runtime.RuntimeContext; -import org.apache.tuscany.core.runtime.RuntimeContextImpl; -import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; -import org.apache.tuscany.core.builder.impl.DefaultWireBuilder; -import org.apache.tuscany.core.client.BootstrapHelper; -import org.apache.tuscany.common.monitor.MonitorFactory; -import org.apache.tuscany.common.monitor.impl.NullMonitorFactory; - -/** - * @version $Rev$ $Date$ - */ -public class SystemObjectRegistrationTestCase extends TestCase { - private RuntimeContext runtime; - private SystemCompositeContext systemContext; - - public void testRegistration() throws ConfigurationException { - MockComponent instance = new MockComponent(); - systemContext.registerJavaObject("foo", MockComponent.class, instance); - assertSame(instance, systemContext.getContext("foo").getInstance(null)); - } - - public void testDuplicateRegistration() throws ConfigurationException { - MockComponent instance = new MockComponent(); - systemContext.registerJavaObject("foo", MockComponent.class, instance); - try { - systemContext.registerJavaObject("foo", MockComponent.class, instance); - fail(); - } catch (DuplicateNameException e) { - // ok - } - } - - public void testAutowireToObject() throws ConfigurationException { - MockComponent instance = new MockComponent(); - systemContext.registerJavaObject("foo", MockComponent.class, instance); - assertSame(instance, systemContext.resolveInstance(MockComponent.class)); - assertNull(systemContext.resolveExternalInstance(MockComponent.class)); - } - - protected void setUp() throws Exception { - super.setUp(); - MonitorFactory monitorFactory = new NullMonitorFactory(); - ContextFactoryBuilderRegistry builderRegistry = BootstrapHelper.bootstrapContextFactoryBuilders(monitorFactory); - DefaultWireBuilder wireBuilder = new DefaultWireBuilder(); - runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, wireBuilder); - runtime.start(); - systemContext = runtime.getSystemContext(); - systemContext.publish(new ModuleStart(this)); - } - - protected void tearDown() throws Exception { - runtime.stop(); - super.tearDown(); - } - - private static class MockComponent { - public String hello(String message) { - return message; - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/TestBuilder.java b/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/TestBuilder.java deleted file mode 100644 index c531c8f7f9..0000000000 --- a/tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/TestBuilder.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed 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.core.system.context; - -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Scope; - -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.ContextFactoryBuilder; -import org.apache.tuscany.core.builder.ContextFactoryBuilderRegistry; -import org.apache.tuscany.core.system.annotation.Autowire; -import org.apache.tuscany.model.assembly.AssemblyObject; - -@Scope("MODULE") -public class TestBuilder implements ContextFactoryBuilder { - private ContextFactoryBuilderRegistry builderRegistry; - - private boolean invoked = false; - - public TestBuilder() { - super(); - } - - @Init(eager = true) - public void init() { - builderRegistry.register(this); - } - - @Autowire - public void setBuilderRegistry(ContextFactoryBuilderRegistry builderRegistry) { - this.builderRegistry = builderRegistry; - } - - public void build(AssemblyObject object) throws BuilderException { - invoked = true; - } - - public boolean invoked() { - return invoked; - } -} |