1 19 20 package org.netbeans.modules.navigator; 21 22 import java.io.File ; 23 import java.net.URL ; 24 import java.util.List ; 25 import javax.swing.JComponent ; 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 41 public class NavigatorControllerTest extends TestCase { 42 43 private static final String JAVA_DATA_TYPE = "text/marvelous/data_type"; 44 45 46 public NavigatorControllerTest(String testName) { 47 super(testName); 48 } 49 50 public static void main(java.lang.String [] args) { 51 junit.textui.TestRunner.run(suite()); 52 } 53 54 protected void setUp() throws Exception { 55 } 56 57 protected void tearDown() throws Exception { 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 { 66 System.out.println("Testing NavigatorController.obtainProviders"); 67 UnitTestUtils.prepareTest(new String [] { "/org/netbeans/modules/navigator/resources/NavigatorControllerTestProvider.xml" }); 68 URL 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 NavigatorController nc = new NavigatorController(null); 89 List 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 102 public static final class TestJavaNavigatorPanel implements NavigatorPanel { 103 104 public String getDisplayName () { 105 return JAVA_DATA_TYPE; 106 } 107 108 public String getDisplayHint () { 109 return null; 110 } 111 112 public JComponent 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 |