KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > SuiteUtilsTest


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.apisupport.project.ui.customizer;
21
22 import java.io.File JavaDoc;
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 /**
37  * Tests {@link SuiteUtils}
38  *
39  * @author Martin Krauskopf
40  */

41 public class SuiteUtilsTest extends TestBase {
42     
43     public SuiteUtilsTest(String JavaDoc name) {
44         super(name);
45     }
46     
47     public void testAddModule() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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     /** Simulates scenario when deadlock occurs when playing with 64582. */
111     public void testPreventDeadLockWhenAddThenRemoveModule_64582() throws Exception JavaDoc {
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 JavaDoc {
119         SuiteProject suite1 = generateSuite("suite1");
120         NbModuleProject module1a = generateStandaloneModule("module1");
121         File JavaDoc otherDir = new File JavaDoc(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 JavaDoc {
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         // user is free to do this, although in more sensible way
148
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 JavaDoc {
164         SuiteProject suite = generateSuite("suite");
165         generateSuiteComponent(suite, "suiteComponent");
166         generateStandaloneModuleDirectory(getWorkDir(), "module");
167         File JavaDoc suiteF = new File JavaDoc(getWorkDir(), "suite");
168         assertTrue(suite + " is a suite", SuiteUtils.isSuite(suiteF));
169         assertFalse(suite + " is not a suite", SuiteUtils.isSuite(new File JavaDoc(suiteF, "suiteComponent")));
170         assertFalse(suite + " is not a suite", SuiteUtils.isSuite(new File JavaDoc(getWorkDir(), "module")));
171     }
172     
173     public void testFindSuiteNotSuiteProject80786() throws Exception JavaDoc {
174         // Check that SuiteUtils.findSuite gracefully ignores a project which is not a suite project.
175
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