1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.util.Arrays ; 23 import java.util.HashSet ; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.modules.apisupport.project.TestBase; 26 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 27 import org.netbeans.spi.project.ui.support.ProjectCustomizer; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.nodes.Node; 31 32 36 public class SuiteCustomizerModuleListTest extends TestBase { 37 38 private FileObject suiteRepoFO; 39 private SuiteProject suite1Prj; 40 private SuiteProperties suite1Props; 41 private FileObject suite1FO; 42 43 private SuiteCustomizerLibraries customizer; 44 45 public SuiteCustomizerModuleListTest(String testName) { 46 super(testName); 47 } 48 49 protected void setUp() throws Exception { 50 super.setUp(); 51 suiteRepoFO = FileUtil.toFileObject(copyFolder(resolveEEPFile("."))); 52 suite1FO = suiteRepoFO.getFileObject("suite1"); 53 suite1Prj = (SuiteProject) ProjectManager.getDefault().findProject(suite1FO); 54 this.suite1Props = new SuiteProperties(suite1Prj, suite1Prj.getHelper(), 55 suite1Prj.getEvaluator(), SuiteUtils.getSubProjects(suite1Prj)); 56 57 customizer = new SuiteCustomizerLibraries(this.suite1Props, ProjectCustomizer.Category.create("x", "xx", null)); 58 } 59 60 public void testDisableCluster() throws Exception { 61 enableAllClusters(false); 62 doDisableCluster(0, true); 63 } 64 65 public void testDisableCluster2() throws Exception { 66 enableAllClusters(false); 67 doDisableCluster(1, true); 68 } 69 70 public void testDisableTwoClusters() throws Exception { 71 enableAllClusters(false); 72 73 String c1 = doDisableCluster(1, true); 74 String c2 = doDisableCluster(2, false); 75 HashSet c = new HashSet (); 76 c.add(c1); 77 c.add(c2); 78 79 String [] xyz = suite1Props.getEnabledClusters(); 80 82 HashSet real = new HashSet (Arrays.asList(xyz)); 83 assertFalse(real.containsAll(c)); 84 } 85 86 private String doDisableCluster(int index, boolean doCheck) throws Exception { 87 Node n = customizer.getExplorerManager().getRootContext(); 88 Node[] clusters = n.getChildren().getNodes(); 89 if (clusters.length <= index) { 90 fail ("Wrong, there should be some clusters. at least: " + index + " and was: " + clusters.length); 91 } 92 Node[] modules = clusters[index].getChildren().getNodes(); 93 if (modules.length == 0) { 94 fail("Expected more modules for cluster: " + clusters[index]); 95 } 96 97 setNodeEnabled(clusters[index], false); 98 assertEquals("No modules in disabled clusters", 99 clusters[index].getChildren().getNodes().length, modules.length); 100 101 customizer.store(); 102 suite1Props.storeProperties(); 103 104 if (doCheck) { 105 String [] xyz = suite1Props.getEnabledClusters(); 106 assertFalse("It's name is name of the node", Arrays.asList(xyz).contains(clusters[index].getName())); 108 } 109 110 return clusters[index].getName(); 111 } 112 113 public void testDisableModule() throws Exception { 114 enableAllClusters(true); 115 116 Node n = customizer.getExplorerManager().getRootContext(); 117 Node[] clusters = n.getChildren().getNodes(); 118 if (clusters.length == 0) { 119 fail("Should be at least one cluster"); 120 } 121 Node[] modules = clusters[0].getChildren().getNodes(); 122 if (modules.length == 0) { 123 fail("Expected at least one module in cluster: " + clusters[0]); 124 } 125 126 setNodeEnabled(modules[0], false); 127 assertNodeEnabled(modules[0], Boolean.FALSE); 128 129 customizer.store(); 130 suite1Props.storeProperties(); 131 132 String [] xyz = suite1Props.getDisabledModules(); 133 assertEquals("One module is disabled", 1, xyz.length); 134 assertEquals("It's name is name of the node", modules[0].getName(), xyz[0]); 135 } 136 137 private static void assertNodeEnabled(Node n, Boolean value) throws Exception { 138 org.openide.nodes.Node.PropertySet[] arr = n.getPropertySets(); 139 for (int i = 0; i < arr.length; i++) { 140 org.openide.nodes.Node.Property[] x = arr[i].getProperties(); 141 for (int j = 0; j < x.length; j++) { 142 if (x[j].getName().equals("enabled")) { 143 Object o = x[j].getValue(); 144 assertEquals("Node is correctly enabled/disabled: " + n, value, o); 145 return; 146 } 147 } 148 } 149 fail("No enabled property found: " + n); 150 } 151 private static void setNodeEnabled(Node n, boolean value) throws Exception { 152 org.openide.nodes.Node.PropertySet[] arr = n.getPropertySets(); 153 for (int i = 0; i < arr.length; i++) { 154 org.openide.nodes.Node.Property[] x = arr[i].getProperties(); 155 for (int j = 0; j < x.length; j++) { 156 if (x[j].getName().equals("enabled")) { 157 x[j].setValue(Boolean.valueOf(value)); 158 return; 159 } 160 } 161 } 162 fail("No enabled property found: " + n); 163 } 164 165 private void enableAllClusters(boolean enableModulesAsWell) throws Exception { 166 Node n = customizer.getExplorerManager().getRootContext(); 167 Node[] clusters = n.getChildren().getNodes(); 168 169 for (int i = 0; i < clusters.length; i++) { 170 setNodeEnabled(clusters[i], true); 171 if (enableModulesAsWell) { 172 Node[] modules = clusters[i].getChildren().getNodes(); 173 for (int j = 0; j < modules.length; j++) { 174 setNodeEnabled(modules[j], true); 175 } 176 } 177 } 178 } 179 } 180 | Popular Tags |