1 19 20 package org.netbeans.modules.apisupport.project.suite; 21 22 import java.util.Arrays ; 23 import java.util.Collections ; 24 import java.util.HashSet ; 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 45 public class SuiteProjectTest extends NbTestCase { 46 47 public SuiteProjectTest(String name) { 48 super(name); 49 } 50 51 protected void setUp() throws Exception { 52 super.setUp(); 53 clearWorkDir(); 54 TestBase.initializeBuildProperties(getWorkDir(), getDataDir()); 55 } 56 57 public void testProjectInformation() throws Exception { 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 (Arrays.asList(new String [] {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 { 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 assertEquals("up-to-date 'modules' property from suite evaluator", "module1", eval.getProperty("modules")); 90 91 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 { 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 run() throws Exception { 107 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 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(); } 129 130 } 131 | Popular Tags |