Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
package org.netbeans.modules.ant.freeform.ui; |
15 |
|
16 |
import java.io.IOException; |
17 |
import java.text.MessageFormat; |
18 |
import junit.framework.*; |
19 |
import java.io.File; |
20 |
import org.netbeans.api.project.Project; |
21 |
import org.netbeans.api.project.ProjectManager; |
22 |
import org.netbeans.modules.ant.freeform.TestBase; |
23 |
import org.openide.filesystems.FileObject; |
24 |
import org.openide.filesystems.FileUtil; |
25 |
|
26 |
/** |
27 |
* |
28 |
* @author Jan Lahoda |
29 |
*/ |
30 |
public class BasicProjectInfoPanelTest extends TestBase { |
31 |
|
32 |
private File outterProjectDir; |
33 |
private FileObject outterProjectDirFO; |
34 |
private Project outterProject; |
35 |
private File innerProjectDir; |
36 |
private File innerAntScript; |
37 |
private File simple3Dir; |
38 |
private File simple3AntScript; |
39 |
private File outterProjectNBProjectDir; |
40 |
|
41 |
public BasicProjectInfoPanelTest(String testName) { |
42 |
super(testName); |
43 |
} |
44 |
|
45 |
protected void setUp() throws Exception { |
46 |
super.setUp(); |
47 |
File outterProjectDirOriginal = FileUtil.normalizeFile(new File(egdir, "freeforminside")); |
48 |
File simple3DirOriginal = FileUtil.normalizeFile(new File(egdir, "simple3")); |
49 |
|
50 |
assertTrue("freeforminside directory (" + outterProjectDirOriginal + ") exists", outterProjectDirOriginal.exists()); |
51 |
assertTrue("simple3 directory (" + simple3DirOriginal + ") exists", simple3DirOriginal.exists()); |
52 |
|
53 |
outterProjectDir = copyFolder(outterProjectDirOriginal); |
54 |
simple3Dir = copyFolder(simple3DirOriginal); |
55 |
|
56 |
assertTrue("freeforminside directory copy exists", outterProjectDir.exists()); |
57 |
assertTrue("simple3 directory copy exists", simple3Dir.exists()); |
58 |
|
59 |
outterProjectDirFO = FileUtil.toFileObject(outterProjectDir); |
60 |
assertNotNull("have FileObject for " + outterProjectDir, outterProjectDirFO); |
61 |
outterProject = ProjectManager.getDefault().findProject(outterProjectDirFO); |
62 |
assertNotNull("have a project", outterProject); |
63 |
outterProjectNBProjectDir = FileUtil.normalizeFile(new File(outterProjectDir, "nbproject")); |
64 |
assertNotNull("found nbproject directory", outterProjectNBProjectDir); |
65 |
innerProjectDir = FileUtil.normalizeFile(new File(outterProjectDir, "FreeForm")); |
66 |
assertTrue("inner directory (" + innerProjectDir + ") exists", innerProjectDir.exists()); |
67 |
innerAntScript = FileUtil.normalizeFile(new File(innerProjectDir, "build.xml")); |
68 |
assertTrue("inner ant script (" + innerAntScript + ") exists", innerAntScript.exists()); |
69 |
simple3AntScript = FileUtil.normalizeFile(new File(simple3Dir, "build.xml")); |
70 |
assertTrue("simple3 ant script (" + simple3AntScript + ") exists", simple3AntScript.exists()); |
71 |
} |
72 |
|
73 |
public static Test suite() { |
74 |
TestSuite suite = new TestSuite(BasicProjectInfoPanelTest.class); |
75 |
|
76 |
return suite; |
77 |
} |
78 |
|
79 |
private boolean deepDelete(File f) throws IOException { |
80 |
if (f.isDirectory()) { |
81 |
File[] children = f.listFiles(); |
82 |
|
83 |
for (int cntr = 0; cntr < children.length; cntr++) { |
84 |
if (!deepDelete(children[cntr])) |
85 |
return false; |
86 |
} |
87 |
} |
88 |
|
89 |
return f.delete(); |
90 |
} |
91 |
|
92 |
/**The BasicProjectInfoPanel should allow creation of a freeform project in the directory hierarchy under |
93 |
* another project, but should refuse to create a project in place of another (loaded, but deleted) |
94 |
* project. See issues #58467 and #55533. |
95 |
*/ |
96 |
public void testGetError1() throws Exception { |
97 |
BasicProjectInfoPanel panel; |
98 |
String error; |
99 |
|
100 |
panel = new BasicProjectInfoPanel(innerProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", innerProjectDir.getAbsolutePath(), null); |
101 |
|
102 |
assertNull("allow creation (#58467)", panel.getError()); |
103 |
|
104 |
//delete the outter/nbproject directory and try to create a new project here: |
105 |
assertTrue("nbproject deleted succesfully", deepDelete(outterProjectNBProjectDir)); |
106 |
|
107 |
panel = new BasicProjectInfoPanel(outterProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", outterProjectDir.getAbsolutePath(), null); |
108 |
|
109 |
error = MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"), |
110 |
new Object[] {"Simple Freeform Project"}); |
111 |
|
112 |
assertEquals("do not allow creation (#55533)", error, panel.getError()); |
113 |
} |
114 |
|
115 |
public void testGetError2() throws Exception { |
116 |
BasicProjectInfoPanel panel; |
117 |
String error; |
118 |
|
119 |
panel = new BasicProjectInfoPanel(simple3Dir.getAbsolutePath(), simple3AntScript.getAbsolutePath(), "NAME", innerProjectDir.getAbsolutePath(), null); |
120 |
|
121 |
assertNull("allow creation (#58467)", panel.getError()); |
122 |
|
123 |
//delete the outter/nbproject directory and try to create a new project here: |
124 |
assertTrue("nbproject deleted succesfully", deepDelete(outterProjectNBProjectDir)); |
125 |
|
126 |
panel = new BasicProjectInfoPanel(simple3Dir.getAbsolutePath(), simple3AntScript.getAbsolutePath(), "NAME", outterProjectDir.getAbsolutePath(), null); |
127 |
|
128 |
error = MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"), |
129 |
new Object[] {"Simple Freeform Project"}); |
130 |
|
131 |
assertEquals("do not allow creation (#55533)", error, panel.getError()); |
132 |
} |
133 |
|
134 |
public void testGetError3() throws Exception { |
135 |
BasicProjectInfoPanel panel; |
136 |
String error; |
137 |
|
138 |
panel = new BasicProjectInfoPanel(innerProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", simple3Dir.getAbsolutePath(), null); |
139 |
|
140 |
assertNull("allow creation (#58467)", panel.getError()); |
141 |
|
142 |
//delete the outter/nbproject directory and try to create a new project here: |
143 |
assertTrue("nbproject deleted succesfully", deepDelete(outterProjectNBProjectDir)); |
144 |
|
145 |
panel = new BasicProjectInfoPanel(outterProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", simple3Dir.getAbsolutePath(), null); |
146 |
|
147 |
error = MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_10"), |
148 |
new Object[] {"Simple Freeform Project"}); |
149 |
|
150 |
assertEquals("do not allow creation (#55533)", error, panel.getError()); |
151 |
} |
152 |
|
153 |
protected boolean runInEQ() { |
154 |
return true; |
155 |
} |
156 |
|
157 |
} |