KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > freeform > ui > BasicProjectInfoPanelTest


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.ant.freeform.ui;
21
22 import java.io.IOException JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24 import java.io.File JavaDoc;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.api.project.ProjectManager;
27 import org.netbeans.modules.ant.freeform.TestBase;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  * @author Jan Lahoda
35  */

36 public class BasicProjectInfoPanelTest extends TestBase {
37
38     private File JavaDoc outterProjectDir;
39     private FileObject outterProjectDirFO;
40     private Project outterProject;
41     private File JavaDoc innerProjectDir;
42     private File JavaDoc innerAntScript;
43     private File JavaDoc simple3Dir;
44     private File JavaDoc simple3AntScript;
45     private File JavaDoc outterProjectNBProjectDir;
46         
47     public BasicProjectInfoPanelTest(String JavaDoc testName) {
48         super(testName);
49     }
50
51     protected void setUp() throws Exception JavaDoc {
52         super.setUp();
53         File JavaDoc outterProjectDirOriginal = FileUtil.normalizeFile(new File JavaDoc(egdir, "freeforminside"));
54         File JavaDoc simple3DirOriginal = FileUtil.normalizeFile(new File JavaDoc(egdir, "simple3"));
55         
56         assertTrue("freeforminside directory (" + outterProjectDirOriginal + ") exists", outterProjectDirOriginal.exists());
57         assertTrue("simple3 directory (" + simple3DirOriginal + ") exists", simple3DirOriginal.exists());
58         
59         outterProjectDir = copyFolder(outterProjectDirOriginal);
60         simple3Dir = copyFolder(simple3DirOriginal);
61         
62         assertTrue("freeforminside directory copy exists", outterProjectDir.exists());
63         assertTrue("simple3 directory copy exists", simple3Dir.exists());
64         
65         outterProjectDirFO = FileUtil.toFileObject(outterProjectDir);
66         assertNotNull("have FileObject for " + outterProjectDir, outterProjectDirFO);
67         outterProject = ProjectManager.getDefault().findProject(outterProjectDirFO);
68         assertNotNull("have a project", outterProject);
69         outterProjectNBProjectDir = FileUtil.normalizeFile(new File JavaDoc(outterProjectDir, "nbproject"));
70         assertNotNull("found nbproject directory", outterProjectNBProjectDir);
71         innerProjectDir = FileUtil.normalizeFile(new File JavaDoc(outterProjectDir, "FreeForm"));
72         assertTrue("inner directory (" + innerProjectDir + ") exists", innerProjectDir.exists());
73         innerAntScript = FileUtil.normalizeFile(new File JavaDoc(innerProjectDir, "build.xml"));
74         assertTrue("inner ant script (" + innerAntScript + ") exists", innerAntScript.exists());
75         simple3AntScript = FileUtil.normalizeFile(new File JavaDoc(simple3Dir, "build.xml"));
76         assertTrue("simple3 ant script (" + simple3AntScript + ") exists", simple3AntScript.exists());
77     }
78
79     private boolean deepDelete(File JavaDoc f) throws IOException JavaDoc {
80         if (f.isDirectory()) {
81             File JavaDoc[] 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 JavaDoc {
97         BasicProjectInfoPanel panel;
98         String JavaDoc 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(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"),
110                 new Object JavaDoc[] {"Simple Freeform Project"});
111                 
112         assertEquals("do not allow creation (#55533)", error, panel.getError());
113     }
114     
115     public void testGetError2() throws Exception JavaDoc {
116         BasicProjectInfoPanel panel;
117         String JavaDoc 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(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"),
129                 new Object JavaDoc[] {"Simple Freeform Project"});
130                 
131         assertEquals("do not allow creation (#55533)", error, panel.getError());
132     }
133     
134     public void testGetError3() throws Exception JavaDoc {
135         BasicProjectInfoPanel panel;
136         String JavaDoc 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(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_10"),
148                 new Object JavaDoc[] {"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 }
158
Popular Tags