1 19 20 package org.netbeans.modules.ant.freeform.ui; 21 22 import java.io.IOException ; 23 import java.text.MessageFormat ; 24 import java.io.File ; 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 36 public class BasicProjectInfoPanelTest extends TestBase { 37 38 private File outterProjectDir; 39 private FileObject outterProjectDirFO; 40 private Project outterProject; 41 private File innerProjectDir; 42 private File innerAntScript; 43 private File simple3Dir; 44 private File simple3AntScript; 45 private File outterProjectNBProjectDir; 46 47 public BasicProjectInfoPanelTest(String testName) { 48 super(testName); 49 } 50 51 protected void setUp() throws Exception { 52 super.setUp(); 53 File outterProjectDirOriginal = FileUtil.normalizeFile(new File (egdir, "freeforminside")); 54 File simple3DirOriginal = FileUtil.normalizeFile(new File (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 (outterProjectDir, "nbproject")); 70 assertNotNull("found nbproject directory", outterProjectNBProjectDir); 71 innerProjectDir = FileUtil.normalizeFile(new File (outterProjectDir, "FreeForm")); 72 assertTrue("inner directory (" + innerProjectDir + ") exists", innerProjectDir.exists()); 73 innerAntScript = FileUtil.normalizeFile(new File (innerProjectDir, "build.xml")); 74 assertTrue("inner ant script (" + innerAntScript + ") exists", innerAntScript.exists()); 75 simple3AntScript = FileUtil.normalizeFile(new File (simple3Dir, "build.xml")); 76 assertTrue("simple3 ant script (" + simple3AntScript + ") exists", simple3AntScript.exists()); 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 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 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 [] {"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 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 [] {"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 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 [] {"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 |