001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.universe;
043:
044: import org.netbeans.api.project.ProjectManager;
045: import org.netbeans.modules.apisupport.project.NbModuleProject;
046: import org.netbeans.modules.apisupport.project.TestBase;
047: import org.openide.filesystems.FileObject;
048:
049: /**
050: *
051: * @author Tomas Musil
052: */
053: public class TestModuleDependencyTest extends TestBase {
054:
055: private final static String ANT_PROJECT_SUPPORT = "org.netbeans.modules.project.ant";
056: private final static String DIALOGS = "org.openide.dialogs";
057: private TestModuleDependency tdJP_001;
058: private TestModuleDependency tdJP_101;
059: private TestModuleDependency tdJP_101otherInstance;
060: private TestModuleDependency tdAnt_111;
061:
062: public TestModuleDependencyTest(String testName) {
063: super (testName);
064: }
065:
066: protected void setUp() throws Exception {
067: clearWorkDir();
068: super .setUp();
069: final NbModuleProject testingProject = generateTestingProject();
070: final String cnb = "org.netbeans.modules.java.project";
071: final String cnb2 = "org.netbeans.modules.project.ant";
072: ModuleEntry meJP = testingProject.getModuleList().getEntry(cnb);
073: ModuleEntry meAnt = testingProject.getModuleList().getEntry(
074: cnb2);
075: tdJP_001 = new TestModuleDependency(meJP, false, false, true);
076: tdJP_101 = new TestModuleDependency(meJP, true, false, true);
077: tdJP_101otherInstance = new TestModuleDependency(meJP, true,
078: false, true);
079: tdAnt_111 = new TestModuleDependency(meAnt, true, true, true);
080: }
081:
082: public void testEquals() throws Exception {
083: assertFalse("001!=101", tdJP_001
084: .equals((TestModuleDependency) tdJP_101));
085: assertTrue("these are equal", tdJP_101
086: .equals((TestModuleDependency) tdJP_101otherInstance));
087: assertFalse(tdAnt_111.equals(null));
088: assertFalse(tdAnt_111.equals(""));
089: }
090:
091: public void testCompareTo() {
092: assertEquals(
093: "equals",
094: 0,
095: tdJP_101
096: .compareTo((TestModuleDependency) tdJP_101otherInstance));
097: assertTrue("o.n.m.java.project < o.n.m.project.ant", tdJP_001
098: .compareTo(tdAnt_111) < 0);
099: assertTrue("o.n.m.project.ant > o.n.m.java.project", tdAnt_111
100: .compareTo(tdJP_101) > 0);
101: }
102:
103: public void testHashCode() {
104: assertEquals("the same hashcodes", tdJP_101.hashCode(),
105: tdJP_101otherInstance.hashCode());
106: assertTrue("the same hashcodes",
107: tdJP_101.hashCode() == tdJP_001.hashCode());
108: assertTrue("different hashcodes",
109: tdJP_101.hashCode() != tdAnt_111.hashCode());
110: }
111:
112: private NbModuleProject generateTestingProject() throws Exception {
113: FileObject fo = TestBase.generateStandaloneModuleDirectory(
114: getWorkDir(), "testing");
115: FileObject projectXMLFO = fo
116: .getFileObject("nbproject/project.xml");
117: String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
118: + "<project xmlns=\"http://www.netbeans.org/ns/project/1\">\n"
119: + "<type>org.netbeans.modules.apisupport.project</type>\n"
120: + "<configuration>\n"
121: + "<data xmlns=\"http://www.netbeans.org/ns/nb-module-project/3\">\n"
122: + "<code-name-base>org.example.testing</code-name-base>\n"
123: + "<standalone/>\n" + "<module-dependencies>\n"
124: + "<dependency>\n" + "<code-name-base>"
125: + DIALOGS
126: + "</code-name-base>\n"
127: + "<build-prerequisite/>\n"
128: + "<compile-dependency/>\n"
129: + "<run-dependency>\n"
130: + "<specification-version>6.2</specification-version>\n"
131: + "</run-dependency>\n"
132: + "</dependency>\n"
133: + "<dependency>\n"
134: + "<code-name-base>"
135: + ANT_PROJECT_SUPPORT
136: + "</code-name-base>\n"
137: + "<build-prerequisite/>\n"
138: + "<compile-dependency/>\n"
139: + "<run-dependency>\n"
140: + "<release-version>1</release-version>\n"
141: + "<specification-version>1.10</specification-version>\n"
142: + "</run-dependency>\n"
143: + "</dependency>\n"
144: + "</module-dependencies>\n"
145: + "<test-dependencies/>\n"
146: + "<friend-packages>\n"
147: + "<friend>org.module.examplemodule</friend>\n"
148: + "<package>org.netbeans.examples.modules.misc</package>\n"
149: + "</friend-packages>\n"
150: + "<class-path-extension>\n"
151: + "<runtime-relative-path>ext/jsr88javax.jar</runtime-relative-path>\n"
152: + "<binary-origin>../external/jsr88javax.jar</binary-origin>\n"
153: + "</class-path-extension>\n"
154: + "</data>\n"
155: + "</configuration>\n" + "</project>\n";
156: TestBase.dump(projectXMLFO, xml);
157: return (NbModuleProject) ProjectManager.getDefault()
158: .findProject(fo);
159: }
160:
161: }
|