KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > navigator > ProviderRegistryTest


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.navigator;
21
22 import java.net.URL JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import org.netbeans.junit.NbTest;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.junit.NbTestSuite;
29 import org.netbeans.spi.navigator.NavigatorPanel;
30 import org.openide.filesystems.FileObject;
31 import org.openide.util.Lookup;
32
33
34 /**
35  *
36  * @author Dafe Simonek
37  */

38 public class ProviderRegistryTest extends NbTestCase {
39
40     /** test data type contants */
41     private static final String JavaDoc MARVELOUS_DATA_TYPE_NAME = "MarvelousDataType";
42     private static final String JavaDoc MARVELOUS_DATA_TYPE = "text/marvelous/data_type";
43     
44     /** Creates a new instance of ProviderRegistryTest */
45     public ProviderRegistryTest() {
46         super("");
47     }
48     
49     public ProviderRegistryTest(String JavaDoc testName) {
50         super(testName);
51     }
52     
53     public static void main(java.lang.String JavaDoc[] args) {
54         junit.textui.TestRunner.run(suite());
55     }
56     
57     public static NbTest suite() {
58         NbTestSuite suite = new NbTestSuite(ProviderRegistryTest.class);
59         return suite;
60     }
61     
62     public void testGetProviders () throws Exception JavaDoc {
63         UnitTestUtils.prepareTest(new String JavaDoc [] { "/org/netbeans/modules/navigator/resources/testGetProvidersLayer.xml" });
64         
65         ProviderRegistry providerReg = ProviderRegistry.getInstance();
66         
67         System.out.println("Asking for non-existent type...");
68         assertEquals(0, providerReg.getProviders("image/non_existent_type").size());
69         
70         System.out.println("Asking for non-existent class...");
71         assertEquals(0, providerReg.getProviders("text/plain").size());
72         
73         System.out.println("Asking for valid type and provider...");
74         List JavaDoc result = providerReg.getProviders(MARVELOUS_DATA_TYPE);
75         assertEquals(1, result.size());
76         assertTrue(result.get(0) instanceof MarvelousDataTypeProvider);
77         MarvelousDataTypeProvider provider = (MarvelousDataTypeProvider)result.get(0);
78         assertEquals(MARVELOUS_DATA_TYPE_NAME, provider.getDisplayName());
79     }
80     
81
82     /** Dummy navigator panel provider, just to test right loading and instantiating
83      * for certain data type
84      */

85     public static final class MarvelousDataTypeProvider implements NavigatorPanel {
86         
87         public String JavaDoc getDisplayName () {
88             return MARVELOUS_DATA_TYPE_NAME;
89         }
90     
91         public String JavaDoc getDisplayHint () {
92             return null;
93         }
94
95         public JComponent JavaDoc getComponent () {
96             return null;
97         }
98
99         public void panelActivated (Lookup context) {
100         }
101
102         public void panelDeactivated () {
103         }
104         
105         public Lookup getLookup () {
106             return null;
107         }
108         
109     }
110     
111     
112 }
113
Popular Tags