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;
043:
044: import java.util.HashMap;
045: import java.util.Map;
046: import javax.swing.ComboBoxModel;
047: import javax.swing.KeyStroke;
048: import org.netbeans.api.project.Project;
049: import org.netbeans.modules.apisupport.project.NbModuleProject;
050: import org.netbeans.modules.apisupport.project.TestBase;
051: import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
052: import org.netbeans.modules.apisupport.project.layers.LayerUtils;
053: import org.netbeans.modules.apisupport.project.ui.UIUtil.LayerItemPresenter;
054: import org.openide.filesystems.FileObject;
055: import org.openide.filesystems.FileSystem;
056:
057: /**
058: * @author Martin Krauskopf
059: */
060: public class UIUtilTest extends LayerTestBase {
061:
062: public UIUtilTest(String testName) {
063: super (testName);
064: }
065:
066: protected void setUp() throws Exception {
067: super .setUp();
068: TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
069: }
070:
071: /**
072: * Test of createLayerPresenterComboModel method, of class org.netbeans.modules.apisupport.project.ui.UIUtil.
073: */
074: public void testCreateLayerPresenterComboModel() throws Exception {
075: Project project = TestBase.generateStandaloneModule(
076: getWorkDir(), "module1");
077: Map<String, Object> excludes = new HashMap<String, Object>();
078: excludes.put("template", true);
079: excludes.put("simple", false);
080: String sfsRoot = "Templates";
081: ComboBoxModel allModel = UIUtil.createLayerPresenterComboModel(
082: project, sfsRoot);
083: ComboBoxModel excludedModel = UIUtil
084: .createLayerPresenterComboModel(project, sfsRoot,
085: excludes);
086: assertTrue(
087: "UIUtil.createLayerPresenterComboModel() doesn't work.",
088: allModel.getSize() >= excludedModel.getSize());
089: }
090:
091: public void testKeyToLogicalString() throws Exception {
092: assertKeyLogicalString("X", "pressed X");
093: assertKeyLogicalString("D-X", "ctrl pressed X");
094: assertKeyLogicalString("DO-X", "ctrl alt pressed X");
095: assertKeyLogicalString("DS-X", "shift ctrl pressed X");
096: assertKeyLogicalString("OS-X", "shift alt pressed X");
097: assertKeyLogicalString("DOS-X", "shift ctrl alt pressed X");
098: assertKeyLogicalString("ENTER", "pressed ENTER");
099: }
100:
101: private void assertKeyLogicalString(String expected,
102: String swingKeyStroke) {
103: assertEquals(swingKeyStroke + " corresponding to " + expected,
104: expected, UIUtil.keyToLogicalString(KeyStroke
105: .getKeyStroke(swingKeyStroke)));
106: }
107:
108: public void testLayerItemPresenterCompareTo() throws Exception {
109: TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
110: NbModuleProject project = TestBase.generateStandaloneModule(
111: getWorkDir(), "module");
112: FileSystem fs = LayerUtils
113: .getEffectiveSystemFilesystem(project);
114: FileObject root = fs.getRoot().getFileObject(
115: "Templates/Project/APISupport");
116: FileObject module = root.getFileObject("emptyModule");
117: FileObject suite = root.getFileObject("emptySuite");
118: FileObject library = root.getFileObject("libraryModule");
119: LayerItemPresenter moduleLIP = new LayerItemPresenter(module,
120: root);
121: LayerItemPresenter moduleLIP1 = new LayerItemPresenter(module,
122: root);
123: LayerItemPresenter suiteLIP = new LayerItemPresenter(suite,
124: root);
125: LayerItemPresenter libraryLIP = new LayerItemPresenter(library,
126: root);
127: assertTrue("'Module Project' < 'Module Suite Project'",
128: moduleLIP.compareTo(suiteLIP) < 0);
129: assertTrue("'Module Project' == 'Module Project'", moduleLIP
130: .compareTo(moduleLIP1) == 0);
131: assertTrue(
132: "'Library Wrapper Module Project < 'Module Project'",
133: libraryLIP.compareTo(moduleLIP) < 0);
134: assertTrue(
135: "'Library Wrapper Module Project < 'Module Suite Project'",
136: libraryLIP.compareTo(suiteLIP) < 0);
137: }
138:
139: }
|