KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import junit.framework.*;
27 import org.netbeans.spi.navigator.NavigatorPanel;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.filesystems.URLMapper;
31 import org.openide.loaders.DataFolder;
32 import org.openide.loaders.DataObject;
33 import org.openide.loaders.DataShadow;
34 import org.openide.util.Lookup;
35
36
37 /**
38  *
39  * @author Dafe Simonek
40  */

41 public class NavigatorControllerTest extends TestCase {
42     
43     private static final String JavaDoc JAVA_DATA_TYPE = "text/marvelous/data_type";
44     
45     
46     public NavigatorControllerTest(String JavaDoc testName) {
47         super(testName);
48     }
49     
50     public static void main(java.lang.String JavaDoc[] args) {
51         junit.textui.TestRunner.run(suite());
52     }
53
54     protected void setUp() throws Exception JavaDoc {
55     }
56
57     protected void tearDown() throws Exception JavaDoc {
58     }
59
60     public static Test suite() {
61         TestSuite suite = new TestSuite(NavigatorControllerTest.class);
62         return suite;
63     }
64
65     public void testObtainProviders() throws Exception JavaDoc {
66         System.out.println("Testing NavigatorController.obtainProviders");
67         UnitTestUtils.prepareTest(new String JavaDoc [] { "/org/netbeans/modules/navigator/resources/NavigatorControllerTestProvider.xml" });
68         URL JavaDoc url = NavigatorControllerTest.class.getResource("resources/sample_folder/subfolder1/subfolder2");
69         assertNotNull("url not found.", url);
70
71         FileUtil.setMIMEType("my_extension", "NavigatorControllerTest/TestMimeType");
72         FileObject fo = URLMapper.findFileObject(url);
73         FileObject[] fos = fo.getChildren();
74         fo = fo.getFileObject("Nic.my_extension");
75         assertNotNull("fo not found.", fo);
76         
77         FileObject foSubFolder1 = fo.getParent().getParent();
78         FileObject foSampleFolder = foSubFolder1.getParent();
79         DataObject dObj = DataObject.find(fo);
80         DataFolder subFolder1 = (DataFolder)DataObject.find(foSubFolder1);
81         DataFolder sampleFolder = (DataFolder)DataObject.find(foSampleFolder);
82         DataShadow shadow1 = DataShadow.create(subFolder1, dObj);
83         DataShadow shadow2 = DataShadow.create(sampleFolder, shadow1);
84         
85         System.out.println("Testing DataShadow resolvement...");
86         // not really valid, uses impl fact that during obtainProviders,
87
// NavigatorTC parameter will not be needed.
88
NavigatorController nc = new NavigatorController(null);
89         List JavaDoc result = nc.obtainProviders(shadow1.getNodeDelegate());
90         assertNotNull("provider not found", result);
91         assertEquals(1, result.size());
92         assertTrue(result.get(0) instanceof TestJavaNavigatorPanel);
93         
94         result = nc.obtainProviders(shadow2.getNodeDelegate());
95         assertNotNull("provider not found", result);
96         assertEquals(1, result.size());
97         assertTrue(result.get(0) instanceof TestJavaNavigatorPanel);
98     }
99
100     /** Dummy navigator panel provider, just for testing
101      */

102     public static final class TestJavaNavigatorPanel implements NavigatorPanel {
103         
104         public String JavaDoc getDisplayName () {
105             return JAVA_DATA_TYPE;
106         }
107     
108         public String JavaDoc getDisplayHint () {
109             return null;
110         }
111
112         public JComponent JavaDoc getComponent () {
113             return null;
114         }
115
116         public void panelActivated (Lookup context) {
117         }
118
119         public void panelDeactivated () {
120         }
121         
122         public Lookup getLookup () {
123             return null;
124         }
125         
126     }
127     
128             
129             
130     
131 }
132
Popular Tags