1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.util.Arrays ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.modules.apisupport.project.InstalledFileLocatorImpl; 26 import org.netbeans.modules.apisupport.project.NbModuleProject; 27 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider; 28 import org.netbeans.modules.apisupport.project.TestBase; 29 import org.netbeans.modules.apisupport.project.Util; 30 import org.netbeans.modules.apisupport.project.layers.LayerTestBase; 31 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 32 import org.netbeans.modules.apisupport.project.suite.SuiteProjectTest; 33 import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils; 34 import org.netbeans.spi.project.ActionProvider; 35 import org.netbeans.spi.project.support.ProjectOperations; 36 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 37 import org.openide.filesystems.FileObject; 38 import org.openide.filesystems.FileUtil; 39 40 45 public class SuiteOperationsTest extends TestBase { 46 47 static { 48 System.setProperty("org.netbeans.core.startup.ModuleSystem.CULPRIT", "true"); 50 LayerTestBase.Lkp.setLookup(new Object [0]); 51 } 52 53 public SuiteOperationsTest(String name) { 54 super(name); 55 } 56 57 protected void setUp() throws Exception { 58 super.setUp(); 59 InstalledFileLocatorImpl.registerDestDir(destDirF); 60 } 61 62 public void testDeleteOfEmptySuite() throws Exception { 63 SuiteProject suite = generateSuite("suite"); 64 SuiteProjectTest.openSuite(suite); 65 SuiteActions ap = (SuiteActions) suite.getLookup().lookup(ActionProvider.class); 66 assertNotNull("have an action provider", ap); 67 assertTrue("delete action is enabled", ap.isActionEnabled(ActionProvider.COMMAND_DELETE, null)); 68 69 FileObject prjDir = suite.getProjectDirectory(); 70 71 ap.invokeActionImpl(ActionProvider.COMMAND_BUILD, suite.getLookup()).waitFinished(); 73 assertNotNull("suite was build", prjDir.getFileObject("build")); 74 75 FileObject[] expectedMetadataFiles = new FileObject[] { 76 prjDir.getFileObject(GeneratedFilesHelper.BUILD_XML_PATH), 77 prjDir.getFileObject("nbproject"), 78 }; 79 assertEquals("correct metadata files", Arrays.asList(expectedMetadataFiles), ProjectOperations.getMetadataFiles(suite)); 80 assertTrue("no data files", ProjectOperations.getDataFiles(suite).isEmpty()); 81 82 ProjectOperations.notifyDeleting(suite); 84 prjDir.getFileSystem().refresh(true); 85 assertNull(prjDir.getFileObject("build")); 86 } 87 88 public void testDeleteOfNonEmptySuite() throws Exception { 89 SuiteProject suite = generateSuite("suite"); 90 FileObject prjDir = suite.getProjectDirectory(); 91 prjDir.createFolder("branding"); 92 NbModuleProject module1 = TestBase.generateSuiteComponent(suite, "module1"); 93 NbModuleProject module2 = TestBase.generateSuiteComponent(suite, "module2"); 94 assertEquals("module1 is suite component", NbModuleProvider.SUITE_COMPONENT, Util.getModuleType(module1)); 95 assertEquals("module2 is suite component", NbModuleProvider.SUITE_COMPONENT, Util.getModuleType(module2)); 96 module1.open(); 97 module2.open(); 98 99 SuiteProjectTest.openSuite(suite); 100 SuiteActions ap = (SuiteActions) suite.getLookup().lookup(ActionProvider.class); 101 assertNotNull("have an action provider", ap); 102 assertTrue("delete action is enabled", ap.isActionEnabled(ActionProvider.COMMAND_DELETE, null)); 103 104 105 ap.invokeActionImpl(ActionProvider.COMMAND_BUILD, suite.getLookup()).waitFinished(); 107 assertNotNull("suite was build", prjDir.getFileObject("build")); 108 109 FileObject[] expectedMetadataFiles = new FileObject[] { 110 prjDir.getFileObject(GeneratedFilesHelper.BUILD_XML_PATH), 111 prjDir.getFileObject("nbproject"), 112 }; 113 assertEquals("correct metadata files", Arrays.asList(expectedMetadataFiles), ProjectOperations.getMetadataFiles(suite)); 114 FileObject[] expectedDataFiles = new FileObject[] { 115 prjDir.getFileObject("branding"), 116 }; 117 assertEquals("correct data files", Arrays.asList(expectedDataFiles), ProjectOperations.getDataFiles(suite)); 118 119 ProjectOperations.notifyDeleting(suite); 121 prjDir.getFileSystem().refresh(true); 122 assertNull(prjDir.getFileObject("build")); 123 124 assertEquals("module1 became standalone module", NbModuleProvider.STANDALONE, Util.getModuleType(module1)); 125 assertEquals("module2 became standalone module", NbModuleProvider.STANDALONE, Util.getModuleType(module2)); 126 } 127 128 public void testMoveModule() throws Exception { 129 SuiteProject suite = generateSuite("suite"); 130 NbModuleProject outer = generateSuiteComponent(suite, getWorkDir(), "outer"); 131 outer.open(); 132 NbModuleProject customOuter = generateSuiteComponent(suite, getWorkDir(), "customOuter"); 133 FileUtil.createData(customOuter.getProjectDirectory(), "mydocs/index.html"); 134 customOuter.open(); 135 136 Project inner = SuiteOperations.moveModule(outer, suite.getProjectDirectory()); 137 assertNotNull("inner successfully moved", inner); 138 assertSame("inner is still in the same suite component", suite, SuiteUtils.findSuite(inner)); 139 assertFalse(ProjectManager.getDefault().isValid(outer)); 140 assertFalse(outer.getProjectDirectory().isValid()); 141 142 Project customInner = SuiteOperations.moveModule(customOuter, suite.getProjectDirectory()); 143 assertNotNull("customInner successfully moved", customInner); 144 assertSame("customInner is still in the same suite component", suite, SuiteUtils.findSuite(customInner)); 145 assertFalse(ProjectManager.getDefault().isValid(customOuter)); 146 assertFalse("customOuter directory is not valid anymore", customOuter.getProjectDirectory().isValid()); 147 FileObject mydocsIndex = customInner.getProjectDirectory().getFileObject("mydocs/index.html"); 148 assertNotNull("mydocs was also moved", mydocsIndex); 149 assertTrue("mydocs is valid", mydocsIndex.isValid()); 150 } 151 152 } 153 | Popular Tags |