KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > spi > project > support > rake > SharabilityQueryImplTest


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.ruby.spi.project.support.rake;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.api.project.ProjectManager;
24 import org.netbeans.api.project.TestUtil;
25 import org.netbeans.api.queries.SharabilityQuery;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.spi.queries.SharabilityQueryImplementation;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30
31 /**
32  * Test functionality of SharabilityQueryImpl.
33  * @author Jesse Glick
34  */

35 public class SharabilityQueryImplTest extends NbTestCase {
36
37     public SharabilityQueryImplTest(String JavaDoc name) {
38         super(name);
39     }
40     
41     /** Location of top of testing dir (contains projdir and external). */
42     private File JavaDoc scratchF;
43     /** Tested impl. */
44     private SharabilityQueryImplementation sqi;
45     
46     protected void setUp() throws Exception JavaDoc {
47         super.setUp();
48         clearWorkDir();
49         TestUtil.setLookup(new Object JavaDoc[] {
50             RakeBasedTestUtil.testRakeBasedProjectType(),
51         });
52         FileObject scratch = TestUtil.makeScratchDir(this);
53         scratchF = FileUtil.toFile(scratch);
54         FileObject projdir = scratch.createFolder("projdir");
55         RakeProjectHelper h = ProjectGenerator.createProject(projdir, "test");
56         assertEquals("right project directory", projdir, h.getProjectDirectory());
57         EditableProperties props = h.getProperties(RakeProjectHelper.PROJECT_PROPERTIES_PATH);
58         props.setProperty("build.dir", "build");
59         props.setProperty("build2.dir", "build/2");
60         props.setProperty("dist.dir", "dist");
61         props.setProperty("src.dir", "src");
62         File JavaDoc externalF = new File JavaDoc(scratchF, "external");
63         props.setProperty("src2.dir", new File JavaDoc(externalF, "src").getAbsolutePath());
64         props.setProperty("build3.dir", new File JavaDoc(externalF, "build").getAbsolutePath());
65         h.putProperties(RakeProjectHelper.PROJECT_PROPERTIES_PATH, props);
66         ProjectManager.getDefault().saveProject(ProjectManager.getDefault().findProject(projdir));
67         sqi = h.createSharabilityQuery(h.getStandardPropertyEvaluator(), new String JavaDoc[] {"${src.dir}", "${src2.dir}"},
68                                        new String JavaDoc[] {"${build.dir}", "${build2.dir}", "${build3.dir}", "${dist.dir}"});
69     }
70     
71     private File JavaDoc file(String JavaDoc path) {
72         return new File JavaDoc(scratchF, path.replace('/', File.separatorChar));
73     }
74     
75     public void testBasicIncludesExcludes() throws Exception JavaDoc {
76         assertEquals("project directory is mixed", SharabilityQuery.MIXED, sqi.getSharability(file("projdir")));
77         assertEquals("build.xml is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/build.xml")));
78         assertEquals("src/ is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src")));
79         assertEquals("src/org/foo/ is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src/org/foo")));
80         assertEquals("src/org/foo/Foo.java is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src/org/foo/Foo.java")));
81         assertEquals("nbproject/ is mixed", SharabilityQuery.MIXED, sqi.getSharability(file("projdir/nbproject")));
82         assertEquals("nbproject/project.xml is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/nbproject/project.xml")));
83         assertEquals("nbproject/private/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/nbproject/private")));
84         assertEquals("nbproject/private/private.properties is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/nbproject/private/private.properties")));
85         assertEquals("build/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build")));
86         assertEquals("build/classes/org/foo/Foo.class is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/classes/org/foo/Foo.class")));
87         assertEquals("dist/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/dist")));
88     }
89     
90     public void testOverlaps() throws Exception JavaDoc {
91         assertEquals("build/2/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/2")));
92         assertEquals("build/2/whatever is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/2/whatever")));
93         // overlaps in includePaths tested in basicIncludesExcludes: src is inside projdir
94
}
95     
96     public void testExternalFiles() throws Exception JavaDoc {
97         assertEquals("external/src is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("external/src")));
98         assertEquals("external/src/org/foo/Foo.java is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("external/src/org/foo/Foo.java")));
99         assertEquals("external/build is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("external/build")));
100         assertEquals("external/build/classes/org/foo/Foo.class is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("external/build/classes/org/foo/Foo.class")));
101     }
102     
103     public void testUnknownFiles() throws Exception JavaDoc {
104         assertEquals("some other dir is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("something")));
105         assertEquals("some other file is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("something/else")));
106         assertEquals("external itself is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("external")));
107     }
108     
109     public void testDirNamesEndingInSlash() throws Exception JavaDoc {
110         assertEquals("project directory is mixed", SharabilityQuery.MIXED, sqi.getSharability(file("projdir/")));
111         assertEquals("src/ is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src/")));
112         assertEquals("src/org/foo/ is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/src/org/foo/")));
113         assertEquals("nbproject/ is mixed", SharabilityQuery.MIXED, sqi.getSharability(file("projdir/nbproject/")));
114         assertEquals("nbproject/private/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/nbproject/private/")));
115         assertEquals("build/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/")));
116         assertEquals("dist/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/dist/")));
117         assertEquals("build/2/ is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("projdir/build/2/")));
118         assertEquals("some other dir is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("something/")));
119         assertEquals("external itself is unknown", SharabilityQuery.UNKNOWN, sqi.getSharability(file("external/")));
120         assertEquals("external/src is sharable", SharabilityQuery.SHARABLE, sqi.getSharability(file("external/src/")));
121         assertEquals("external/build is not sharable", SharabilityQuery.NOT_SHARABLE, sqi.getSharability(file("external/build/")));
122     }
123     
124     public void testSubprojectFiles() throws Exception JavaDoc {
125         assertEquals("nbproject/private from a subproject is sharable as far as this impl is concerned", SharabilityQuery.SHARABLE, sqi.getSharability(file("projdir/subproj/nbproject/private")));
126     }
127     
128     // XXX testChangedProperties
129
// XXX testExternalSourceDirs
130

131 }
132
Popular Tags