/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */

package org.jfox.framework.xml;

import java.io.File;

import junit.framework.TestCase;
import org.jfox.framework.deploy.ComponentDescriptor;
import org.jfox.framework.deploy.ModuleDescriptor;
import org.jfox.framework.deploy.PropertyDescriptor;
import org.jfox.framework.util.XmlUtils;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class ComponentBundleTest extends TestCase {
    ModuleDescriptor moduleDescriptor;

    public void setUp() throws Exception {
        super.setUp();
        moduleDescriptor = new ModuleDescriptor(XmlUtils.getDocument(new File("modules/SampleA/META-INF/module.xml").toURL()));
    }

    public void tearDown() throws Exception {
        super.setUp();
    }

    public void testCount() {
        ComponentDescriptor[] cds = moduleDescriptor.getComponentDescriptors();
        assertEquals(1, cds.length);
    }

    public void testComponentDescriptor() {
        ComponentDescriptor cd = moduleDescriptor.getComponentDescriptors()[0];
        assertEquals(cd.getImplementation(), "org.jfox.framework.TestComponentA");
    }

    public void testConstructor() {
        ComponentDescriptor cd = moduleDescriptor.getComponentDescriptors()[0];
        assertEquals(cd.getConstructorDescriptor().getParamDescriptors()[0].getType(), "java.lang.String");
    }

    public void testProperty() {
        ComponentDescriptor cd = moduleDescriptor.getComponentDescriptors()[0];
        PropertyDescriptor[] pds = cd.getPropertyDescriptors();
        assertEquals(2, pds.length);
        assertEquals(pds[0].getName(), "name");
        assertEquals(pds[1].getParamDescriptors()[0].getRef(), "org.jfox.framework.TestComponentB");
        assertNull(pds[0].getParamDescriptors()[0].getType());
    }

}