KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > EvaluatorTest


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;
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.spi.project.support.ant.EditableProperties;
26 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
27 import org.openide.filesystems.FileObject;
28 import org.openide.filesystems.FileUtil;
29
30 /**
31  * Test {@link Evaluator} generally (but also see {@link ClassPathProviderImplTest}).
32  * @author Jesse Glick
33  */

34 public class EvaluatorTest extends TestBase {
35
36     public EvaluatorTest(String JavaDoc name) {
37         super(name);
38     }
39     
40     private NbModuleProject javaProjectProject;
41     private NbModuleProject loadersProject;
42     private File JavaDoc userPropertiesFile;
43     
44     protected void setUp() throws Exception JavaDoc {
45         super.setUp();
46         userPropertiesFile = TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
47         FileObject dir = nbCVSRoot().getFileObject("java/project");
48         assertNotNull("have java/project checked out", dir);
49         Project p = ProjectManager.getDefault().findProject(dir);
50         javaProjectProject = (NbModuleProject)p;
51         dir = nbCVSRoot().getFileObject("openide/loaders");
52         assertNotNull("have openide/loaders checked out", dir);
53         p = ProjectManager.getDefault().findProject(dir);
54         loadersProject = (NbModuleProject)p;
55     }
56     
57     public void testEvaluator() throws Exception JavaDoc {
58         PropertyEvaluator eval = javaProjectProject.evaluator();
59         assertEquals("right basedir", file("java/project"),
60             javaProjectProject.getHelper().resolveFile(eval.getProperty("basedir")));
61         assertEquals("right nb_all", nbCVSRootFile(),
62             javaProjectProject.getHelper().resolveFile(eval.getProperty("nb_all")));
63         assertEquals("right code.name.base.dashes", "org-netbeans-modules-java-project", eval.getProperty("code.name.base.dashes"));
64         assertEquals("right is.autoload", "true", eval.getProperty("is.autoload"));
65         assertEquals("right manifest.mf", "manifest.mf", eval.getProperty("manifest.mf"));
66         assertEquals("right core.dir", file("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM),
67             javaProjectProject.getHelper().resolveFile(eval.getProperty("core.dir")));
68         assertEquals("right apisupport/project.dir", file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE),
69             javaProjectProject.getHelper().resolveFile(eval.getProperty("apisupport/project.dir")));
70         assertEquals("right module JAR", file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-java-project.jar"),
71             javaProjectProject.getHelper().resolveFile(eval.evaluate("${cluster}/${module.jar}")));
72         eval = loadersProject.evaluator();
73         assertEquals("right module JAR", file("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar"),
74             loadersProject.getHelper().resolveFile(eval.evaluate("${cluster}/${module.jar}")));
75     }
76
77     /** @see "#63541" */
78     public void testJdkProperties() throws Exception JavaDoc {
79         File JavaDoc testjdk = new File JavaDoc(getWorkDir(), "testjdk");
80         EditableProperties ep = Util.loadProperties(FileUtil.toFileObject(userPropertiesFile));
81         ep.setProperty("platforms.testjdk.home", testjdk.getAbsolutePath());
82         Util.storeProperties(FileUtil.toFileObject(userPropertiesFile), ep);
83         NbModuleProject p = generateStandaloneModule("module");
84         PropertyEvaluator eval = p.evaluator();
85         TestBase.TestPCL l = new TestBase.TestPCL();
86         eval.addPropertyChangeListener(l);
87         String JavaDoc bootcp = eval.getProperty("nbjdk.bootclasspath");
88         String JavaDoc origbootcp = bootcp;
89         assertNotNull(bootcp); // who knows what actual value will be inside a unit test - probably empty
90
ep = p.getHelper().getProperties("nbproject/platform.properties");
91         ep.setProperty("nbjdk.active", "testjdk");
92         p.getHelper().putProperties("nbproject/platform.properties", ep);
93         assertTrue("got a change in bootcp", l.changed.contains("nbjdk.bootclasspath"));
94         l.reset();
95         bootcp = eval.getProperty("nbjdk.bootclasspath");
96         assertEquals("correct bootcp", new File JavaDoc(testjdk, "jre/lib/rt.jar".replace('/', File.separatorChar)).getAbsolutePath(), bootcp);
97         ep = p.getHelper().getProperties("nbproject/platform.properties");
98         ep.setProperty("nbjdk.active", "default");
99         p.getHelper().putProperties("nbproject/platform.properties", ep);
100         assertTrue("got a change in bootcp", l.changed.contains("nbjdk.bootclasspath"));
101         l.reset();
102         bootcp = eval.getProperty("nbjdk.bootclasspath");
103         assertEquals(origbootcp, bootcp);
104     }
105     
106 }
107
Popular Tags