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-2006 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 org.netbeans.modules.ant.freeform.ui;
043:
044: import java.io.IOException;
045: import java.text.MessageFormat;
046: import java.io.File;
047: import org.netbeans.api.project.Project;
048: import org.netbeans.api.project.ProjectManager;
049: import org.netbeans.modules.ant.freeform.TestBase;
050: import org.openide.filesystems.FileObject;
051: import org.openide.filesystems.FileUtil;
052: import org.openide.util.NbBundle;
053:
054: /**
055: *
056: * @author Jan Lahoda
057: */
058: public class BasicProjectInfoPanelTest extends TestBase {
059:
060: private File outterProjectDir;
061: private FileObject outterProjectDirFO;
062: private Project outterProject;
063: private File innerProjectDir;
064: private File innerAntScript;
065: private File simple3Dir;
066: private File simple3AntScript;
067: private File outterProjectNBProjectDir;
068:
069: public BasicProjectInfoPanelTest(String testName) {
070: super (testName);
071: }
072:
073: protected void setUp() throws Exception {
074: super .setUp();
075: File outterProjectDirOriginal = FileUtil
076: .normalizeFile(new File(egdir, "freeforminside"));
077: File simple3DirOriginal = FileUtil.normalizeFile(new File(
078: egdir, "simple3"));
079:
080: assertTrue("freeforminside directory ("
081: + outterProjectDirOriginal + ") exists",
082: outterProjectDirOriginal.exists());
083: assertTrue("simple3 directory (" + simple3DirOriginal
084: + ") exists", simple3DirOriginal.exists());
085:
086: outterProjectDir = copyFolder(outterProjectDirOriginal);
087: simple3Dir = copyFolder(simple3DirOriginal);
088:
089: assertTrue("freeforminside directory copy exists",
090: outterProjectDir.exists());
091: assertTrue("simple3 directory copy exists", simple3Dir.exists());
092:
093: outterProjectDirFO = FileUtil.toFileObject(outterProjectDir);
094: assertNotNull("have FileObject for " + outterProjectDir,
095: outterProjectDirFO);
096: outterProject = ProjectManager.getDefault().findProject(
097: outterProjectDirFO);
098: assertNotNull("have a project", outterProject);
099: outterProjectNBProjectDir = FileUtil.normalizeFile(new File(
100: outterProjectDir, "nbproject"));
101: assertNotNull("found nbproject directory",
102: outterProjectNBProjectDir);
103: innerProjectDir = FileUtil.normalizeFile(new File(
104: outterProjectDir, "FreeForm"));
105: assertTrue("inner directory (" + innerProjectDir + ") exists",
106: innerProjectDir.exists());
107: innerAntScript = FileUtil.normalizeFile(new File(
108: innerProjectDir, "build.xml"));
109: assertTrue("inner ant script (" + innerAntScript + ") exists",
110: innerAntScript.exists());
111: simple3AntScript = FileUtil.normalizeFile(new File(simple3Dir,
112: "build.xml"));
113: assertTrue("simple3 ant script (" + simple3AntScript
114: + ") exists", simple3AntScript.exists());
115: }
116:
117: private boolean deepDelete(File f) throws IOException {
118: if (f.isDirectory()) {
119: File[] children = f.listFiles();
120:
121: for (int cntr = 0; cntr < children.length; cntr++) {
122: if (!deepDelete(children[cntr]))
123: return false;
124: }
125: }
126:
127: return f.delete();
128: }
129:
130: /**The BasicProjectInfoPanel should allow creation of a freeform project in the directory hierarchy under
131: * another project, but should refuse to create a project in place of another (loaded, but deleted)
132: * project. See issues #58467 and #55533.
133: */
134: public void testGetError1() throws Exception {
135: BasicProjectInfoPanel panel;
136: String error;
137:
138: panel = new BasicProjectInfoPanel(innerProjectDir
139: .getAbsolutePath(), innerAntScript.getAbsolutePath(),
140: "NAME", innerProjectDir.getAbsolutePath(), null);
141:
142: assertNull("allow creation (#58467)", panel.getError());
143:
144: //delete the outter/nbproject directory and try to create a new project here:
145: assertTrue("nbproject deleted succesfully",
146: deepDelete(outterProjectNBProjectDir));
147:
148: panel = new BasicProjectInfoPanel(outterProjectDir
149: .getAbsolutePath(), innerAntScript.getAbsolutePath(),
150: "NAME", outterProjectDir.getAbsolutePath(), null);
151:
152: error = MessageFormat.format(NbBundle.getMessage(
153: BasicProjectInfoPanel.class,
154: "LBL_BasicProjectInfoPanel_Error_9"),
155: new Object[] { "Simple Freeform Project" });
156:
157: assertEquals("do not allow creation (#55533)", error, panel
158: .getError());
159: }
160:
161: public void testGetError2() throws Exception {
162: BasicProjectInfoPanel panel;
163: String error;
164:
165: panel = new BasicProjectInfoPanel(simple3Dir.getAbsolutePath(),
166: simple3AntScript.getAbsolutePath(), "NAME",
167: innerProjectDir.getAbsolutePath(), null);
168:
169: assertNull("allow creation (#58467)", panel.getError());
170:
171: //delete the outter/nbproject directory and try to create a new project here:
172: assertTrue("nbproject deleted succesfully",
173: deepDelete(outterProjectNBProjectDir));
174:
175: panel = new BasicProjectInfoPanel(simple3Dir.getAbsolutePath(),
176: simple3AntScript.getAbsolutePath(), "NAME",
177: outterProjectDir.getAbsolutePath(), null);
178:
179: error = MessageFormat.format(NbBundle.getMessage(
180: BasicProjectInfoPanel.class,
181: "LBL_BasicProjectInfoPanel_Error_9"),
182: new Object[] { "Simple Freeform Project" });
183:
184: assertEquals("do not allow creation (#55533)", error, panel
185: .getError());
186: }
187:
188: public void testGetError3() throws Exception {
189: BasicProjectInfoPanel panel;
190: String error;
191:
192: panel = new BasicProjectInfoPanel(innerProjectDir
193: .getAbsolutePath(), innerAntScript.getAbsolutePath(),
194: "NAME", simple3Dir.getAbsolutePath(), null);
195:
196: assertNull("allow creation (#58467)", panel.getError());
197:
198: //delete the outter/nbproject directory and try to create a new project here:
199: assertTrue("nbproject deleted succesfully",
200: deepDelete(outterProjectNBProjectDir));
201:
202: panel = new BasicProjectInfoPanel(outterProjectDir
203: .getAbsolutePath(), innerAntScript.getAbsolutePath(),
204: "NAME", simple3Dir.getAbsolutePath(), null);
205:
206: error = MessageFormat.format(NbBundle.getMessage(
207: BasicProjectInfoPanel.class,
208: "LBL_BasicProjectInfoPanel_Error_10"),
209: new Object[] { "Simple Freeform Project" });
210:
211: assertEquals("do not allow creation (#55533)", error, panel
212: .getError());
213: }
214:
215: protected boolean runInEQ() {
216: return true;
217: }
218:
219: }
|