summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/test/java/org/apache/tuscany/container/js/config/ModuleComponentConfigurationLoaderTestCase.java
blob: 4f9ba1ab490e8a515ec8a85b53d4d75c9a5007ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
 *
 *  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.container.js.config;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
import org.apache.tuscany.container.js.assembly.impl.JavaScriptImplementationImpl;
import org.apache.tuscany.container.js.loader.JavaScriptSCDLModelLoader;
import org.apache.tuscany.core.config.ConfigurationException;
import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader;
import org.apache.tuscany.core.config.impl.ModuleComponentConfigurationLoaderImpl;
import org.apache.tuscany.model.assembly.AssemblyModelContext;
import org.apache.tuscany.model.assembly.Component;
import org.apache.tuscany.model.assembly.ComponentImplementation;
import org.apache.tuscany.model.assembly.Module;
import org.apache.tuscany.model.assembly.ModuleComponent;
import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl;
import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl;
import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader;
import org.apache.tuscany.model.scdl.loader.SCDLModelLoader;
import org.apache.tuscany.model.scdl.loader.impl.SCDLAssemblyModelLoaderImpl;

/**
 * @version $Rev: 368822 $ $Date: 2006-01-13 18:54:38 +0000 (Fri, 13 Jan 2006) $
 */
public class ModuleComponentConfigurationLoaderTestCase extends TestCase {
    private ModuleComponentConfigurationLoader loader;

    public void testFoo() throws ConfigurationException {
        URL xml = ModuleComponentConfigurationLoaderTestCase.class.getResource("ModuleComponentLoaderTest1.module");
        ModuleComponent moduleComponent = loader.loadModuleComponent("test", "test", xml.toString());
        Assert.assertEquals("test", moduleComponent.getName());
        Module module = moduleComponent.getModuleImplementation();
        Assert.assertEquals("ModuleComponentLoaderTest1", module.getName());
        List<Component> components = module.getComponents();
        Assert.assertEquals(1, components.size());
        Component component = components.get(0);
        Assert.assertEquals("HelloWorldServiceComponent", component.getName());

        component = module.getComponent("HelloWorldServiceComponent");
        Assert.assertEquals("HelloWorldServiceComponent", component.getName());

        ComponentImplementation implementation = component.getComponentImplementation();
        Assert.assertTrue(implementation instanceof JavaScriptImplementationImpl);
    }

    protected void setUp() throws Exception {
        super.setUp();
        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
        List<SCDLModelLoader> scdlLoaders=new ArrayList<SCDLModelLoader>();
        JavaScriptSCDLModelLoader jsLoader=new JavaScriptSCDLModelLoader();
        scdlLoaders.add(jsLoader);
        AssemblyModelLoader modelLoader=new SCDLAssemblyModelLoaderImpl(scdlLoaders);
        AssemblyModelContext modelContext=new AssemblyModelContextImpl(
                new AssemblyFactoryImpl(), modelLoader,new ResourceLoaderImpl(this.getClass().getClassLoader()));
          loader = new ModuleComponentConfigurationLoaderImpl(modelContext);
    }
}