1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.io.File ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.modules.apisupport.project.NbModuleProject; 26 import org.netbeans.modules.apisupport.project.ProjectXMLManager; 27 import org.netbeans.modules.apisupport.project.SuiteProvider; 28 import org.netbeans.modules.apisupport.project.TestBase; 29 import org.netbeans.modules.apisupport.project.Util; 30 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 31 import org.netbeans.spi.project.SubprojectProvider; 32 import org.netbeans.spi.project.support.ant.EditableProperties; 33 import org.openide.filesystems.FileObject; 34 import org.openide.loaders.DataFolder; 35 36 41 public class SuiteUtilsTest extends TestBase { 42 43 public SuiteUtilsTest(String name) { 44 super(name); 45 } 46 47 public void testAddModule() throws Exception { 48 SuiteProject suite1 = generateSuite("suite1"); 49 NbModuleProject module1 = generateStandaloneModule("module1"); 50 SuiteProvider suiteProvider = (SuiteProvider) module1.getLookup().lookup(SuiteProvider.class); 51 assertNull("module1 is standalone module - doesn't have valid SuiteProvider", suiteProvider.getSuiteDirectory()); 52 53 SuiteUtils.addModule(suite1, module1); 54 SubprojectProvider spp = SuitePropertiesTest.getSubProjectProvider(suite1); 55 assertEquals("one module suite component", 1, spp.getSubprojects().size()); 56 suiteProvider = (SuiteProvider) module1.getLookup().lookup(SuiteProvider.class); 57 assertNotNull("module1 became suite component - has valid SuiteProvider", suiteProvider.getSuiteDirectory()); 58 59 NbModuleProject module2 = generateStandaloneModule("module2"); 60 NbModuleProject module3 = generateStandaloneModule("module3"); 61 SuiteUtils.addModule(suite1, module2); 62 SuiteUtils.addModule(suite1, module3); 63 64 assertEquals("three module suite components", 3, spp.getSubprojects().size()); 65 } 66 67 public void testRemoveModuleFromSuite() throws Exception { 68 SuiteProject suite1 = generateSuite("suite1"); 69 NbModuleProject module1 = TestBase.generateSuiteComponent(suite1, "module1"); 70 SubprojectProvider spp = SuitePropertiesTest.getSubProjectProvider(suite1); 71 assertEquals("one module suite component", 1, spp.getSubprojects().size()); 72 73 SuiteProvider suiteProvider = (SuiteProvider) module1.getLookup().lookup(SuiteProvider.class); 74 assertNotNull("module1 is suite component - has valid SuiteProvider", suiteProvider.getSuiteDirectory()); 75 76 assertNull("user.properites.file property doesn't exist", module1.evaluator().getProperty("user.properties.file")); 77 SuiteUtils.removeModuleFromSuite(module1); 78 assertEquals("user.properties.file resolved for standalone module", 79 getWorkDirPath() + File.separatorChar + "build.properties", 80 module1.evaluator().getProperty("user.properties.file")); 81 spp = SuitePropertiesTest.getSubProjectProvider(suite1); 82 assertEquals("doesn't have suite component", 0, spp.getSubprojects().size()); 83 suiteProvider = (SuiteProvider) module1.getLookup().lookup(SuiteProvider.class); 84 assertNull("module1 became standalone module - doesn't have valid SuiteProvider", suiteProvider.getSuiteDirectory()); 85 } 86 87 public void testRemoveModuleFromSuiteWithDependencies() throws Exception { 88 SuiteProject suite1 = generateSuite("suite1"); 89 NbModuleProject module1 = TestBase.generateSuiteComponent(suite1, "module1"); 90 NbModuleProject module2 = TestBase.generateSuiteComponent(suite1, "module2"); 91 92 SubprojectProvider spp = SuitePropertiesTest.getSubProjectProvider(suite1); 93 assertEquals("two suite components", 2, spp.getSubprojects().size()); 94 95 Util.addDependency(module2, module1); 96 ProjectManager.getDefault().saveProject(module2); 97 ProjectXMLManager pxm2 = new ProjectXMLManager(module2); 98 assertEquals("one dependency", 1, pxm2.getDirectDependencies().size()); 99 100 SuiteUtils.removeModuleFromSuiteWithDependencies(module1); 101 spp = SuitePropertiesTest.getSubProjectProvider(suite1); 102 assertEquals("one suite component", 1, spp.getSubprojects().size()); 103 SuiteProvider suiteProvider = (SuiteProvider) module1.getLookup().lookup(SuiteProvider.class); 104 assertNull("module1 became standalone module - doesn't have valid SuiteProvider", suiteProvider.getSuiteDirectory()); 105 106 pxm2 = new ProjectXMLManager(module2); 107 assertEquals("dependency was removed", 0, pxm2.getDirectDependencies().size()); 108 } 109 110 111 public void testPreventDeadLockWhenAddThenRemoveModule_64582() throws Exception { 112 SuiteProject suite1 = generateSuite("suite1"); 113 NbModuleProject module1 = TestBase.generateStandaloneModule(getWorkDir(), "module1"); 114 SuiteUtils.addModule(suite1, module1); 115 SuiteUtils.removeModuleFromSuite(module1); 116 } 117 118 public void testAddTwoModulesWithTheSameCNB_62819() throws Exception { 119 SuiteProject suite1 = generateSuite("suite1"); 120 NbModuleProject module1a = generateStandaloneModule("module1"); 121 File otherDir = new File (getWorkDir(), "otherDir"); 122 otherDir.mkdir(); 123 NbModuleProject module1b = TestBase.generateStandaloneModule(otherDir, "module1"); 124 125 SuiteUtils.addModule(suite1, module1a); 126 SuiteUtils.addModule(suite1, module1b); 127 SubprojectProvider spp = SuitePropertiesTest.getSubProjectProvider(suite1); 128 assertEquals("cannot add two suite components with the same cnb", 1, spp.getSubprojects().size()); 129 130 SuiteProvider suiteProvider = (SuiteProvider) module1a.getLookup().lookup(SuiteProvider.class); 131 assertNotNull("module1a became suite component - has valid SuiteProvider", suiteProvider.getSuiteDirectory()); 132 suiteProvider = (SuiteProvider) module1b.getLookup().lookup(SuiteProvider.class); 133 assertNull("module1b remains standalone - has not valid SuiteProvider", suiteProvider.getSuiteDirectory()); 134 } 135 136 public void testGeneratingOfUniqAntProperty_62819() throws Exception { 137 SuiteProject suite1 = generateSuite("suite1"); 138 NbModuleProject module1 = generateStandaloneModule("module1"); 139 NbModuleProject module2 = generateStandaloneModule("module2"); 140 141 SuiteUtils.addModule(suite1, module1); 142 FileObject propsFO = suite1.getProjectDirectory().getFileObject("nbproject/project.properties"); 143 EditableProperties props = Util.loadProperties(propsFO); 144 assertEquals("modules property", "${project.org.example.module1}", props.getProperty("modules")); 145 assertEquals("module1 property", "../module1", props.getProperty("project.org.example.module1")); 146 147 assertEquals("module1 project removed (sanity check)", "../module1", props.remove("project.org.example.module1")); 149 props.setProperty("modules", "${project.org.example.module2}"); 150 props.setProperty("project.org.example.module2", "../module1"); 151 Util.storeProperties(propsFO, props); 152 153 SuiteUtils.addModule(suite1, module2); 154 SubprojectProvider spp = SuitePropertiesTest.getSubProjectProvider(suite1); 155 assertEquals("one module suite component", 2, spp.getSubprojects().size()); 156 157 SuiteProvider suiteProvider = (SuiteProvider) module1.getLookup().lookup(SuiteProvider.class); 158 assertNotNull("module1 became suite component - has valid SuiteProvider", suiteProvider.getSuiteDirectory()); 159 suiteProvider = (SuiteProvider) module2.getLookup().lookup(SuiteProvider.class); 160 assertNotNull("module2 became suite component - has valid SuiteProvider", suiteProvider.getSuiteDirectory()); 161 } 162 163 public void testIsSuite() throws Exception { 164 SuiteProject suite = generateSuite("suite"); 165 generateSuiteComponent(suite, "suiteComponent"); 166 generateStandaloneModuleDirectory(getWorkDir(), "module"); 167 File suiteF = new File (getWorkDir(), "suite"); 168 assertTrue(suite + " is a suite", SuiteUtils.isSuite(suiteF)); 169 assertFalse(suite + " is not a suite", SuiteUtils.isSuite(new File (suiteF, "suiteComponent"))); 170 assertFalse(suite + " is not a suite", SuiteUtils.isSuite(new File (getWorkDir(), "module"))); 171 } 172 173 public void testFindSuiteNotSuiteProject80786() throws Exception { 174 SuiteProject suite = generateSuite("suite"); 176 NbModuleProject module = generateSuiteComponent(suite, "suiteComponent"); 177 FileObject copy = suite.getProjectDirectory().getParent().createFolder("copy"); 178 DataFolder.findFolder(module.getProjectDirectory()).copy(DataFolder.findFolder(copy)); 179 generateStandaloneModuleDirectory(getWorkDir(), "copy"); 180 Project modulecopy = ProjectManager.getDefault().findProject(copy.getFileObject("suiteComponent")); 181 assertNotNull(modulecopy); 182 assertNull(SuiteUtils.findSuite(modulecopy)); 183 } 184 185 } 186 187 | Popular Tags |