KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > ModuleDependencyTest


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.ui.customizer;
21
22 import java.text.Collator JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.TreeSet JavaDoc;
27 import org.netbeans.api.project.ProjectManager;
28 import org.netbeans.modules.apisupport.project.EditableManifest;
29 import org.netbeans.modules.apisupport.project.ManifestManager;
30 import org.netbeans.modules.apisupport.project.NbModuleProject;
31 import org.netbeans.modules.apisupport.project.TestBase;
32 import org.netbeans.modules.apisupport.project.Util;
33 import org.netbeans.modules.apisupport.project.suite.SuiteProject;
34 import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
35 import org.netbeans.modules.apisupport.project.universe.ModuleList;
36 import org.netbeans.spi.project.support.ant.AntProjectHelper;
37 import org.netbeans.spi.project.support.ant.EditableProperties;
38
39 /**
40  * @author Martin Krauskopf
41  */

42 public class ModuleDependencyTest extends TestBase {
43     
44     public ModuleDependencyTest(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     public void testHashCodeAndEqualsAndCompareTo() throws Exception JavaDoc {
49         NbModuleProject module = generateStandaloneModule("module");
50         ModuleList ml = module.getModuleList();
51         ModuleEntry antME = ml.getEntry("org.apache.tools.ant.module");
52         ModuleDependency d1 = new ModuleDependency(antME);
53         ModuleDependency sameAsD1 = new ModuleDependency(antME);
54         ModuleDependency alsoSameAsD1 = new ModuleDependency(antME, antME.getReleaseVersion(), antME.getSpecificationVersion(), true, false);
55         ModuleDependency d2 = new ModuleDependency(antME, "0-1", null, true, false);
56         ModuleDependency d3 = new ModuleDependency(antME, null, null, true, false);
57         ModuleDependency d4 = new ModuleDependency(antME, antME.getReleaseVersion(), null, true, true);
58         ModuleDependency d5 = new ModuleDependency(antME, antME.getReleaseVersion(), null, true, false);
59         
60         // test hash code and equals
61
Set JavaDoc/*<ModuleDependency>*/ set = new HashSet JavaDoc();
62         Set JavaDoc/*<ModuleDependency>*/ sorted = new TreeSet JavaDoc();
63         set.add(d1);
64         sorted.add(d1);
65         assertFalse("already there", set.add(sameAsD1));
66         assertFalse("already there", sorted.add(sameAsD1));
67         assertFalse("already there", set.add(alsoSameAsD1));
68         assertFalse("already there", sorted.add(alsoSameAsD1));
69         assertTrue("is not there yet", set.add(d2));
70         assertTrue("is not there yet", sorted.add(d2));
71         assertTrue("is not there yet", set.add(d3));
72         assertTrue("is not there yet", sorted.add(d3));
73         assertTrue("is not there yet", set.add(d4));
74         assertTrue("is not there yet", sorted.add(d4));
75         assertTrue("is not there yet", set.add(d5));
76         assertTrue("is not there yet", sorted.add(d5));
77         
78         ModuleDependency[] expectedOrder = new ModuleDependency[] {
79             d3, d2, d5, d4, d1
80         };
81         Iterator JavaDoc it = sorted.iterator();
82         for (int i = 0; i < expectedOrder.length; i++) {
83             assertSame("expected order", expectedOrder[i], it.next());
84         }
85         assertFalse("sanity check", it.hasNext());
86     }
87     
88     public void testLocalizedNameComparator() throws Exception JavaDoc {
89         NbModuleProject module = generateStandaloneModule("module");
90         ModuleList ml = module.getModuleList();
91         ModuleDependency[] deps = new ModuleDependency[] {
92             new ModuleDependency(ml.getEntry("org.apache.tools.ant.module")),
93             new ModuleDependency(ml.getEntry("org.openide.loaders")),
94             new ModuleDependency(ml.getEntry("org.apache.tools.ant.module")),
95             new ModuleDependency(ml.getEntry("org.openide.io")),
96             new ModuleDependency(ml.getEntry("org.jdesktop.layout")),
97             new ModuleDependency(ml.getEntry("org.openide.filesystems")),
98             new ModuleDependency(ml.getEntry("org.openide.execution")),
99         };
100         
101         for (int i = 0; i < deps.length; i++) {
102             for (int j = 0; j < deps.length; j++) {
103                 int locNameResult = Collator.getInstance().compare(
104                         deps[i].getModuleEntry().getLocalizedName(),
105                         deps[j].getModuleEntry().getLocalizedName());
106                 int realResult = ModuleDependency.LOCALIZED_NAME_COMPARATOR.compare(deps[i], deps[j]);
107                 assertTrue("ordering works: " + deps[i] + " <--> " + deps[j],
108                         locNameResult > 0 ? realResult > 0 :
109                             (locNameResult == 0 ? realResult == 0 : realResult < 0));
110 // (int) Math.signum(locNameResult), (int) Math.signum(realResult));
111
}
112         }
113     }
114     
115     public void testSpecVersionBaseSourceEntries() throws Exception JavaDoc { // #72463
116
SuiteProject suite = generateSuite("suite");
117         NbModuleProject p = TestBase.generateSuiteComponent(suite, "module");
118         ModuleList ml = ModuleList.getModuleList(p.getProjectDirectoryFile());
119         ModuleEntry e = ml.getEntry("org.example.module");
120         assertNotNull("have entry", e);
121         ModuleDependency dep = new ModuleDependency(e);
122         assertEquals("right initial spec vers from manifest", "1.0", dep.getSpecificationVersion());
123         EditableProperties ep = p.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
124         ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE, "1.1.0");
125         p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
126         EditableManifest em = Util.loadManifest(p.getManifestFile());
127         em.removeAttribute(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, null);
128         Util.storeManifest(p.getManifestFile(), em);
129         ProjectManager.getDefault().saveProject(p);
130         dep = new ModuleDependency(e);
131         assertEquals("right spec.version.base", "1.1", dep.getSpecificationVersion());
132         ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE, "1.2.0");
133         p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
134         ProjectManager.getDefault().saveProject(p);
135         dep = new ModuleDependency(e);
136         assertEquals("right modified spec.version.base", "1.2", dep.getSpecificationVersion());
137         dep = new ModuleDependency(e, null, "1.0", true, false);
138         assertEquals("right explicit spec vers", "1.0", dep.getSpecificationVersion());
139     }
140     
141     public void testAppropriateDefaultCompileDependency() throws Exception JavaDoc { // #73666
142
NbModuleProject p = generateStandaloneModule("module");
143         ModuleList ml = ModuleList.getModuleList(p.getProjectDirectoryFile());
144         ModuleDependency d = new ModuleDependency(ml.getEntry("org.example.module"));
145         assertFalse("no public packages -> no compile dependency by default", d.hasCompileDependency());
146     }
147     
148 }
149
Popular Tags