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.navigator;
043:
044: import java.util.Collection;
045: import javax.swing.JComponent;
046: import org.netbeans.junit.NbTest;
047: import org.netbeans.junit.NbTestCase;
048: import org.netbeans.junit.NbTestSuite;
049: import org.netbeans.spi.navigator.NavigatorPanel;
050: import org.openide.util.Lookup;
051:
052: /**
053: *
054: * @author Dafe Simonek
055: */
056: public class ProviderRegistryTest extends NbTestCase {
057:
058: /** test data type contants */
059: private static final String MARVELOUS_DATA_TYPE_NAME = "MarvelousDataType";
060: private static final String MARVELOUS_DATA_TYPE = "text/marvelous/data_type";
061:
062: /** Creates a new instance of ProviderRegistryTest */
063: public ProviderRegistryTest() {
064: super ("");
065: }
066:
067: public ProviderRegistryTest(String testName) {
068: super (testName);
069: }
070:
071: public static void main(java.lang.String[] args) {
072: junit.textui.TestRunner.run(suite());
073: }
074:
075: public static NbTest suite() {
076: NbTestSuite suite = new NbTestSuite(ProviderRegistryTest.class);
077: return suite;
078: }
079:
080: public void testGetProviders() throws Exception {
081: UnitTestUtils
082: .prepareTest(new String[] { "/org/netbeans/modules/navigator/resources/testGetProvidersLayer.xml" });
083:
084: ProviderRegistry providerReg = ProviderRegistry.getInstance();
085:
086: System.out.println("Asking for non-existent type...");
087: assertEquals(0, providerReg.getProviders(
088: "image/non_existent_type").size());
089:
090: System.out.println("Asking for non-existent class...");
091: assertEquals(0, providerReg.getProviders("text/plain").size());
092:
093: System.out.println("Asking for valid type and provider...");
094: Collection<? extends NavigatorPanel> result = providerReg
095: .getProviders(MARVELOUS_DATA_TYPE);
096: assertEquals(1, result.size());
097: NavigatorPanel np = result.iterator().next();
098: assertTrue(np instanceof MarvelousDataTypeProvider);
099: MarvelousDataTypeProvider provider = (MarvelousDataTypeProvider) np;
100: assertEquals(MARVELOUS_DATA_TYPE_NAME, provider
101: .getDisplayName());
102: }
103:
104: /** Dummy navigator panel provider, just to test right loading and instantiating
105: * for certain data type
106: */
107: public static final class MarvelousDataTypeProvider implements
108: NavigatorPanel {
109:
110: public String getDisplayName() {
111: return MARVELOUS_DATA_TYPE_NAME;
112: }
113:
114: public String getDisplayHint() {
115: return null;
116: }
117:
118: public JComponent getComponent() {
119: return null;
120: }
121:
122: public void panelActivated(Lookup context) {
123: }
124:
125: public void panelDeactivated() {
126: }
127:
128: public Lookup getLookup() {
129: return null;
130: }
131:
132: }
133:
134: }
|