001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006s Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package projects.apitest;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import junit.framework.*;
047: import org.netbeans.jellytools.JellyTestCase;
048: import org.netbeans.junit.NbTestSuite;
049: import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator;
050:
051: public class CreateProjectTest extends JellyTestCase {
052:
053: public CreateProjectTest(java.lang.String testName) {
054: super (testName);
055: }
056:
057: public static void main(java.lang.String[] args) {
058: junit.textui.TestRunner.run(suite());
059: }
060:
061: public static Test suite() {
062: TestSuite suite = new NbTestSuite(CreateProjectTest.class);
063: return suite;
064: }
065:
066: @Override
067: public void setUp() {
068: System.out.println("######## " + getName() + " #######"); // NOI18N
069: }
070:
071: public void testCreateAndOpenProject_API_1() throws Exception {
072: String projName = "testCreateAndOpenProject_API_1";
073: String mainClass = "MyMain" + projName; // NOI18N
074: File projectDir = new File(getWorkDir(), projName);
075: projectDir.mkdir();
076: J2SEProjectGenerator.createProject(projectDir, projName,
077: mainClass, null, null);
078: assertNotNull(Utilities.openProject(projectDir));
079: }
080:
081: // public void testCloseProject_API_1() throws Exception {
082: // assertTrue(Utilities.closeProject(projName1));
083: // }
084: //
085:
086: public void testReopenAndCloseProject_API_1() throws Exception {
087: String projName = "testCreateAndOpenProject_API_1";
088: String mainClass = "MyMain" + projName; // NOI18N
089: File projectDir = new File(getWorkDir(), projName);
090: projectDir.mkdir();
091: J2SEProjectGenerator.createProject(projectDir, projName,
092: mainClass, null, null);
093: Utilities.openProject(projectDir);
094: assertNotNull(Utilities.closeProject(projName));
095: }
096:
097: // public void testReopenAndDeleteProjectFolder_API_1() throws Exception {
098: // String mainClass = "MyMain" + projName1; // NOI18N
099: // File projectDir = new File(getWorkDir(), projName1);
100: // projectDir.mkdir();
101: // AntProjectHelper project = org.netbeans.modules.java.j2seproject.J2SEProjectGenerator.createProject(projectDir, projName1, mainClass, null);
102: // Utilities.waitScanFinished();
103: // Utilities.openProject(projectDir);
104: // assertTrue(Utilities.deleteProjectFolder(project.getProjectDirectory().getPath()));
105: // }
106:
107: public void testCreateAndOpenProject_API_2() throws Exception {
108: File projectDir = createProject("testCreateAndOpenProject_API_2");
109: assertNotNull(Utilities.openProject(projectDir));
110: }
111:
112: public File createProject(String prjName) throws IOException {
113: File projectDir = new File(getWorkDir(), prjName);
114: projectDir.mkdir();
115:
116: File[] sourceFolders = new File[2];
117: File src1 = new File(projectDir, "src1");
118: src1.mkdirs();
119: File src2 = new File(projectDir, "src2");
120: src2.mkdirs();
121: sourceFolders[0] = src1;
122: sourceFolders[1] = src2;
123:
124: File[] testFolders = new File[2];
125: File test1 = new File(projectDir, "test1");
126: test1.mkdirs();
127: File test2 = new File(projectDir, "test2");
128: test2.mkdirs();
129: testFolders[0] = test1;
130: testFolders[1] = test2;
131: J2SEProjectGenerator.createProject(projectDir, prjName,
132: sourceFolders, testFolders, null, null);
133: return projectDir;
134: }
135:
136: public void testCloseProject_API_2() throws Exception {
137: String prjName = "testCloseProject_API_2";
138: File f = createProject(prjName);
139: assertTrue("File is folder", f.isDirectory());
140: Utilities.openProject(f);
141:
142: assertTrue(Utilities.closeProject(prjName));
143: }
144:
145: public void testReopenAndCloseProject_API_2() throws Exception {
146: String prjName = "testReopenAndCloseProject_API_2";
147: File projectDir = new File(getWorkDir(), prjName);
148: projectDir.mkdir();
149:
150: File[] sourceFolders = new File[2];
151: File src1 = new File(projectDir, "src1");
152: src1.mkdirs();
153: File src2 = new File(projectDir, "src2");
154: src2.mkdirs();
155: sourceFolders[0] = src1;
156: sourceFolders[1] = src2;
157:
158: File[] testFolders = new File[2];
159: File test1 = new File(projectDir, "test1");
160: test1.mkdirs();
161: File test2 = new File(projectDir, "test2");
162: test2.mkdirs();
163: testFolders[0] = test1;
164: testFolders[1] = test2;
165:
166: J2SEProjectGenerator.createProject(projectDir, prjName,
167: sourceFolders, testFolders, null, null);
168: Utilities.openProject(projectDir);
169: assertTrue(Utilities.closeProject(prjName));
170:
171: }
172: // public void testReopenAndDeleteProjectFolder_API_2() throws Exception {
173: // File projectDir = new File(getWorkDir(), projName2);
174: // projectDir.mkdir();
175: //
176: // File[] sourceFolders = new File[2];
177: // File src1 = new File(projectDir, "src1");
178: // src1.mkdirs();
179: // File src2 = new File(projectDir, "src2");
180: // src2.mkdirs();
181: // sourceFolders[0] = src1;
182: // sourceFolders[1] = src2;
183: //
184: // File[] testFolders = new File[2];
185: // File test1 = new File(projectDir, "test1");
186: // test1.mkdirs();
187: // File test2 = new File(projectDir, "test2");
188: // test2.mkdirs();
189: // testFolders[0] = test1;
190: // testFolders[1] = test2;
191: //
192: // AntProjectHelper project = org.netbeans.modules.java.j2seproject.J2SEProjectGenerator.createProject(projectDir, projName2, sourceFolders, testFolders, null);
193: // Utilities.waitScanFinished();
194: // Utilities.openProject(projectDir);
195: // assertTrue(Utilities.deleteProjectFolder(project.getProjectDirectory().getPath()));
196: // }
197: }
|