diff options
Diffstat (limited to 'tags/java-M1-final/java/sca/core/src/test/java/org/apache/tuscany/core/system/context')
8 files changed, 0 insertions, 863 deletions
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; - } -} |