KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > universe > TestModuleDependencyTest


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.universe;
21
22 import org.netbeans.api.project.ProjectManager;
23 import org.netbeans.modules.apisupport.project.NbModuleProject;
24 import org.netbeans.modules.apisupport.project.TestBase;
25 import org.openide.filesystems.FileObject;
26
27
28 /**
29  *
30  * @author Tomas Musil
31  */

32 public class TestModuleDependencyTest extends TestBase {
33     
34     private final static String JavaDoc ANT_PROJECT_SUPPORT = "org.netbeans.modules.project.ant";
35     private final static String JavaDoc DIALOGS = "org.openide.dialogs";
36     private TestModuleDependency tdJP_001;
37     private TestModuleDependency tdJP_101;
38     private TestModuleDependency tdJP_101otherInstance;
39     private TestModuleDependency tdAnt_111;
40     
41     public TestModuleDependencyTest(String JavaDoc testName) {
42         super(testName);
43     }
44     
45     protected void setUp() throws Exception JavaDoc {
46         clearWorkDir();
47         super.setUp();
48         final NbModuleProject testingProject = generateTestingProject();
49         final String JavaDoc cnb = "org.netbeans.modules.java.project";
50         final String JavaDoc cnb2 = "org.netbeans.modules.project.ant";
51         ModuleEntry meJP = testingProject.getModuleList().getEntry(cnb);
52         ModuleEntry meAnt = testingProject.getModuleList().getEntry(cnb2);
53         tdJP_001 = new TestModuleDependency(meJP, false, false, true);
54         tdJP_101 = new TestModuleDependency(meJP, true, false, true);
55         tdJP_101otherInstance = new TestModuleDependency(meJP, true, false, true);
56         tdAnt_111 = new TestModuleDependency(meAnt, true, true, true);
57     }
58     
59     
60     public void testEquals() throws Exception JavaDoc{
61         assertFalse("001!=101" , tdJP_001.equals((TestModuleDependency)tdJP_101));
62         assertTrue("these are equal", tdJP_101.equals((TestModuleDependency)tdJP_101otherInstance));
63         assertFalse(tdAnt_111.equals(null));
64         assertFalse(tdAnt_111.equals(""));
65     }
66     
67     public void testCompareTo() {
68         assertEquals("equals", 0, tdJP_101.compareTo((TestModuleDependency) tdJP_101otherInstance));
69         assertTrue("o.n.m.java.project < o.n.m.project.ant", tdJP_001.compareTo(tdAnt_111) < 0);
70         assertTrue("o.n.m.project.ant > o.n.m.java.project", tdAnt_111.compareTo(tdJP_101) > 0);
71     }
72     
73     public void testHashCode() {
74         assertEquals("the same hashcodes", tdJP_101.hashCode(),tdJP_101otherInstance.hashCode());
75         assertTrue("the same hashcodes", tdJP_101.hashCode() == tdJP_001.hashCode());
76         assertTrue("different hashcodes", tdJP_101.hashCode() != tdAnt_111.hashCode());
77     }
78     
79     private NbModuleProject generateTestingProject() throws Exception JavaDoc {
80         FileObject fo = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "testing");
81         FileObject projectXMLFO = fo.getFileObject("nbproject/project.xml");
82         String JavaDoc xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
83                 "<project xmlns=\"http://www.netbeans.org/ns/project/1\">\n" +
84                 "<type>org.netbeans.modules.apisupport.project</type>\n" +
85                 "<configuration>\n" +
86                 "<data xmlns=\"http://www.netbeans.org/ns/nb-module-project/3\">\n" +
87                 "<code-name-base>org.example.testing</code-name-base>\n" +
88                 "<standalone/>\n" +
89                 "<module-dependencies>\n" +
90                 "<dependency>\n" +
91                 "<code-name-base>" + DIALOGS + "</code-name-base>\n" +
92                 "<build-prerequisite/>\n" +
93                 "<compile-dependency/>\n" +
94                 "<run-dependency>\n" +
95                 "<specification-version>6.2</specification-version>\n" +
96                 "</run-dependency>\n" +
97                 "</dependency>\n" +
98                 "<dependency>\n" +
99                 "<code-name-base>" + ANT_PROJECT_SUPPORT + "</code-name-base>\n" +
100                 "<build-prerequisite/>\n" +
101                 "<compile-dependency/>\n" +
102                 "<run-dependency>\n" +
103                 "<release-version>1</release-version>\n" +
104                 "<specification-version>1.10</specification-version>\n" +
105                 "</run-dependency>\n" +
106                 "</dependency>\n" +
107                 "</module-dependencies>\n" +
108                 "<test-dependencies/>\n" +
109                 "<friend-packages>\n" +
110                 "<friend>org.module.examplemodule</friend>\n" +
111                 "<package>org.netbeans.examples.modules.misc</package>\n" +
112                 "</friend-packages>\n" +
113                 "<class-path-extension>\n" +
114                 "<runtime-relative-path>ext/jsr88javax.jar</runtime-relative-path>\n" +
115                 "<binary-origin>../external/jsr88javax.jar</binary-origin>\n" +
116                 "</class-path-extension>\n" +
117                 "</data>\n" +
118                 "</configuration>\n" +
119                 "</project>\n";
120         TestBase.dump(projectXMLFO, xml);
121         return (NbModuleProject) ProjectManager.getDefault().findProject(fo);
122     }
123     
124     
125 }
126
Popular Tags