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.ui.customizer;
043:
044: import java.util.ArrayList;
045: import java.util.Arrays;
046: import java.util.Collections;
047: import java.util.HashSet;
048: import java.util.List;
049: import java.util.Set;
050: import org.netbeans.modules.apisupport.project.universe.ModuleList;
051: import org.netbeans.modules.apisupport.project.TestBase;
052: import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
053:
054: /**
055: * Tests {@link AddModuleFilter}.
056: * @author Jesse Glick
057: */
058: public class AddModuleFilterTest extends TestBase {
059:
060: public AddModuleFilterTest(String name) {
061: super (name);
062: }
063:
064: private AddModuleFilter filter;
065:
066: protected @Override
067: void setUp() throws Exception {
068: super .setUp();
069: ModuleList ml = ModuleList
070: .getModuleList(resolveEEPFile("suite1/action-project"));
071: Set<ModuleDependency> deps = new HashSet<ModuleDependency>();
072: for (ModuleEntry entry : ml.getAllEntries()) {
073: deps.add(new ModuleDependency(entry));
074: }
075: filter = new AddModuleFilter(deps, "some.random.module");
076: }
077:
078: public void testSimpleMatches() throws Exception {
079: // JAR:
080: assertMatches("boot.jar",
081: new String[] { "org.netbeans.bootstrap" });
082: // Class-Path JAR:
083: assertMatches("project-ant.jar",
084: new String[] { "org.netbeans.modules.project.ant" });
085: // Display name:
086: assertMatches("demo library",
087: new String[] { "org.netbeans.examples.modules.lib" });
088: }
089:
090: public void testClassAndPackageNameMatches() throws Exception {
091: // Using binaries:
092: assertMatches("callablesys",
093: new String[] { "org.openide.util" }); // org.openide.util.actions.CallableSystemAction
094: assertMatches("org.openide.nodes",
095: new String[] { "org.openide.nodes" });
096: // This is an impl class, exclude it:
097: assertMatches("simplefileownerqueryimpl", new String[0]);
098: // Using sources:
099: assertMatches("libclass",
100: new String[] { "org.netbeans.examples.modules.lib" });
101: // Impl class:
102: assertMatches("magicaction", new String[0]);
103: // Using class-path extensions:
104: assertMatches("javax.help",
105: new String[] { "org.netbeans.modules.javahelp" });
106: // XXX test that friend APIs only match if "I" am a friend (needs API change in ModuleDependency)
107: }
108:
109: public void testMatchStrings() throws Exception {
110: ModuleDependency dep = filter.getMatches("callablesys")
111: .iterator().next();
112: assertEquals(
113: Collections
114: .singleton("org.openide.util.actions.CallableSystemAction"),
115: filter.getMatchesFor("callablesys", dep));
116: }
117:
118: public void testMatchOrdering() throws Exception { // #71995
119: List<String> matches = new ArrayList<String>();
120: for (ModuleDependency dep : filter.getMatches("systemaction")) {
121: matches.add(dep.getModuleEntry().getCodeNameBase());
122: }
123: assertEquals(Arrays.asList("org.openide.util", // etc.SystemAction: matchLevel=0
124: "org.netbeans.modules.editor", // etc.NbEditorUI.SystemActionPerformer: matchLevel=1
125: "org.openide.loaders" // etc.FileSystemAction: matchLevel=2
126: ), matches);
127: }
128:
129: private void assertMatches(String text, String[] cnbs) {
130: Set<String> matchedCNBs = new HashSet<String>();
131: for (ModuleDependency dep : filter.getMatches(text)) {
132: matchedCNBs.add(dep.getModuleEntry().getCodeNameBase());
133: }
134: assertEquals("correct matches for '" + text + "'",
135: new HashSet<String>(Arrays.asList(cnbs)), matchedCNBs);
136: }
137:
138: }
|