tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmar...@apache.org
Subject svn commit: r368298 [7/9] - in /incubator/tuscany/contrib/java/trunk/runtime: binding.axis/ common/ container.java/ container.java/src/main/java/org/apache/tuscany/container/java/assembly/impl/ container.java/src/main/java/org/apache/tuscany/container/...
Date Thu, 12 Jan 2006 07:22:33 GMT
Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/injection/ReflectionHelperTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/injection/ReflectionHelperTestCase.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/injection/ReflectionHelperTestCase.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/injection/ReflectionHelperTestCase.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,74 @@
+package org.apache.tuscany.core.injection;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.config.JavaIntrospectionHelper;
+
+public class ReflectionHelperTestCase extends TestCase {
+
+    public ReflectionHelperTestCase() {
+        super();
+    }
+
+    public ReflectionHelperTestCase(String arg0) {
+        super(arg0);
+    }
+
+    public void testGetSuperAllFields() throws Exception {
+        Set<Field> superBeanFields = JavaIntrospectionHelper.getAllFields(SuperBean.class);
+        Assert.assertEquals(SuperBean.ALL_SUPER_FIELDS, superBeanFields.size());
+    }
+
+    public void testBean1AllFields() throws Exception {
+        Set<Field> beanFields = JavaIntrospectionHelper.getAllFields(Bean1.class);
+        Assert.assertEquals(Bean1.ALL_BEAN1_FIELDS, beanFields.size());
+    }
+
+    public void testGetSuperAllMethods() throws Exception {
+        Set<Method> superBeanMethods = JavaIntrospectionHelper.getAllUniqueMethods(SuperBean.class);
+        Assert.assertEquals(SuperBean.ALL_SUPER_METHODS, superBeanMethods.size());
+    }
+
+    public void testGetBean1AllMethods() throws Exception {
+        Set<Method> beanMethods = JavaIntrospectionHelper.getAllUniqueMethods(Bean1.class);
+        Assert.assertEquals(Bean1.ALL__BEAN1_METHODS, beanMethods.size());
+    }
+
+    public void testOverrideMethod() throws Exception {
+        Set<Method> beanFields = JavaIntrospectionHelper.getAllUniqueMethods(Bean1.class);
+        boolean invoked = false;
+        for (Method method : beanFields) {
+            if (method.getName().equals("override")) {
+                method.invoke(new Bean1(), new Object[]{"foo"});
+                invoked = true;
+            }
+        }
+        if (!invoked) {
+            throw new Exception("Override never invoked");
+        }
+    }
+
+    public void testNoOverrideMethod() throws Exception {
+        Set<Method> beanFields = JavaIntrospectionHelper.getAllUniqueMethods(Bean1.class);
+        boolean found = false;
+        for (Method method : beanFields) {
+            if (method.getName().equals("noOverride") && method.getParameterTypes().length == 0) {
+                found = true;
+            }
+        }
+        if (!found) {
+            throw new Exception("No override not found");
+        }
+    }
+
+    public void testGetBean1AllFields() throws Exception {
+        Set<Field> bean1 = JavaIntrospectionHelper.getAllFields(Bean1.class);
+        Assert.assertEquals(Bean1.ALL_BEAN1_FIELDS, bean1.size());
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/injection/SuperBean.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/injection/SuperBean.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/injection/SuperBean.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/injection/SuperBean.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,27 @@
+package org.apache.tuscany.core.injection;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SuperBean {
+
+    public static final int ALL_SUPER_FIELDS = 3;
+
+    public static final int ALL_SUPER_METHODS = 4;
+
+    private String superField1;
+
+    public void setSuperMethod1(String param) {
+    }
+
+    public void setSuperMethod1(int param) {
+    }
+
+    public void override(String param) throws Exception {
+        throw new Exception("Override not handled");
+    }
+
+    public void noOverride() throws Exception {
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,48 @@
+/**
+ * 
+ * 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.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.core.builder.BuilderConfigException;
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.builder.impl.AssemblyVisitor;
+import org.apache.tuscany.core.config.ConfigurationException;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.ConfigurationContext;
+import org.apache.tuscany.model.assembly.ExtensibleModelObject;
+
+/**
+ *  A mock configuration context
+ * 
+ * @version $Rev$ $Date$
+ */
+public class MockConfigContext implements ConfigurationContext {
+
+    private List<RuntimeConfigurationBuilder> builders = new ArrayList();
+
+    public MockConfigContext(List<RuntimeConfigurationBuilder> builders) {
+        this.builders=builders;
+    }
+
+    public void configure(ExtensibleModelObject model) throws ConfigurationException {
+    }
+
+    public void build(AggregateContext parent, ExtensibleModelObject model) throws BuilderConfigException {
+        AssemblyVisitor visitor = new AssemblyVisitor(parent, builders);
+        visitor.start(model);
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/MockSystemAssemblyFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/MockSystemAssemblyFactory.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/MockSystemAssemblyFactory.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/MockSystemAssemblyFactory.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,262 @@
+/**
+ * 
+ * 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.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.core.builder.RuntimeConfiguration;
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.config.JavaIntrospectionHelper;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent;
+import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl;
+import org.apache.tuscany.core.system.assembly.SystemImplementation;
+import org.apache.tuscany.core.system.assembly.pojo.PojoSystemBinding;
+import org.apache.tuscany.core.system.assembly.pojo.PojoSystemImplementation;
+import org.apache.tuscany.core.system.builder.SystemComponentContextBuilder;
+import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder;
+import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder;
+import org.apache.tuscany.model.assembly.Component;
+import org.apache.tuscany.model.assembly.EntryPoint;
+import org.apache.tuscany.model.assembly.ExternalService;
+import org.apache.tuscany.model.assembly.Module;
+import org.apache.tuscany.model.assembly.Part;
+import org.apache.tuscany.model.assembly.ScopeEnum;
+import org.apache.tuscany.model.assembly.Service;
+import org.apache.tuscany.model.assembly.pojo.PojoAggregateComponent;
+import org.apache.tuscany.model.assembly.pojo.PojoComponent;
+import org.apache.tuscany.model.assembly.pojo.PojoConfiguredReference;
+import org.apache.tuscany.model.assembly.pojo.PojoConfiguredService;
+import org.apache.tuscany.model.assembly.pojo.PojoEntryPoint;
+import org.apache.tuscany.model.assembly.pojo.PojoExternalService;
+import org.apache.tuscany.model.assembly.pojo.PojoInterface;
+import org.apache.tuscany.model.assembly.pojo.PojoInterfaceType;
+import org.apache.tuscany.model.assembly.pojo.PojoJavaInterface;
+import org.apache.tuscany.model.assembly.pojo.PojoModule;
+import org.apache.tuscany.model.assembly.pojo.PojoPart;
+import org.apache.tuscany.model.assembly.pojo.PojoReference;
+import org.apache.tuscany.model.assembly.pojo.PojoService;
+import org.apache.tuscany.model.assembly.pojo.PojoSimpleComponent;
+import org.apache.tuscany.model.types.java.JavaInterface;
+
+/**
+ * Creates test artifacts for system types such as runtime configurations and system components
+ * 
+ * @version $Rev$ $Date$
+ */
+public class MockSystemAssemblyFactory {
+
+    private MockSystemAssemblyFactory() {
+    }
+
+    public static List<RuntimeConfigurationBuilder> createBuilders() {
+        List<RuntimeConfigurationBuilder> builders = new ArrayList();
+        builders.add((new SystemComponentContextBuilder()));
+        builders.add(new SystemEntryPointBuilder());
+        builders.add(new SystemExternalServiceBuilder());
+        return builders;
+    }
+
+    /**
+     * Creates a component
+     * 
+     * @param name the name of the component
+     * @param type the component implementation class name
+     * @param scope the scope of the component implementation
+     * @param aggregateContext the containing aggregate context
+     * @throws NoSuchMethodException
+     * @throws ClassNotFoundException
+     * @see RuntimeConfiguration
+     */
+    public static Component createComponent(String name, String type, ScopeEnum scope) throws NoSuchMethodException,
+            ClassNotFoundException {
+
+        Class claz = JavaIntrospectionHelper.loadClass(type);
+        PojoComponent sc = null;
+        if (AggregateContext.class.isAssignableFrom(claz)) {
+            sc = new PojoAggregateComponent();
+        } else {
+            sc = new PojoSimpleComponent();
+        }
+        SystemImplementation impl = new PojoSystemImplementation();
+        impl.setClass(type);
+        sc.setComponentImplementation(impl);
+        Service s = new PojoService();
+        JavaInterface ji = new PojoJavaInterface();
+        s.setInterfaceContract(ji);
+        ji.setScope(scope);
+        impl.getServices().add(s);
+        sc.setName(name);
+        sc.setComponentImplementation(impl);
+        return sc;
+    }
+
+    /**
+     * Creates a basic entry point with no configured reference using the system binding
+     * 
+     * @param name the name of the entry point
+     * @param interfaz the inteface exposed by the entry point
+     * @param refName the name of the entry point reference
+     */
+    public static PojoEntryPoint createEntryPoint(String name, Class interfaz, String refName) {
+        return createEntryPoint(name, interfaz, refName, null);
+    }
+
+    /**
+     * Creates an entry point wired to the given target (e.g. component, external service) using the system binding
+     * 
+     * @param name the name of the entry point
+     * @param interfaz the inteface exposed by the entry point
+     * @param refName the name of the entry point reference
+     * @param referenceTarget the target of the entry point wire
+     */
+    public static PojoEntryPoint createEntryPoint(String name, Class interfaz, String refName, Part referenceTarget) {
+        // create entry point
+        PojoEntryPoint ep = new PojoEntryPoint();
+        ep.setName(name);
+        PojoReference ref = new PojoReference();
+        ref.setName(refName);
+        PojoConfiguredReference configuredReference = new PojoConfiguredReference();
+        configuredReference.setReference(ref);
+        PojoConfiguredService service = new PojoConfiguredService();
+        configuredReference.addConfiguredService(service);
+        ep.setConfiguredReference(configuredReference);
+        ep.getConfiguredReference().getConfiguredServices().get(0).setPart(referenceTarget);
+        PojoInterfaceType interfaceType = new PojoInterfaceType();
+        interfaceType.setInstanceClass(interfaz);
+        PojoInterface inter = new PojoJavaInterface();
+        inter.setInterfaceType(interfaceType);
+        ep.setInterfaceContract(inter);
+        ep.getBindings().add(new PojoSystemBinding());
+        return ep;
+    }
+
+    /**
+     * Creates an entry point that should be wired to the given target (e.g. component, external service) using the
+     * system binding. The system assembly process should resolve the target name to an actual target configuration.
+     * 
+     * @param name the name of the entry point
+     * @param interfaz the inteface exposed by the entry point
+     * @param refName the name of the entry point reference
+     * @param componentName the name of the target to resolve
+     */
+    public static PojoEntryPoint createEntryPointWithStringRef(String name, Class interfaz, String refName, String componentName) {
+        PojoEntryPoint ep = createEntryPoint(name, interfaz, refName, null);
+        PojoConfiguredReference cRef = new PojoConfiguredReference();
+        PojoReference ref = new PojoReference();
+        cRef.setReference(ref);
+        PojoService service = new PojoService();
+        service.setName(componentName);
+        PojoConfiguredService cService = new PojoConfiguredService();
+        cService.setService(service);
+        cRef.getConfiguredServices().add(cService);
+        ep.setConfiguredReference(cRef);
+        return ep;
+    }
+
+    /**
+     * Creates an external service
+     */
+    public static ExternalService createExternalService(String name, String refName) {
+        PojoExternalService es = new PojoExternalService();
+        es.setName(name);
+        PojoConfiguredService configuredService = new PojoConfiguredService();
+        // FIXME No idea if this is correct, I suspect it isn't
+        PojoPart part = new PojoPart();
+        part.setName(refName);
+        configuredService.setPart(part);
+        es.setConfiguredService(configuredService);
+        es.getBindings().add(new PojoSystemBinding());
+        return es;
+    }
+
+    /**
+     * Creates an external service that specifies an autowire of the given type
+     */
+    public static ExternalService createAutowirableExternalService(String name, Class type) {
+        PojoExternalService es = new PojoExternalService();
+        es.setName(name);
+        PojoInterface inter = new PojoJavaInterface();
+        PojoInterfaceType interType = new PojoInterfaceType();
+        interType.setInstanceClass(type);
+        inter.setInterfaceType(interType);
+        es.setInterfaceContract(inter);
+        es.getBindings().add(new PojoSystemBinding());
+        PojoConfiguredService configuredService = new PojoConfiguredService();
+        es.setConfiguredService(configuredService);
+        return es;
+    }
+
+    /**
+     * Creates a test system module component with a module-scoped component and entry point
+     */
+    public static Module createSystemModule() throws Exception {
+        PojoModule module = new PojoModule();
+        module.setName("system.module");
+
+        // create test component
+        PojoSimpleComponent component = new PojoSimpleComponent();
+        component.setName("TestService1");
+        SystemImplementation impl = new PojoSystemImplementation();
+        impl.setClass(ModuleScopeSystemComponentImpl.class.getName());
+        component.setComponentImplementation(impl);
+        Service s = new PojoService();
+        JavaInterface ji = new PojoJavaInterface();
+        s.setInterfaceContract(ji);
+        ji.setScope(ScopeEnum.MODULE_LITERAL);
+        impl.getServices().add(s);
+        component.setComponentImplementation(impl);
+
+        // create the entry point
+        EntryPoint ep = createEntryPoint("TestService1EP", ModuleScopeSystemComponent.class, "target");
+        // wire the entry point to the component
+        ep.getConfiguredReference().getConfiguredServices().get(0).setPart(component);
+
+        module.addEntryPoint(ep);
+        module.addComponent(component);
+        return module;
+    }
+
+    /**
+     * Creates a test system module component with a module-scoped component and entry point
+     */
+    public static Module createSystemChildModule() throws Exception {
+        PojoModule module = new PojoModule();
+        module.setName("system.test.module");
+
+        // create test component
+        PojoSimpleComponent component = new PojoSimpleComponent();
+        component.setName("TestService2");
+        SystemImplementation impl = new PojoSystemImplementation();
+        impl.setClass(ModuleScopeSystemComponentImpl.class.getName());
+        component.setComponentImplementation(impl);
+        Service s = new PojoService();
+        JavaInterface ji = new PojoJavaInterface();
+        s.setInterfaceContract(ji);
+        ji.setScope(ScopeEnum.MODULE_LITERAL);
+        impl.getServices().add(s);
+        component.setComponentImplementation(impl);
+
+        // create the entry point
+        EntryPoint ep = createEntryPoint("TestService2EP", ModuleScopeSystemComponent.class, "target");
+        // wire the entry point to the component
+        ep.getConfiguredReference().getConfiguredServices().get(0).setPart(component);
+
+        module.addEntryPoint(ep);
+        module.addComponent(component);
+        return module;
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/GenericSystemComponent.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/GenericSystemComponent.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/GenericSystemComponent.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/GenericSystemComponent.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,6 @@
+package org.apache.tuscany.core.mock.component;
+
+public interface GenericSystemComponent {
+
+}
+

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponent.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponent.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponent.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponent.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,28 @@
+/**
+ *
+ *  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.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("MODULE")
+public interface ModuleScopeSystemComponent extends GenericSystemComponent {
+
+}
+

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponentImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponentImpl.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponentImpl.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/mock/component/ModuleScopeSystemComponentImpl.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,25 @@
+/**
+ *
+ *  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.mock.component;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ModuleScopeSystemComponentImpl implements ModuleScopeSystemComponent {
+
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentContextBuilderTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentContextBuilderTestCase.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentContextBuilderTestCase.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentContextBuilderTestCase.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,137 @@
+/**
+ * 
+ * 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.RuntimeConfiguration;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.InstanceContext;
+import org.apache.tuscany.core.context.ContextConstants;
+import org.apache.tuscany.core.context.impl.AggregateContextImpl;
+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.MockSystemAssemblyFactory;
+import org.apache.tuscany.core.monitor.ConsoleMonitorFactory;
+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.pojo.PojoConfiguredProperty;
+import org.apache.tuscany.model.assembly.pojo.PojoProperty;
+
+/**
+ * Tests to that system components are built properly
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SystemComponentContextBuilderTestCase extends TestCase {
+
+    public void testComponentContextBuilder() throws Exception {
+        SystemComponentContextBuilder builder = new SystemComponentContextBuilder();
+        Component component = MockSystemAssemblyFactory.createComponent("test", SystemComponentImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+
+        ConfiguredProperty cProp = new PojoConfiguredProperty();
+        Property prop = new PojoProperty();
+        prop.setName("testInt");
+        cProp.setValue(1);
+        cProp.setProperty(prop);
+        component.getConfiguredProperties().add(cProp);
+
+        cProp = new PojoConfiguredProperty();
+        prop = new PojoProperty();
+        prop.setName("testString");
+        cProp.setValue("test");
+        cProp.setProperty(prop);
+        component.getConfiguredProperties().add(cProp);
+
+        cProp = new PojoConfiguredProperty();
+        prop = new PojoProperty();
+        prop.setName("testDouble");
+        cProp.setValue(1d);
+        cProp.setProperty(prop);
+        component.getConfiguredProperties().add(cProp);
+
+        cProp = new PojoConfiguredProperty();
+        prop = new PojoProperty();
+        prop.setName("testFloat");
+        cProp.setValue(1f);
+        cProp.setProperty(prop);
+        component.getConfiguredProperties().add(cProp);
+
+        cProp = new PojoConfiguredProperty();
+        prop = new PojoProperty();
+        prop.setName("testShort");
+        cProp.setValue((short) 1);
+        cProp.setProperty(prop);
+        component.getConfiguredProperties().add(cProp);
+
+        cProp = new PojoConfiguredProperty();
+        prop = new PojoProperty();
+        prop.setName("testByte");
+        cProp.setValue((byte) 1);
+        cProp.setProperty(prop);
+        component.getConfiguredProperties().add(cProp);
+
+        cProp = new PojoConfiguredProperty();
+        prop = new PojoProperty();
+        prop.setName("testBoolean");
+        cProp.setValue(Boolean.TRUE);
+        cProp.setProperty(prop);
+        component.getConfiguredProperties().add(cProp);
+
+        cProp = new PojoConfiguredProperty();
+        prop = new PojoProperty();
+        prop.setName("testChar");
+        cProp.setValue('1');
+        cProp.setProperty(prop);
+        component.getConfiguredProperties().add(cProp);
+        
+        builder.setParentContext(createContext());
+        builder.setModelObject(component);
+        builder.build();
+        RuntimeConfiguration config = (RuntimeConfiguration) component.getComponentImplementation().getRuntimeConfiguration();
+        Assert.assertNotNull(config);
+        InstanceContext ctx = (InstanceContext) config.createInstanceContext();
+        
+        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.stop();
+        Assert.assertTrue(instance.destroyed());
+    }
+
+    private AggregateContext createContext() {
+        return new AggregateContextImpl("test.parent", null, new DefaultScopeStrategy(), new EventContextImpl(),
+                new MockConfigContext(null), new ConsoleMonitorFactory());
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/SystemComponentImpl.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,165 @@
+/**
+ * 
+ * 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.AggregateContext;
+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;
+
+/**
+ * A system component used for unit testing
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SystemComponentImpl {
+
+    @Autowire
+    private ConfigurationContext ctx;
+
+    @ParentContext
+    private AggregateContext parent;
+
+    @Autowire
+    private AutowireContext autowireCtx;
+
+    private ConfigurationContext ctxSetter;
+
+    private AggregateContext parentSetter;
+
+    private AutowireContext autowireCtxSetter;
+
+    public ConfigurationContext getConfigContext() {
+        return ctx;
+    }
+
+    public AggregateContext 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(AggregateContext ctx) {
+        parentSetter = ctx;
+    }
+
+    public AggregateContext 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 == true);
+    }
+
+   private boolean destroyed;
+    
+    @Destroy
+    public void destroy(){
+        destroyed=true;
+    }
+    
+    public boolean destroyed(){
+        return (destroyed == true);
+    }
+    
+    @Property
+    private int testInt;
+    
+    public int getTestInt(){
+        return testInt;
+    }
+
+    @Property
+    private double testDouble;
+    
+    public double getTestDouble(){
+        return testDouble;
+    }
+
+    @Property
+    private float testFloat;
+    
+    public float getTestFloat(){
+        return testFloat;
+    }
+    
+    @Property
+    private short testShort;
+    
+    public short getTestShort(){
+        return testShort;
+    }
+    
+    @Property
+    private boolean testBoolean;
+    
+    public boolean getTestBoolean(){
+        return testBoolean;
+    }
+    
+    @Property
+    private byte testByte;
+    
+    public byte getTestByte(){
+        return testByte;
+    }
+    
+    @Property
+    private char testChar;
+    
+    public char getTestChar(){
+        return testChar;
+    }
+    
+    @Property
+    private String testString;
+    
+    public String getTestString(){
+        return testString;
+    }
+
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/builder/impl/AssemblyVisitorTestCase.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,104 @@
+/**
+ * 
+ * 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.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.builder.impl.AssemblyVisitor;
+import org.apache.tuscany.core.context.Context;
+import org.apache.tuscany.core.system.assembly.pojo.PojoSystemBinding;
+import org.apache.tuscany.core.system.assembly.pojo.PojoSystemImplementation;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
+import org.apache.tuscany.model.assembly.ConfiguredPort;
+import org.apache.tuscany.model.assembly.ConfiguredRuntimeObject;
+import org.apache.tuscany.model.assembly.pojo.PojoConfiguredReference;
+import org.apache.tuscany.model.assembly.pojo.PojoEntryPoint;
+import org.apache.tuscany.model.assembly.pojo.PojoModule;
+import org.apache.tuscany.model.assembly.pojo.PojoReference;
+import org.apache.tuscany.model.assembly.pojo.PojoSimpleComponent;
+
+/**
+ * Tests decorating a logical configuration model
+ * 
+ * @version $Rev$ $Date$
+ */
+public class AssemblyVisitorTestCase extends TestCase {
+
+    private static final Object MARKER = new Object();
+
+    public void testModelVisit() throws Exception {
+        PojoSimpleComponent component = new PojoSimpleComponent();
+        PojoSystemImplementation impl = new PojoSystemImplementation();
+        component.setComponentImplementation(impl);
+        PojoConfiguredReference cRef = new PojoConfiguredReference();
+        PojoReference ref = new PojoReference();
+        cRef.setReference(ref);
+        component.getConfiguredReferences().add(cRef);
+
+        PojoEntryPoint ep = new PojoEntryPoint();
+        PojoSystemBinding binding = new PojoSystemBinding();
+        ep.addBinding(binding);
+        PojoConfiguredReference cEpRef = new PojoConfiguredReference();
+        PojoReference epRef = new PojoReference();
+        cEpRef.setReference(epRef);
+        ep.setConfiguredReference(cEpRef);
+
+        PojoModule module = new PojoModule();
+        module.getComponents().add(component);
+        module.getEntryPoints().add(ep);
+
+        List<RuntimeConfigurationBuilder> builders = new ArrayList();
+        builders.add(new TestBuilder());
+        AssemblyVisitor visitor = new AssemblyVisitor(null, builders);
+        visitor.start(module);
+
+        Assert.assertSame(MARKER, impl.getRuntimeConfiguration());
+        Assert.assertSame(MARKER, cRef.getRuntimeConfiguration());
+        Assert.assertSame(MARKER, cRef.getProxyFactory());
+        Assert.assertSame(MARKER, binding.getRuntimeConfiguration());
+        Assert.assertSame(MARKER, cEpRef.getRuntimeConfiguration());
+        Assert.assertSame(MARKER, cEpRef.getProxyFactory());
+        Assert.assertSame(MARKER, module.getRuntimeConfiguration());
+
+    }
+
+    private class TestBuilder implements RuntimeConfigurationBuilder {
+
+        private AssemblyModelObject model;
+
+        public void setModelObject(AssemblyModelObject model) {
+            this.model = model;
+        }
+
+        public void setParentContext(Context context) {
+        }
+
+        public void build() throws BuilderException {
+            if (model instanceof ConfiguredPort) {
+                ((ConfiguredPort) model).setProxyFactory(MARKER);
+            }
+            if (model instanceof ConfiguredRuntimeObject) {
+                ((ConfiguredRuntimeObject) model).setRuntimeConfiguration(MARKER);
+            }
+        }
+
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/RuntimeBootTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/RuntimeBootTestCase.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/RuntimeBootTestCase.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/RuntimeBootTestCase.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,66 @@
+/**
+ * 
+ * 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 java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.EventContext;
+import org.apache.tuscany.core.context.Context;
+import org.apache.tuscany.core.context.ContextConstants;
+import org.apache.tuscany.core.mock.MockSystemAssemblyFactory;
+import org.apache.tuscany.core.monitor.ConsoleMonitorFactory;
+import org.apache.tuscany.model.assembly.Component;
+
+/**
+ * Tests runtime boot scenarios
+ * 
+ * @version $Rev$ $Date$
+ */
+public class RuntimeBootTestCase extends TestCase {
+
+    public void testIncrementalBoot() throws Exception{
+
+        List<RuntimeConfigurationBuilder> builders  = MockSystemAssemblyFactory.createBuilders();
+        // start the runtime context
+        RuntimeContext runtimeContext = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtimeContext.start();
+        
+        // create the system context
+        Component component = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM,
+                SystemAggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtimeContext.registerModelObject(component);
+        
+        AggregateContext system = runtimeContext.getSystemContext();
+        Assert.assertNotNull(system);
+        // register system components
+        system.registerModelObject(MockSystemAssemblyFactory.createSystemModule());
+        // start the module scope
+        system.fireEvent(EventContext.MODULE_START, null);
+        // register the first module
+        
+        // register the second module
+        
+        // start the modules
+        
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        runtimeContext.stop();
+        Assert.assertEquals(Context.STOPPED,system.getLifecycleState());
+    }
+}
+

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/RuntimeContextImplTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/RuntimeContextImplTestCase.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/RuntimeContextImplTestCase.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/RuntimeContextImplTestCase.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,360 @@
+/**
+ * 
+ * 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 java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.config.ConfigurationException;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.EventContext;
+import org.apache.tuscany.core.context.Context;
+import org.apache.tuscany.core.context.ContextConstants;
+import org.apache.tuscany.core.context.impl.AggregateContextImpl;
+import org.apache.tuscany.core.mock.MockSystemAssemblyFactory;
+import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent;
+import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl;
+import org.apache.tuscany.core.monitor.ConsoleMonitorFactory;
+import org.apache.tuscany.core.system.assembly.pojo.PojoSystemBinding;
+import org.apache.tuscany.model.assembly.Component;
+import org.apache.tuscany.model.assembly.EntryPoint;
+import org.apache.tuscany.model.assembly.ExternalService;
+import org.apache.tuscany.model.assembly.ScopeEnum;
+import org.apache.tuscany.model.assembly.Service;
+import org.apache.tuscany.model.assembly.pojo.PojoConfiguredService;
+import org.apache.tuscany.model.assembly.pojo.PojoEntryPoint;
+import org.apache.tuscany.model.assembly.pojo.PojoInterface;
+import org.apache.tuscany.model.assembly.pojo.PojoInterfaceType;
+import org.apache.tuscany.model.assembly.pojo.PojoJavaInterface;
+import org.apache.tuscany.model.assembly.pojo.PojoService;
+import org.osoa.sca.ModuleContext;
+import org.osoa.sca.ServiceUnavailableException;
+
+/**
+ * Performs basic tests on the runtime context
+ * 
+ * @version $Rev$ $Date$
+ */
+public class RuntimeContextImplTestCase extends TestCase {
+
+    /**
+     * Tests explicit wiring of an external service to a system entry point that is wired to a child system module entry
+     * point
+     */
+    public void testSystemExplicitWiring() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+
+        RuntimeContext runtime = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtime.start();
+
+        AggregateContext root = runtime.getRootContext();
+        Assert.assertNotNull(root);
+        Assert.assertTrue(root.getLifecycleState() == Context.RUNNING);
+
+        // register the system context
+        runtime.registerModelObject(MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM,
+                SystemAggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM));
+        AggregateContext system = (AggregateContext) runtime.getSystemContext();
+        Assert.assertNotNull(system);
+        system.registerModelObject(MockSystemAssemblyFactory.createSystemModule());
+
+        // register a child system context
+        system.registerModelObject(MockSystemAssemblyFactory.createComponent("system.child", SystemAggregateContextImpl.class
+                .getName(), ContextConstants.AGGREGATE_SCOPE_ENUM));
+        AggregateContext systemChild = (AggregateContext) system.getContext("system.child");
+        systemChild.registerModelObject(MockSystemAssemblyFactory.createSystemChildModule());
+
+        // register a top-level system entry point that exposes the child entry point
+        PojoEntryPoint ep = MockSystemAssemblyFactory.createEntryPoint("TestService2EP", ModuleScopeSystemComponent.class, "ref");
+        ep.addBinding(new PojoSystemBinding());
+        Service service = new PojoService();
+        service.setName("system.child/TestService2EP");
+        ((PojoConfiguredService) ep.getConfiguredReference().getConfiguredServices().get(0)).setService(service);
+        PojoInterface inter = new PojoJavaInterface();
+        PojoInterfaceType interType = new PojoInterfaceType();
+        interType.setInstanceClass(ModuleScopeSystemComponentImpl.class);
+        inter.setInterfaceType(interType);
+        service.setInterfaceContract(inter);
+        ep.setInterfaceContract(inter);
+        system.registerModelObject(ep);
+        system.fireEvent(EventContext.MODULE_START, null);
+        Assert.assertNotNull(system.locateInstance("TestService1"));
+        Assert.assertNotNull(system.locateInstance("TestService2EP"));
+
+        // create a test module and wire an external service to the system entry point
+        Component moduleComponent = MockSystemAssemblyFactory.createComponent("test.module",
+                AggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(moduleComponent);
+        AggregateContextImpl moduleContext = (AggregateContextImpl) runtime.getContext("test.module");
+        Assert.assertNotNull(moduleContext);
+        ExternalService es = MockSystemAssemblyFactory.createExternalService("TestService2ES", "tuscany.system/TestService2EP");
+        moduleContext.registerModelObject(es);
+        moduleContext.fireEvent(EventContext.MODULE_START, null);
+        Assert.assertNotNull(moduleContext.locateInstance("TestService2ES"));
+
+        moduleContext.fireEvent(EventContext.MODULE_STOP, null);
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        runtime.stop();
+    }
+
+    /**
+     * Tests autowiring an external service to a system entry point
+     */
+    public void testSystemAutoWiring() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+
+        RuntimeContext runtime = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtime.start();
+
+        AggregateContext root = runtime.getRootContext();
+        Assert.assertNotNull(root);
+        Assert.assertTrue(root.getLifecycleState() == Context.RUNNING);
+
+        // register the system context
+        runtime.registerModelObject(MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM,
+                SystemAggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM));
+        AggregateContext system = (AggregateContext) runtime.getSystemContext();
+        Assert.assertNotNull(system);
+        system.registerModelObject(MockSystemAssemblyFactory.createSystemModule());
+
+        // create a test module and wire an external service to the system entry point
+        Component moduleComponent = MockSystemAssemblyFactory.createComponent("test.module",
+                AggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(moduleComponent);
+        AggregateContextImpl moduleContext = (AggregateContextImpl) runtime.getContext("test.module");
+        Assert.assertNotNull(moduleContext);
+        ExternalService es = MockSystemAssemblyFactory.createAutowirableExternalService("TestService2ES",
+                ModuleScopeSystemComponent.class);
+        moduleContext.registerModelObject(es);
+
+        system.fireEvent(EventContext.MODULE_START, null);
+        moduleContext.fireEvent(EventContext.MODULE_START, null);
+        // test that the autowire was resolved
+        Assert.assertNotNull(moduleContext.locateInstance("TestService2ES"));
+
+        moduleContext.fireEvent(EventContext.MODULE_STOP, null);
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        runtime.stop();
+    }
+
+    public void testServiceNotFound() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+
+        RuntimeContext runtime = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtime.start();
+        Component systemComponent = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM, SystemAggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(systemComponent);
+        // create a test module
+        Component moduleComponent = MockSystemAssemblyFactory.createComponent("module", AggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(moduleComponent);
+        AggregateContextImpl moduleContext = (AggregateContextImpl) runtime.getContext("module");
+        moduleContext.fireEvent(EventContext.MODULE_START, null);
+        try {
+            ((ModuleContext) moduleContext).locateService("TestService");
+            fail("Expected " + ServiceUnavailableException.class.getName());
+        } catch (ServiceUnavailableException e) {
+            // expected
+        }
+        moduleContext.fireEvent(EventContext.MODULE_STOP, null);
+        runtime.stop();
+    }
+
+    public void testExternalServiceReferenceNotFound() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+
+        RuntimeContext runtime = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtime.start();
+        // create the system context
+        Component component = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM, SystemAggregateContextImpl.class
+                .getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(component);
+        AggregateContext system = runtime.getSystemContext();
+
+        // create a test module
+        Component moduleComponent = MockSystemAssemblyFactory.createComponent("module", AggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(moduleComponent);
+        AggregateContextImpl moduleContext = (AggregateContextImpl) runtime.getContext("module");
+        ExternalService es = MockSystemAssemblyFactory.createExternalService("TestServiceES", "tuscany.system/TestService1xEP");
+        moduleContext.registerModelObject(es);
+
+        // start the modules and test inter-module system wires
+        system.fireEvent(EventContext.MODULE_START, null);
+        moduleContext.fireEvent(EventContext.MODULE_START, null);
+        try {
+            ((ModuleContext) moduleContext).locateService("TestServiceES");
+            fail("Expected " + ServiceUnavailableException.class.getName());
+        } catch (ServiceUnavailableException e) {
+            // expected
+        }
+        moduleContext.fireEvent(EventContext.MODULE_STOP, null);
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        runtime.stop();
+    }
+
+    public void testEntryPointReferenceNotFound() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+
+        RuntimeContext runtime = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtime.start();
+        Component systemComponent = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM, SystemAggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(systemComponent);
+
+        // create a test module
+        Component moduleComponent = MockSystemAssemblyFactory.createComponent("module", AggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(moduleComponent);
+
+        Component component = MockSystemAssemblyFactory.createComponent("NoService", ModuleScopeSystemComponentImpl.class
+                .getName(), ScopeEnum.MODULE_LITERAL);
+        // do not register the above component!
+
+        AggregateContextImpl moduleContext = (AggregateContextImpl) runtime.getContext("module");
+        moduleContext.registerModelObject(MockSystemAssemblyFactory.createEntryPoint("TestServiceEP",
+                ModuleScopeSystemComponent.class, "NoReference", component));
+
+        moduleContext.fireEvent(EventContext.MODULE_START, null);
+        try {
+            ((ModuleContext) moduleContext).locateService("TestServiceEP");
+            fail("Expected " + ServiceUnavailableException.class.getName());
+        } catch (ServiceUnavailableException e) {
+            // expected
+        }
+        moduleContext.fireEvent(EventContext.MODULE_STOP, null);
+        runtime.stop();
+    }
+
+    /**
+     * Test two module components that have external services wired to entry points contained in each
+     */
+    public void testCircularWires() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+        RuntimeContext runtime = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtime.start();
+        Component systemComponent = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM, SystemAggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(systemComponent);
+
+        // create a test modules
+        Component module1 = MockSystemAssemblyFactory.createComponent("module1", AggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(module1);
+        Component module2 = MockSystemAssemblyFactory.createComponent("module2", AggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(module2);
+
+        AggregateContextImpl moduleContext1 = (AggregateContextImpl) runtime.getContext("module1");
+        AggregateContextImpl moduleContext2 = (AggregateContextImpl) runtime.getContext("module2");
+
+        Component component1 = MockSystemAssemblyFactory.createComponent("Component1", ModuleScopeSystemComponentImpl.class
+                .getName(), ScopeEnum.MODULE_LITERAL);
+        EntryPoint entryPoint1 = MockSystemAssemblyFactory.createEntryPoint("EntryPoint1", ModuleScopeSystemComponent.class,
+                "Component1", component1);
+        ExternalService externalService1 = MockSystemAssemblyFactory.createExternalService("ExternalService1",
+                "module2/EntryPoint2");
+        moduleContext1.registerModelObject(component1);
+        moduleContext1.registerModelObject(entryPoint1);
+        moduleContext1.registerModelObject(externalService1);
+
+        Component component2 = MockSystemAssemblyFactory.createComponent("Component2", ModuleScopeSystemComponentImpl.class
+                .getName(), ScopeEnum.MODULE_LITERAL);
+        EntryPoint entryPoint2 = MockSystemAssemblyFactory.createEntryPoint("EntryPoint2", ModuleScopeSystemComponent.class,
+                "Component2", component2);
+        ExternalService externalService2 = MockSystemAssemblyFactory.createExternalService("ExternalService2",
+                "module1/EntryPoint1");
+        moduleContext2.registerModelObject(component2);
+        moduleContext2.registerModelObject(entryPoint2);
+        moduleContext2.registerModelObject(externalService2);
+
+        moduleContext1.fireEvent(EventContext.MODULE_START, null);
+        moduleContext2.fireEvent(EventContext.MODULE_START, null);
+        Assert.assertNotNull(moduleContext2.locateInstance("ExternalService2"));
+        Assert.assertNotNull(moduleContext1.locateInstance("ExternalService1"));
+        runtime.stop();
+    }
+
+    /**
+     * Tests that a circular reference between an external service in one module and an entry point in another is caught
+     * as an error condition FIXME this must be implemented
+     */
+    public void testInterModuleCircularReference() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+
+        RuntimeContext runtime = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtime.start();
+        Component systemComponent = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM, SystemAggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(systemComponent);
+
+        // create a test modules
+        Component module1 = MockSystemAssemblyFactory.createComponent("module1", AggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(module1);
+        Component module2 = MockSystemAssemblyFactory.createComponent("module2", AggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(module2);
+
+        AggregateContextImpl moduleContext1 = (AggregateContextImpl) runtime.getContext("module1");
+        AggregateContextImpl moduleContext2 = (AggregateContextImpl) runtime.getContext("module2");
+        ExternalService externalService1 = MockSystemAssemblyFactory.createExternalService("ExternalService1",
+                "module2/EntryPoint2");
+        EntryPoint entryPoint1 = MockSystemAssemblyFactory.createEntryPoint("EntryPoint1", ModuleScopeSystemComponent.class,
+                "ExternalService1", externalService1);
+        ExternalService externalService2 = MockSystemAssemblyFactory.createExternalService("ExternalService2",
+                "module1/EntryPoint1");
+        EntryPoint entryPoint2 = MockSystemAssemblyFactory.createEntryPoint("EntryPoint2", ModuleScopeSystemComponent.class,
+                "ExternalService2", externalService2);
+        try {
+            // FIXME this should throw a circular reference exception
+            moduleContext1.registerModelObject(externalService1);
+            moduleContext1.registerModelObject(entryPoint1);
+            moduleContext2.registerModelObject(externalService2);
+            moduleContext2.registerModelObject(entryPoint2);
+            // FIXME implement fail("Expected " + ConfigurationException.class.getName());
+        } catch (ConfigurationException e) {
+            // expected
+        }
+    }
+
+    public void testRuntimeBuilderAutowire() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+
+        RuntimeContext runtime = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtime.start();
+        Component systemComponent = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM,
+                SystemAggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(systemComponent);
+
+        AggregateContext system = runtime.getSystemContext();
+        Component builder = MockSystemAssemblyFactory.createComponent("TestBuilder", TestBuilder.class.getName(),
+                ScopeEnum.MODULE_LITERAL);
+        system.registerModelObject(builder);
+        system.fireEvent(EventContext.MODULE_START, null);
+        Component module1 = MockSystemAssemblyFactory.createComponent("module1", AggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(module1);
+        AggregateContextImpl moduleContext1 = (AggregateContextImpl) runtime.getContext("module1");
+        Assert.assertTrue(((TestBuilder)system.locateInstance("TestBuilder")).invoked());
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        runtime.stop();
+
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateComponentContextRegisterTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateComponentContextRegisterTestCase.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateComponentContextRegisterTestCase.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateComponentContextRegisterTestCase.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,40 @@
+/**
+ * 
+ * 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 java.util.List;
+
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.context.AggregateComponentContextRegisterTestCase;
+import org.apache.tuscany.core.context.AggregateContext;
+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.MockSystemAssemblyFactory;
+import org.apache.tuscany.core.monitor.ConsoleMonitorFactory;
+
+/**
+ * Tests registration of model objects for an system aggregate context
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SystemAggregateComponentContextRegisterTestCase extends AggregateComponentContextRegisterTestCase {
+
+    protected AggregateContext createContext() {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+        AggregateContext moduleContext = new SystemAggregateContextImpl("test.context", null,
+                new DefaultScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders), new ConsoleMonitorFactory());
+        return moduleContext;
+    }
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateComponentContextTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateComponentContextTestCase.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateComponentContextTestCase.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateComponentContextTestCase.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,131 @@
+/**
+ * 
+ * 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 java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.EventContext;
+import org.apache.tuscany.core.context.ContextConstants;
+import org.apache.tuscany.core.context.impl.AggregateContextImpl;
+import org.apache.tuscany.core.context.impl.EventContextImpl;
+import org.apache.tuscany.core.mock.MockConfigContext;
+import org.apache.tuscany.core.mock.MockSystemAssemblyFactory;
+import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent;
+import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl;
+import org.apache.tuscany.core.monitor.ConsoleMonitorFactory;
+import org.apache.tuscany.model.assembly.Component;
+import org.apache.tuscany.model.assembly.EntryPoint;
+import org.apache.tuscany.model.assembly.ScopeEnum;
+
+/**
+ * Tests the system aggregate context
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SystemAggregateComponentContextTestCase extends TestCase {
+
+    public void testChildLocate() throws Exception {
+        List<RuntimeConfigurationBuilder> builders  = MockSystemAssemblyFactory.createBuilders();
+
+        SystemAggregateContextImpl system = new SystemAggregateContextImpl("system", null,
+                new SystemScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders), new ConsoleMonitorFactory());
+        system.start();
+
+        Component aggregateComponent = MockSystemAssemblyFactory.createComponent("system.child",
+                AggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
+        system.registerModelObject(aggregateComponent);
+        AggregateContext childContext = (AggregateContext) system.getContext("system.child");
+        Assert.assertNotNull(childContext);
+
+        Component component = MockSystemAssemblyFactory.createComponent("TestService1", ModuleScopeSystemComponentImpl.class.getName(),
+                ScopeEnum.MODULE_LITERAL);
+        EntryPoint ep = MockSystemAssemblyFactory.createEntryPoint("TestService1EP", ModuleScopeSystemComponent.class,
+                "TestService1", component);
+        childContext.registerModelObject(component);
+        childContext.registerModelObject(ep);
+        childContext.fireEvent(EventContext.MODULE_START, null);
+        Assert.assertNotNull(system.locateInstance("system.child/TestService1EP"));
+        childContext.fireEvent(EventContext.MODULE_STOP, null);
+        system.stop();
+    }
+
+    public void testAutowire() throws Exception {
+        List<RuntimeConfigurationBuilder> builders  = MockSystemAssemblyFactory.createBuilders();
+        SystemAggregateContextImpl system = new SystemAggregateContextImpl("system", null,
+                new SystemScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders), new ConsoleMonitorFactory());
+
+        Component component = MockSystemAssemblyFactory.createComponent("TestService1", ModuleScopeSystemComponentImpl.class
+                .getName(), ScopeEnum.MODULE_LITERAL);
+        EntryPoint ep = MockSystemAssemblyFactory.createEntryPoint("TestService1EP", ModuleScopeSystemComponent.class,
+                "TestService1", component);
+        system.registerModelObject(component);
+        system.registerModelObject(ep);
+        system.start();
+        system.fireEvent(EventContext.MODULE_START, null);
+        Assert.assertSame(system.locateInstance("TestService1EP"), system.resolveInstance(ModuleScopeSystemComponent.class));
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        system.stop();
+    }
+
+    public void testAutowireRegisterAfterStart() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+
+        SystemAggregateContextImpl system = new SystemAggregateContextImpl("system", null,
+                new SystemScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders), new ConsoleMonitorFactory());
+
+        Component component = MockSystemAssemblyFactory.createComponent("TestService1", ModuleScopeSystemComponentImpl.class
+                .getName(), ScopeEnum.MODULE_LITERAL);
+        system.registerModelObject(component);
+        system.start();
+        system.fireEvent(EventContext.MODULE_START, null);
+        EntryPoint ep = MockSystemAssemblyFactory.createEntryPoint("TestService1EP", ModuleScopeSystemComponent.class,
+                "TestService1", component);
+        system.registerModelObject(ep);
+        Assert.assertSame(system.locateInstance("TestService1EP"), system.resolveInstance(ModuleScopeSystemComponent.class));
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        system.stop();
+    }
+
+    public void testAutowireModuleRegister() throws Exception {
+        List<RuntimeConfigurationBuilder> builders  = MockSystemAssemblyFactory.createBuilders();
+
+        SystemAggregateContextImpl system = new SystemAggregateContextImpl("system", null,
+                new SystemScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders), new ConsoleMonitorFactory());
+        system.registerModelObject(MockSystemAssemblyFactory.createSystemModule());
+        system.start();
+        system.fireEvent(EventContext.MODULE_START, null);
+        Assert.assertSame(system.locateInstance("TestService1EP"), system.resolveInstance(ModuleScopeSystemComponent.class));
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        system.stop();
+    }
+    
+    public void testAutowireModuleRegisterAfterStart() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+        SystemAggregateContextImpl system = new SystemAggregateContextImpl("system", null,
+                new SystemScopeStrategy(), new EventContextImpl(), new MockConfigContext(builders), new ConsoleMonitorFactory());
+        system.start();
+        system.fireEvent(EventContext.MODULE_START, null);
+        system.registerModelObject(MockSystemAssemblyFactory.createSystemModule());
+        Assert.assertSame(system.locateInstance("TestService1EP"), system.resolveInstance(ModuleScopeSystemComponent.class));
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        system.stop();
+    }
+
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateHierarchyTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateHierarchyTestCase.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateHierarchyTestCase.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemAggregateHierarchyTestCase.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,52 @@
+/**
+ * 
+ * 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 java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.context.AbstractAggregateHierarchyTests;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.ContextConstants;
+import org.apache.tuscany.core.context.impl.AggregateContextImpl;
+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.MockSystemAssemblyFactory;
+import org.apache.tuscany.core.monitor.ConsoleMonitorFactory;
+
+/**
+ * Performs testing of various hierarchical scenarios
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SystemAggregateHierarchyTestCase extends AbstractAggregateHierarchyTests {
+
+
+
+    protected AggregateContext createContextHierachy() throws Exception {
+        List<RuntimeConfigurationBuilder> builders = MockSystemAssemblyFactory.createBuilders();
+        AggregateContext parent = new SystemAggregateContextImpl("test.parent", null, new DefaultScopeStrategy(),
+                new EventContextImpl(), new MockConfigContext(builders), new ConsoleMonitorFactory());
+        parent.registerModelObject(MockSystemAssemblyFactory.createComponent("test.child", AggregateContextImpl.class.getName(),
+                ContextConstants.AGGREGATE_SCOPE_ENUM));
+        parent.start();
+        AggregateContext child = (AggregateContext) parent.getContext("test.child");
+        Assert.assertNotNull(child);
+        return parent;
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemBootstrapTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemBootstrapTestCase.java?rev=368298&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemBootstrapTestCase.java (added)
+++ incubator/tuscany/contrib/java/trunk/runtime/core/src/test/java/org/apache/tuscany/core/system/context/SystemBootstrapTestCase.java Wed Jan 11 23:21:44 2006
@@ -0,0 +1,172 @@
+/**
+ * 
+ * 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 java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.AutowireContext;
+import org.apache.tuscany.core.context.EventContext;
+import org.apache.tuscany.core.context.ContextConstants;
+import org.apache.tuscany.core.context.impl.AggregateContextImpl;
+import org.apache.tuscany.core.mock.MockSystemAssemblyFactory;
+import org.apache.tuscany.core.mock.component.GenericSystemComponent;
+import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponent;
+import org.apache.tuscany.core.mock.component.ModuleScopeSystemComponentImpl;
+import org.apache.tuscany.core.monitor.ConsoleMonitorFactory;
+import org.apache.tuscany.core.system.assembly.pojo.PojoSystemBinding;
+import org.apache.tuscany.model.assembly.Component;
+import org.apache.tuscany.model.assembly.ExternalService;
+import org.apache.tuscany.model.assembly.Module;
+import org.apache.tuscany.model.assembly.Service;
+import org.apache.tuscany.model.assembly.pojo.PojoConfiguredService;
+import org.apache.tuscany.model.assembly.pojo.PojoEntryPoint;
+import org.apache.tuscany.model.assembly.pojo.PojoInterface;
+import org.apache.tuscany.model.assembly.pojo.PojoInterfaceType;
+import org.apache.tuscany.model.assembly.pojo.PojoJavaInterface;
+import org.apache.tuscany.model.assembly.pojo.PojoService;
+
+/**
+ * Tests bootstrapping a system module
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SystemBootstrapTestCase extends TestCase {
+
+    /**
+     * Simulates booting a runtime process
+     */
+    public void testBoot() throws Exception {
+        List<RuntimeConfigurationBuilder> builders  = MockSystemAssemblyFactory.createBuilders();
+
+        RuntimeContext runtimeContext = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtimeContext.start();
+        // create the system context
+        Component component = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM,
+                SystemAggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtimeContext.registerModelObject(component);
+        AggregateContext systemContext = runtimeContext.getSystemContext();
+        Assert.assertNotNull(systemContext);
+        Module systemModule = MockSystemAssemblyFactory.createSystemModule();
+       // MockSystemAssemblyFactory.buildModule(systemModule, systemContext);
+        systemContext.registerModelObject(systemModule);
+
+        // create a test module
+        Component moduleComponent = MockSystemAssemblyFactory.createComponent("module", AggregateContextImpl.class
+                .getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtimeContext.registerModelObject(moduleComponent);
+        AggregateContextImpl moduleContext = (AggregateContextImpl) runtimeContext.getContext("module");
+        Assert.assertNotNull(moduleContext);
+        ExternalService es = MockSystemAssemblyFactory.createExternalService("TestServiceES", "tuscany.system/TestService1EP");
+        moduleContext.registerModelObject(es);
+
+        // start the modules and test inter-module system wires
+        systemContext.fireEvent(EventContext.MODULE_START, null);
+        moduleContext.fireEvent(EventContext.MODULE_START, null);
+
+        Assert.assertNotNull(systemContext.locateInstance("TestService1EP"));
+        GenericSystemComponent testService = (GenericSystemComponent) systemContext.locateInstance("TestService1");
+        Assert.assertNotNull(testService);
+        GenericSystemComponent testES = (GenericSystemComponent) moduleContext.locateInstance("TestServiceES");
+        Assert.assertNotNull(testES);
+        Assert.assertSame(testService, testES);
+    }
+
+    public void testRuntimeBoot() throws Exception {
+        List<RuntimeConfigurationBuilder> builders  = MockSystemAssemblyFactory.createBuilders();
+        RuntimeContext runtime = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+        runtime.start();
+        runtime.getRootContext();
+        runtime.registerModelObject(MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM,
+                SystemAggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM));
+        AggregateContext system = (AggregateContext) runtime.getSystemContext();
+        system.registerModelObject(MockSystemAssemblyFactory.createSystemModule());
+        system.registerModelObject(MockSystemAssemblyFactory.createComponent("module2", SystemAggregateContextImpl.class
+                .getName(), ContextConstants.AGGREGATE_SCOPE_ENUM));
+        AggregateContext systemModule2 = (AggregateContext) system.getContext("module2");
+        systemModule2.registerModelObject(MockSystemAssemblyFactory.createSystemChildModule());
+
+        PojoEntryPoint ep = MockSystemAssemblyFactory.createEntryPoint("TestService2EP", ModuleScopeSystemComponent.class, "ref");
+        ep.addBinding(new PojoSystemBinding());
+        Service service = new PojoService();
+        service.setName("module2/TestService2EP");
+        ((PojoConfiguredService) ep.getConfiguredReference().getConfiguredServices().get(0)).setService(service);
+        PojoInterface inter = new PojoJavaInterface();
+        PojoInterfaceType interType = new PojoInterfaceType();
+        interType.setInstanceClass(ModuleScopeSystemComponentImpl.class);
+        inter.setInterfaceType(interType);
+        service.setInterfaceContract(inter);
+        ep.setInterfaceContract(inter);
+        system.registerModelObject(ep);
+        system.fireEvent(EventContext.MODULE_START, null);
+        Assert.assertNotNull(system.locateInstance("TestService1"));
+        Assert.assertNotNull(system.locateInstance("TestService2EP"));
+
+        Assert.assertNotNull(((AutowireContext) system).resolveInstance(ModuleScopeSystemComponentImpl.class));
+        // create a test module
+        Component moduleComponent = MockSystemAssemblyFactory.createComponent("test.module", AggregateContextImpl.class
+                .getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
+        runtime.registerModelObject(moduleComponent);
+        AggregateContextImpl moduleContext = (AggregateContextImpl) runtime.getContext("test.module");
+        Assert.assertNotNull(moduleContext);
+        ExternalService es = MockSystemAssemblyFactory.createExternalService("TestService2ES", "tuscany.system/TestService2EP");
+        moduleContext.registerModelObject(es);
+        moduleContext.fireEvent(EventContext.MODULE_START, null);
+        Assert.assertNotNull(moduleContext.locateInstance("TestService2ES"));
+
+        moduleContext.fireEvent(EventContext.MODULE_STOP, null);
+        system.fireEvent(EventContext.MODULE_STOP, null);
+        runtime.stop();
+    }
+    
+//    public void testT() throws Exception{
+//        
+//        List<RuntimeConfigurationBuilder> builders = new ArrayList();
+//        builders.add((new SystemComponentContextBuilder()));
+//        builders.add(new SystemEntryPointBuilder());
+//        builders.add(new SystemExternalServiceBuilder());
+//
+//        RuntimeContext runtimeContext = new RuntimeContextImpl(new ConsoleMonitorFactory(), builders, null);
+//        runtimeContext.start();
+//        // create the system context
+//        Component component = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM,
+//                SystemAggregateComponentContextImpl.class.getName(), ModuleConstants.AGGREGATE_SCOPE_ENUM);
+//        runtimeContext.registerModelObject(component);
+//        AggregateComponentContext systemContext = runtimeContext.getSystemContext();
+//        Assert.assertNotNull(systemContext);
+//        Module systemModule = MockSystemAssemblyFactory.createSystemModule();
+//        systemContext.registerModelObject(systemModule);
+//
+//        // create a test module
+//        Component moduleComponent = MockSystemAssemblyFactory.createComponent("module", AggregateComponentContextImpl.class
+//                .getName(), ModuleConstants.AGGREGATE_SCOPE_ENUM);
+//        runtimeContext.registerModelObject(moduleComponent);
+//        AggregateComponentContextImpl moduleContext = (AggregateComponentContextImpl) runtimeContext.getContext("module");
+//        Assert.assertNotNull(moduleContext);
+//        ExternalService es = MockSystemAssemblyFactory.createExternalService("TestServiceES", "tuscany.system/TestService1xEP");
+//        moduleContext.registerModelObject(es);
+//
+//        // start the modules and test inter-module system wires
+//        systemContext.fireEvent(EventContext.MODULE_START, null);
+//        moduleContext.fireEvent(EventContext.MODULE_START, null);
+//
+//        moduleContext.locateService("TestServiceES");
+//    }
+
+
+}



Mime
View raw message