Tests init BLD200601102030
authorjungi@netbeans.org
Tue, 10 Jan 2006 16:53:46 +0000
changeset 67363a1986921606
parent 6735 23fde1a315a4
child 6737 f3b6014cfefc
Tests init
j2ee.ejbfreeform/nbproject/project.properties
j2ee.ejbfreeform/test/build-unit.xml
j2ee.ejbfreeform/test/build.xml
j2ee.ejbfreeform/test/cfg-unit.xml
j2ee.ejbfreeform/test/unit/src/org/netbeans/modules/j2ee/ejbfreeform/EJBProjectGeneratorTest.java
j2ee.ejbfreeform/test/unit/src/org/netbeans/modules/j2ee/ejbfreeform/TestBase.java
     1.1 --- a/j2ee.ejbfreeform/nbproject/project.properties	Tue Jan 10 16:24:12 2006 +0000
     1.2 +++ b/j2ee.ejbfreeform/nbproject/project.properties	Tue Jan 10 16:53:46 2006 +0000
     1.3 @@ -15,14 +15,22 @@
     1.4  # masterfs needed for the usual reasons
     1.5  # core needed for ArchiveURLMapper
     1.6  test.unit.run.cp.extra=\
     1.7 +    ${openide/modules.dir}/lib/org-openide-modules.jar:\
     1.8      ${openide/masterfs.dir}/modules/org-netbeans-modules-masterfs.jar:\
     1.9      ${openidex.dir}/modules/org-openidex-util.jar:\
    1.10      ${projects/projectui.dir}/modules/org-netbeans-modules-projectui.jar:\
    1.11 -    ${core.dir}/core/core.jar:\
    1.12 +    ${core.dir}/modules/org-netbeans-core.jar:\
    1.13 +    ${core/swing/plaf.dir}/modules/org-netbeans-swing-plaf.jar:\
    1.14 +    ${core/startup.dir}/core/core.jar:\
    1.15      ${core.dir}/lib/boot.jar:\
    1.16      ${libs/xerces.dir}/modules/ext/xerces-2.6.2.jar:\
    1.17      ${libs/xerces.dir}/modules/ext/xml-commons-dom-ranges-1.0.b2.jar:\
    1.18      ${ant.dir}/modules/org-apache-tools-ant-module.jar:\
    1.19 +    ${openide/compat.dir}/modules/org-openide-compat.jar:\
    1.20      ${openide/io.dir}/modules/org-openide-io.jar:\
    1.21 -    ${openide/loaders.dir}/core/openide-loaders.jar
    1.22 +    ${openide/loaders.dir}/core/openide-loaders.jar:\
    1.23 +    ${j2eeserver.dir}/modules/ext/jsr88javax.jar:\
    1.24 +    ${openide/windows.dir}/modules/org-openide-windows.jar:\
    1.25 +    ${j2ee/genericserver.dir}/modules/org-netbeans-modules-j2ee-genericserver.jar
    1.26  test-unit-sys-prop.test.ant.home=${ant.dir}/ant
    1.27 +test-unit-sys-prop.test.netbeans.user=testerIde
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/j2ee.ejbfreeform/test/build-unit.xml	Tue Jan 10 16:53:46 2006 +0000
     2.3 @@ -0,0 +1,20 @@
     2.4 +<?xml version="1.0" encoding="UTF-8"?>
     2.5 +<!--
     2.6 +                Sun Public License Notice
     2.7 +
     2.8 +The contents of this file are subject to the Sun Public License
     2.9 +Version 1.0 (the "License"). You may not use this file except in
    2.10 +compliance with the License. A copy of the License is available at
    2.11 +http://www.sun.com/
    2.12 +
    2.13 +The Original Code is NetBeans. The Initial Developer of the Original
    2.14 +Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
    2.15 +Microsystems, Inc. All Rights Reserved.
    2.16 +-->
    2.17 +
    2.18 +<project name="j2ee/ejbfreeform/test-unit" basedir="." default="all">
    2.19 +
    2.20 +    <import file="../../../nbbuild/templates/xtest-unit.xml"/>
    2.21 +    
    2.22 +</project>
    2.23 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/j2ee.ejbfreeform/test/build.xml	Tue Jan 10 16:53:46 2006 +0000
     3.3 @@ -0,0 +1,26 @@
     3.4 +<?xml version="1.0"?>
     3.5 +<!--
     3.6 +                Sun Public License Notice
     3.7 +
     3.8 +The contents of this file are subject to the Sun Public License
     3.9 +Version 1.0 (the "License"). You may not use this file except in
    3.10 +compliance with the License. A copy of the License is available at
    3.11 +http://www.sun.com/
    3.12 +
    3.13 +The Original Code is NetBeans. The Initial Developer of the Original
    3.14 +Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
    3.15 +Microsystems, Inc. All Rights Reserved.
    3.16 +-->
    3.17 +<project name="j2ee/ejbfreeform/test" basedir="." default="all">
    3.18 +
    3.19 +    <!-- Name of tested module -->
    3.20 +    <property name="xtest.module" value="j2ee/ejbfreeform"/>
    3.21 +    
    3.22 +    <import file="../../../nbbuild/templates/xtest.xml"/>
    3.23 +    
    3.24 +    <!-- default testtypes, attributes used when no value is supplied from command line -->
    3.25 +    <property name="xtest.testtype" value="unit"/>
    3.26 +    <property name="xtest.attribs" value="stable"/>
    3.27 +    
    3.28 +</project>
    3.29 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/j2ee.ejbfreeform/test/cfg-unit.xml	Tue Jan 10 16:53:46 2006 +0000
     4.3 @@ -0,0 +1,27 @@
     4.4 +<?xml version="1.0" encoding="UTF-8"?>
     4.5 +<!--
     4.6 +                Sun Public License Notice
     4.7 +
     4.8 +The contents of this file are subject to the Sun Public License
     4.9 +Version 1.0 (the "License"). You may not use this file except in
    4.10 +compliance with the License. A copy of the License is available at
    4.11 +http://www.sun.com/
    4.12 +
    4.13 +The Original Code is NetBeans. The Initial Developer of the Original
    4.14 +Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
    4.15 +Microsystems, Inc. All Rights Reserved.
    4.16 +-->
    4.17 +
    4.18 +<mconfig name="j2ee/ejbfreeform">
    4.19 +
    4.20 +    <testbag testattribs="stable" executor="unit-executor" name="j2ee/ejbfreeform">
    4.21 +        <testset dir="unit/src">
    4.22 +            <patternset>
    4.23 +                <include name="**/*Test.class"/>
    4.24 +            </patternset>
    4.25 +        </testset>
    4.26 +    </testbag>
    4.27 +    <compiler name="default-compiler" antfile="build-unit.xml" target="default-compiler" default="true"/>
    4.28 +    <executor name="unit-executor" antfile="build-unit.xml" target="run-unit-test"/>
    4.29 +
    4.30 +</mconfig>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/j2ee.ejbfreeform/test/unit/src/org/netbeans/modules/j2ee/ejbfreeform/EJBProjectGeneratorTest.java	Tue Jan 10 16:53:46 2006 +0000
     5.3 @@ -0,0 +1,135 @@
     5.4 +/*
     5.5 + *                 Sun Public License Notice
     5.6 + *
     5.7 + * The contents of this file are subject to the Sun Public License
     5.8 + * Version 1.0 (the "License"). You may not use this file except in
     5.9 + * compliance with the License. A copy of the License is available at
    5.10 + * http://www.sun.com/
    5.11 + *
    5.12 + * The Original Code is NetBeans. The Initial Developer of the Original
    5.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
    5.14 + * Microsystems, Inc. All Rights Reserved.
    5.15 + */
    5.16 +
    5.17 +package org.netbeans.modules.j2ee.ejbfreeform;
    5.18 +
    5.19 +import java.io.File;
    5.20 +import java.io.FileOutputStream;
    5.21 +import java.io.OutputStream;
    5.22 +import java.util.ArrayList;
    5.23 +import java.util.List;
    5.24 +import java.util.jar.JarEntry;
    5.25 +import java.util.jar.JarOutputStream;
    5.26 +import org.netbeans.api.project.Project;
    5.27 +import org.netbeans.api.project.ProjectInformation;
    5.28 +import org.netbeans.api.project.ProjectManager;
    5.29 +import org.netbeans.api.project.ProjectUtils;
    5.30 +import org.netbeans.modules.ant.freeform.spi.support.Util;
    5.31 +import org.netbeans.modules.java.freeform.JavaProjectGenerator;
    5.32 +import org.netbeans.spi.project.support.ant.AntProjectHelper;
    5.33 +import org.openide.filesystems.FileObject;
    5.34 +import org.openide.filesystems.FileUtil;
    5.35 +import org.w3c.dom.Element;
    5.36 +import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
    5.37 +import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarProvider;
    5.38 +
    5.39 +/**
    5.40 + * Tests for JavaProjectGenerator.
    5.41 + *
    5.42 + * @author David Konecny
    5.43 + */
    5.44 +public class EJBProjectGeneratorTest extends TestBase {
    5.45 +    
    5.46 +    private File lib1;
    5.47 +    private File lib2;
    5.48 +    private File src;
    5.49 +    private File test;
    5.50 +    private File conf;
    5.51 +    
    5.52 +    protected void setUp() throws Exception {
    5.53 +        super.setUp();
    5.54 +    }
    5.55 +    
    5.56 +    public EJBProjectGeneratorTest(java.lang.String testName) {
    5.57 +        super(testName);
    5.58 +    }
    5.59 +    
    5.60 +    private AntProjectHelper createEmptyProject(String projectFolder, String projectName) throws Exception {
    5.61 +        File base = new File(getWorkDir(), projectFolder);
    5.62 +        base.mkdir();
    5.63 +        File antScript = new File(base, "build.xml");
    5.64 +        antScript.createNewFile();
    5.65 +        src = new File(base, "src");
    5.66 +        src.mkdir();
    5.67 +        conf = new File(base, "conf");
    5.68 +        conf.mkdir();
    5.69 +        new File(conf, "ejb-jar.xml").createNewFile();
    5.70 +        test = new File(base, "test");
    5.71 +        test.mkdir();
    5.72 +        File libs = new File(base, "libs");
    5.73 +        libs.mkdir();
    5.74 +        lib1 = new File(libs, "some.jar");
    5.75 +        createRealJarFile(lib1);
    5.76 +        lib2 = new File(libs, "some2.jar");
    5.77 +        createRealJarFile(lib2);
    5.78 +        EJBProjectGenerator.EJBModule ejbMod = new EJBProjectGenerator.EJBModule();
    5.79 +        ejbMod.j2eeSpecLevel = "1.4";
    5.80 +        ejbMod.classpath = "";
    5.81 +        ejbMod.configFiles = Util.relativizeLocation(base, base, FileUtil.normalizeFile(conf));
    5.82 +        List mods = new ArrayList();
    5.83 +        mods.add(ejbMod);
    5.84 +        AntProjectHelper helper = FreeformProjectGenerator.createProject(base, base, projectName, null);
    5.85 +        EJBProjectGenerator.putEJBModules(helper, Util.getAuxiliaryConfiguration(helper), mods);
    5.86 +        EJBProjectGenerator.putServerID(helper, "GENERIC");
    5.87 +        
    5.88 +        //srcFolders
    5.89 +        JavaProjectGenerator.SourceFolder sf = new JavaProjectGenerator.SourceFolder();
    5.90 +        sf.label = "src";
    5.91 +        sf.type = "java";
    5.92 +        sf.style = "packages";
    5.93 +        sf.location = src.getAbsolutePath();
    5.94 +        ArrayList sources = new ArrayList();
    5.95 +        sources.add(sf);
    5.96 +        JavaProjectGenerator.putSourceFolders(helper, sources, null);
    5.97 +        List l = new ArrayList();
    5.98 +        String s = Util.relativizeLocation(base, base, FileUtil.normalizeFile(src));
    5.99 +        l.add(s);
   5.100 +        l.add(src.getName());
   5.101 +        EJBProjectGenerator.putEJBSourceFolder(helper, l);
   5.102 +        
   5.103 +        return helper;
   5.104 +    }
   5.105 +    
   5.106 +    public void testEJBModules() throws Exception {
   5.107 +        AntProjectHelper helper = createEmptyProject("proj1", "proj-1");
   5.108 +        FileObject base = helper.getProjectDirectory();
   5.109 +        Project p = ProjectManager.getDefault().findProject(base);
   5.110 +        ProjectManager.getDefault().saveProject(p);
   5.111 +        assertNotNull("Project was not created", p);
   5.112 +        assertEquals("Project folder is incorrect", base, p.getProjectDirectory());
   5.113 +        ProjectInformation pi = ProjectUtils.getInformation(p);
   5.114 +        assertEquals("Project name was not set", "proj-1", pi.getName());
   5.115 +        /*
   5.116 +        EjbJarProvider eji = (EjbJarProvider) p.getLookup().lookup(EjbJarProvider.class);
   5.117 +        assertNotNull(eji.findEjbJar(p.getProjectDirectory()));
   5.118 +        System.out.println("eji" + eji);
   5.119 +         */
   5.120 +        EJBModules e = new EJBModules(p, helper, helper.getStandardPropertyEvaluator());
   5.121 +        assertNotNull("EJBModules not found", e);
   5.122 +        assertEquals(FileUtil.toFileObject(new File(conf, "ejb-jar.xml")), e.getEjbJars()[0].getDeploymentDescriptor());
   5.123 +    }
   5.124 +    
   5.125 +    // create real Jar otherwise FileUtil.isArchiveFile returns false for it
   5.126 +    public void createRealJarFile(File f) throws Exception {
   5.127 +        OutputStream os = new FileOutputStream(f);
   5.128 +        try {
   5.129 +            JarOutputStream jos = new JarOutputStream(os);
   5.130 +            JarEntry entry = new JarEntry("foo.txt");
   5.131 +            jos.putNextEntry(entry);
   5.132 +            jos.flush();
   5.133 +            jos.close();
   5.134 +        } finally {
   5.135 +            os.close();
   5.136 +        }
   5.137 +    }
   5.138 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/j2ee.ejbfreeform/test/unit/src/org/netbeans/modules/j2ee/ejbfreeform/TestBase.java	Tue Jan 10 16:53:46 2006 +0000
     6.3 @@ -0,0 +1,109 @@
     6.4 +/*
     6.5 + * TestBase.java
     6.6 + * NetBeans JUnit based test
     6.7 + *
     6.8 + * Created on 10. leden 2006, 14:40
     6.9 + */
    6.10 +
    6.11 +package org.netbeans.modules.j2ee.ejbfreeform;
    6.12 +
    6.13 +import java.io.File;
    6.14 +import org.netbeans.junit.*;
    6.15 +import org.openide.filesystems.FileObject;
    6.16 +import org.openide.filesystems.FileSystem;
    6.17 +import org.openide.filesystems.LocalFileSystem;
    6.18 +import org.openide.filesystems.MultiFileSystem;
    6.19 +import org.openide.filesystems.Repository;
    6.20 +import org.openide.filesystems.XMLFileSystem;
    6.21 +import org.openide.util.Lookup;
    6.22 +import org.openide.util.lookup.InstanceContent;
    6.23 +import org.openide.util.lookup.Lookups;
    6.24 +import org.openide.util.lookup.ProxyLookup;
    6.25 +
    6.26 +/**
    6.27 + *
    6.28 + * @author jungi
    6.29 + */
    6.30 +public class TestBase extends NbTestCase {
    6.31 +    
    6.32 +    static {
    6.33 +        System.setProperty("org.openide.util.Lookup", Lkp.class.getName());
    6.34 +    }
    6.35 +    
    6.36 +    public TestBase(java.lang.String testName) {
    6.37 +        super(testName);
    6.38 +    }
    6.39 +    
    6.40 +    protected void setUp() throws Exception {
    6.41 +        super.setUp();
    6.42 +        clearWorkDir();
    6.43 +        scratchF = getWorkDir();
    6.44 +        mkdir("system/J2EE/InstalledServers");
    6.45 +        mkdir("system/J2EE/DeploymentPlugins");
    6.46 +        System.setProperty("SYSTEMDIR", new File(scratchF, "system").getAbsolutePath());
    6.47 +        FileObject sfs = Repository.getDefault().getDefaultFileSystem().getRoot();
    6.48 +        assertNotNull("no default FS", sfs);
    6.49 +        FileObject j2eeFolder = sfs.getFileObject("J2EE");
    6.50 +        assertNotNull("have J2EE", j2eeFolder);
    6.51 +    }
    6.52 +    
    6.53 +    private File scratchF;
    6.54 +    
    6.55 +    private void mkdir(String path) {
    6.56 +        new File(scratchF, path.replace('/', File.separatorChar)).mkdirs();
    6.57 +    }
    6.58 +    
    6.59 +    private static final class Repo extends Repository {
    6.60 +        
    6.61 +        public Repo() throws Exception {
    6.62 +            super(mksystem());
    6.63 +        }
    6.64 +        
    6.65 +        private static FileSystem mksystem() throws Exception {
    6.66 +            LocalFileSystem lfs = new LocalFileSystem();
    6.67 +            lfs.setRootDirectory(new File(System.getProperty("SYSTEMDIR")));
    6.68 +            //get layer for the generic server
    6.69 +            java.net.URL layerFile = Repo.class.getClassLoader().getResource("org/netbeans/modules/j2ee/genericserver/resources/layer.xml");
    6.70 +            assert layerFile != null;
    6.71 +            XMLFileSystem layer = new XMLFileSystem(layerFile);
    6.72 +            FileSystem layers [] = new FileSystem [] {lfs, layer};
    6.73 +            MultiFileSystem mfs = new MultiFileSystem(layers);
    6.74 +            return mfs;
    6.75 +        }
    6.76 +        
    6.77 +    }
    6.78 +    
    6.79 +    public static final class Lkp extends ProxyLookup {
    6.80 +        
    6.81 +        public Lkp() {
    6.82 +            super(new Lookup[] {
    6.83 +                Lookups.fixed(new Object[] {"repo"}, new Conv()),
    6.84 +                Lookups.metaInfServices(Lkp.class.getClassLoader()),
    6.85 +                Lookups.singleton(Lkp.class.getClassLoader()),
    6.86 +            });
    6.87 +        }
    6.88 +        
    6.89 +        private static final class Conv implements InstanceContent.Convertor {
    6.90 +            public Conv() {}
    6.91 +            public Object convert(Object obj) {
    6.92 +                assert obj == "repo";
    6.93 +                try {
    6.94 +                    return new Repo();
    6.95 +                } catch (Exception e) {
    6.96 +                    e.printStackTrace();
    6.97 +                    return null;
    6.98 +                }
    6.99 +            }
   6.100 +            public String displayName(Object obj) {
   6.101 +                return obj.toString();
   6.102 +            }
   6.103 +            public String id(Object obj) {
   6.104 +                return obj.toString();
   6.105 +            }
   6.106 +            public Class type(Object obj) {
   6.107 +                assert obj == "repo";
   6.108 +                return Repository.class;
   6.109 +            }
   6.110 +        }
   6.111 +    }
   6.112 +}