KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > suite > SuiteProjectTest


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.suite;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.api.project.ProjectInformation;
27 import org.netbeans.api.project.ProjectManager;
28 import org.netbeans.api.project.ProjectUtils;
29 import org.netbeans.junit.NbTestCase;
30 import org.netbeans.modules.apisupport.project.TestBase;
31 import org.netbeans.modules.apisupport.project.Util;
32 import org.netbeans.modules.apisupport.project.ui.customizer.BasicBrandingModel;
33 import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties;
34 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
35 import org.netbeans.spi.project.support.ant.AntProjectHelper;
36 import org.netbeans.spi.project.support.ant.EditableProperties;
37 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
38 import org.openide.filesystems.FileObject;
39 import org.openide.util.Mutex;
40
41 /**
42  * Test basic {@link SuiteProject} stuff.
43  * @author Jesse Glick
44  */

45 public class SuiteProjectTest extends NbTestCase {
46     
47     public SuiteProjectTest(String JavaDoc name) {
48         super(name);
49     }
50     
51     protected void setUp() throws Exception JavaDoc {
52         super.setUp();
53         clearWorkDir();
54         TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
55     }
56     
57     public void testProjectInformation() throws Exception JavaDoc {
58         SuiteProject p = TestBase.generateSuite(getWorkDir(), "Sweet Stuff");
59         ProjectInformation i = ProjectUtils.getInformation(p);
60         assertEquals("Sweet_Stuff", i.getName());
61         assertEquals("Sweet Stuff", i.getDisplayName());
62         BasicBrandingModel model = new BasicBrandingModel(new SuiteProperties(p, p.getHelper(), p.getEvaluator(), Collections.EMPTY_SET));
63         assertEquals("sweet_stuff", model.getName());
64         assertEquals("Sweet Stuff", model.getTitle());
65         TestBase.TestPCL l = new TestBase.TestPCL();
66         i.addPropertyChangeListener(l);
67         EditableProperties ep = p.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
68         ep.setProperty("app.name", "sweetness");
69         ep.setProperty("app.title", "Sweetness is Now!");
70         p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
71         assertEquals(new HashSet JavaDoc(Arrays.asList(new String JavaDoc[] {ProjectInformation.PROP_NAME, ProjectInformation.PROP_DISPLAY_NAME})), l.changed);
72         assertEquals("Sweet_Stuff", i.getName());
73         assertEquals("Sweetness is Now!", i.getDisplayName());
74         model = new BasicBrandingModel(new SuiteProperties(p, p.getHelper(), p.getEvaluator(), Collections.EMPTY_SET));
75         assertEquals("sweetness", model.getName());
76         assertEquals("Sweetness is Now!", model.getTitle());
77     }
78     
79     public void testSuiteEvaluatorReturnsUpToDateValues() throws Exception JavaDoc { // #67314, #72981
80
SuiteProject suite1 = TestBase.generateSuite(getWorkDir(), "suite1");
81         PropertyEvaluator eval = suite1.getEvaluator();
82         TestBase.generateSuiteComponent(suite1, "module1");
83         
84         FileObject suiteEPFO = suite1.getProjectDirectory().getFileObject("nbproject/project.properties");
85         EditableProperties suiteEP = Util.loadProperties(suiteEPFO);
86         assertEquals("modules property", "${project.org.example.module1}", suiteEP.getProperty("modules"));
87         assertEquals("project.org.example.module1 property", "module1", suiteEP.getProperty("project.org.example.module1"));
88         // #67314
89
assertEquals("up-to-date 'modules' property from suite evaluator", "module1", eval.getProperty("modules"));
90         
91         // branding.dir check (#72981)
92
assertEquals("branding.dir has a default value", "branding", eval.getProperty("branding.dir"));
93         suiteEP.setProperty("custom.dir", "custom");
94         suiteEP.setProperty("branding.dir", "${custom.dir}/nonDefaultBrandingDir");
95         suite1.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, suiteEP);
96         assertEquals("branding dir evaluated", "custom/nonDefaultBrandingDir", eval.getProperty("branding.dir"));
97     }
98     
99     public void testPlatformPropertiesFromEvaluatorAreUpToDate() throws Exception JavaDoc {
100         final SuiteProject suite = TestBase.generateSuite(getWorkDir(), "suite1", "custom");
101         PropertyEvaluator eval = suite.getEvaluator();
102         assertEquals("custom", eval.getProperty("nbplatform.active"));
103         assertEquals(NbPlatform.getPlatformByID("custom").getDestDir(), suite.getHelper().resolveFile(eval.getProperty("netbeans.dest.dir")));
104         
105         ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() {
106             public Object JavaDoc run() throws Exception JavaDoc {
107                 // simulate change (e.g. through suite properties)
108
FileObject plafProps = suite.getProjectDirectory().getFileObject("nbproject/platform.properties");
109                 EditableProperties ep = Util.loadProperties(plafProps);
110                 ep.setProperty("nbplatform.active", "default");
111                 Util.storeProperties(plafProps, ep);
112                 return null;
113             }
114         });
115         
116         assertEquals("nbplatform.active change took effect", "default", eval.getProperty("nbplatform.active"));
117         assertEquals("#67628: netbeans.dest.dir change did as well", NbPlatform.getDefaultPlatform().getDestDir(), suite.getHelper().resolveFile(eval.getProperty("netbeans.dest.dir")));
118     }
119     
120     /**
121      * Accessor method for those who wish to simulate open of a project and in
122      * case of suite for example generate the build.xml.
123      */

124     public static void openSuite(final Project p) {
125         SuiteProject.OpenedHook hook = (SuiteProject.OpenedHook) p.getLookup().lookup(SuiteProject.OpenedHook.class);
126         assertNotNull("has an OpenedHook", hook);
127         hook.projectOpened(); // protected but can use package-private access
128
}
129     
130 }
131
Popular Tags