KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbfreeform > TestBase


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbfreeform;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.api.project.ProjectManager;
25 import org.netbeans.junit.*;
26 import org.netbeans.modules.ant.freeform.FreeformProject;
27 import org.netbeans.modules.java.platform.JavaPlatformProvider;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileSystem;
30 import org.openide.filesystems.FileUtil;
31 import org.openide.filesystems.LocalFileSystem;
32 import org.openide.filesystems.MultiFileSystem;
33 import org.openide.filesystems.Repository;
34 import org.openide.filesystems.XMLFileSystem;
35 import org.openide.modules.ModuleInfo;
36 import org.openide.util.Lookup;
37 import org.openide.util.lookup.InstanceContent;
38 import org.openide.util.lookup.Lookups;
39 import org.openide.util.lookup.ProxyLookup;
40
41 /**
42  *
43  * @author jungi
44  */

45 public class TestBase extends NbTestCase {
46     
47     static {
48 // System.setProperty("org.openide.util.Lookup", Lkp.class.getName());
49
}
50     
51     protected File JavaDoc egdir;
52     protected FileObject buildXml;
53     protected FreeformProject ejbFF;
54     protected FileObject ejbJarXml;
55     protected FileObject bean;
56     protected FileObject schema;
57
58     public TestBase(java.lang.String JavaDoc testName) {
59         super(testName);
60     }
61     
62     protected void setUp() throws Exception JavaDoc {
63         super.setUp();
64         Lookup.getDefault().lookup(ModuleInfo.class);
65         clearWorkDir();
66         scratchF = getWorkDir();
67         mkdir("system/J2EE/InstalledServers");
68         mkdir("system/J2EE/DeploymentPlugins");
69         System.setProperty("SYSTEMDIR", new File JavaDoc(scratchF, "system").getAbsolutePath());
70         FileObject sfs = Repository.getDefault().getDefaultFileSystem().getRoot();
71         assertNotNull("no default FS", sfs);
72         FileObject j2eeFolder = sfs.getFileObject("J2EE");
73         assertNotNull("have J2EE", j2eeFolder);
74     }
75     
76     protected void setUpProject() throws Exception JavaDoc {
77         egdir = FileUtil.normalizeFile(getDataDir());
78         assertTrue("data dir " + egdir + " exists", egdir.exists());
79         FileObject prjDir = FileUtil.toFileObject(egdir).getFileObject("test-app");
80         assertNotNull("found projdir", prjDir);
81         Project _ejbFF = ProjectManager.getDefault().findProject(prjDir);
82         assertNotNull("have a project", _ejbFF);
83         EJBProjectGeneratorTest.validate(_ejbFF);
84         ejbFF = (FreeformProject)_ejbFF;
85         ejbJarXml = prjDir.getFileObject("conf/ejb-jar.xml");
86         assertNotNull("found ejb-jar.xml", ejbJarXml);
87         bean = prjDir.getFileObject("src/beans/ent/CustomerLocal.java");
88         assertNotNull("found CustomerLocal", bean);
89         schema = prjDir.getFileObject("resources/APP_test-app.dbschema");
90         assertNotNull("found dbschema", schema);
91         buildXml = prjDir.getFileObject("build.xml");
92         assertNotNull("found build.xml", buildXml);
93     }
94
95     protected boolean runInEQ() {
96         return true;
97     }
98     
99     private File JavaDoc scratchF;
100     
101     private void mkdir(String JavaDoc path) {
102         new File JavaDoc(scratchF, path.replace('/', File.separatorChar)).mkdirs();
103     }
104     
105 // private static final class Repo extends Repository {
106
//
107
// public Repo() throws Exception {
108
// super(mksystem());
109
// }
110
//
111
// private static FileSystem mksystem() throws Exception {
112
// LocalFileSystem lfs = new LocalFileSystem();
113
// lfs.setRootDirectory(new File(System.getProperty("SYSTEMDIR")));
114
// //get layer for the generic server
115
// java.net.URL layerFile = Repo.class.getClassLoader().getResource("org/netbeans/modules/j2ee/genericserver/resources/layer.xml");
116
// assert layerFile != null;
117
// XMLFileSystem layer = new XMLFileSystem(layerFile);
118
// FileSystem layers [] = new FileSystem [] {lfs, layer};
119
// MultiFileSystem mfs = new MultiFileSystem(layers);
120
// return mfs;
121
// }
122
//
123
// }
124
//
125
// public static final class Lkp extends ProxyLookup {
126
//
127
// public Lkp() {
128
// super(new Lookup[] {
129
// Lookups.fixed(new Object[] {"repo", new DummyJavaPlatformProvider()}, new Conv()),
130
// Lookups.metaInfServices(Lkp.class.getClassLoader()),
131
// Lookups.singleton(Lkp.class.getClassLoader())
132
// });
133
// }
134
//
135
// private static final class Conv implements InstanceContent.Convertor {
136
// public Conv() {}
137
// public Object convert(Object obj) {
138
// if (obj instanceof JavaPlatformProvider) {
139
// return obj;
140
// }
141
// assert obj == "repo";
142
// try {
143
// return new Repo();
144
// } catch (Exception e) {
145
// e.printStackTrace();
146
// return null;
147
// }
148
// }
149
// public String displayName(Object obj) {
150
// return obj.toString();
151
// }
152
// public String id(Object obj) {
153
// return obj.toString();
154
// }
155
// public Class type(Object obj) {
156
// if (obj instanceof JavaPlatformProvider) {
157
// return JavaPlatformProvider.class;
158
// }
159
// assert obj == "repo";
160
// return Repository.class;
161
// }
162
// }
163
// }
164

165 }
166
Popular Tags