1 19 20 package org.openide.loaders; 21 22 import java.awt.Button ; 23 import java.util.Date ; 24 import junit.framework.*; 25 import java.io.*; 26 import java.util.Enumeration ; 27 import java.util.HashSet ; 28 import java.util.Set ; 29 import java.util.StringTokenizer ; 30 import org.openide.*; 31 import org.openide.cookies.*; 32 import org.openide.filesystems.*; 33 import org.openide.filesystems.FileSystem; 34 import org.openide.loaders.*; 35 import org.openide.modules.ModuleInfo; 36 import org.openide.util.*; 37 import org.openide.util.Utilities; 38 import org.openide.util.actions.*; 39 import org.openide.nodes.*; 40 import java.util.List ; 41 42 46 public class InstanceDataObjectHasEditorTest extends org.netbeans.junit.NbTestCase { 47 private FileObject fo; 48 49 50 public InstanceDataObjectHasEditorTest (String testName) { 51 super (testName); 52 } 53 54 protected void setUp () throws java.lang.Exception { 55 clearWorkDir (); 56 57 Lookup.getDefault().lookup(ModuleInfo.class); 59 } 60 61 public void testSettingsFileOnSFSShouldHaveEditor () throws Exception { 62 FileObject set = createSettings (Repository.getDefault ().getDefaultFileSystem ().getRoot (), "x.settings"); 63 DataObject obj = DataObject.find (set); 64 assertEquals (InstanceDataObject.class, obj.getClass ()); 65 assertNull ("It does not have edit cookie", obj.getCookie (EditCookie.class)); 66 assertNull ("It does not have open cookie", obj.getCookie (OpenCookie.class)); 67 assertNull ("It does not have editor cookie", obj.getCookie (EditorCookie.class)); 68 69 Object o = obj.getNodeDelegate ().getPreferredAction (); 70 Class c = o == null ? Object .class : o.getClass (); 71 72 if (c == org.openide.actions.OpenAction.class) { 73 fail ("Default actions should not be open on SFS: " + o); 74 } 75 } 76 77 public void testSettingsFileOnNonSFSShouldHaveEditor () throws Exception { 78 clearWorkDir (); 79 LocalFileSystem lfs = new LocalFileSystem (); 80 lfs.setRootDirectory (getWorkDir ()); 81 82 FileObject set = createSettings (lfs.getRoot (), "x.settings"); 83 DataObject obj = DataObject.find (set); 84 assertEquals (InstanceDataObject.class, obj.getClass ()); 85 assertNotNull ("It has edit cookie", obj.getCookie (EditCookie.class)); 86 assertNotNull ("It has open cookie", obj.getCookie (OpenCookie.class)); 87 assertNotNull ("It has editor cookie", obj.getCookie (EditorCookie.class)); 88 89 Object o = obj.getNodeDelegate ().getPreferredAction (); 90 Class c = o == null ? Object .class : o.getClass (); 91 92 assertEquals ("Default actions should be open on non-SFS", org.openide.actions.OpenAction.class, c); 93 } 94 95 public void testSettingsFileOnNonSFSAfterCopyShouldHaveEditor () throws Exception { 96 clearWorkDir (); 97 LocalFileSystem lfs = new LocalFileSystem (); 98 lfs.setRootDirectory (getWorkDir ()); 99 100 FileObject set = createSettings (lfs.getRoot (), "x.settings"); 101 DataObject old = DataObject.find (set); 102 Date d = set.lastModified(); 103 104 111 112 FileObject tgt = FileUtil.createFolder(lfs.getRoot (), "moved"); 113 DataFolder fld = DataFolder.findFolder (tgt); 114 115 DataObject obj = old.copy (fld); 116 117 assertEquals ("No change in modifications", d, set.lastModified()); 118 assertEquals ("The same name", obj.getPrimaryFile().getNameExt (), set.getNameExt()); 119 120 assertEquals (InstanceDataObject.class, obj.getClass ()); 121 assertNotNull ("It has edit cookie", obj.getCookie (EditCookie.class)); 122 assertNotNull ("It has open cookie", obj.getCookie (OpenCookie.class)); 123 assertNotNull ("It has editor cookie", obj.getCookie (EditorCookie.class)); 124 125 Object o = obj.getNodeDelegate ().getPreferredAction (); 126 Class c = o == null ? Object .class : o.getClass (); 127 128 assertEquals ("Default actions should be open on non-SFS", org.openide.actions.OpenAction.class, c); 129 } 130 131 private FileObject createSettings (FileObject root, String name) throws IOException { 132 FileObject set = FileUtil.createData (root, name); 133 134 FileLock lock = set.lock (); 135 PrintStream os = new PrintStream (set.getOutputStream (lock)); 136 137 os.println ("<?xml version=\"1.0\"?>"); 138 os.println ("<!DOCTYPE settings PUBLIC \"-//NetBeans//DTD Session settings 1.0//EN\" \"http://www.netbeans.org/dtds/sessionsettings-1_0.dtd\">"); 139 os.println ("<settings version=\"1.0\">"); 140 os.println ("<instanceof class=\"java.io.Serializable\"/>"); 142 os.println ("<instanceof class=\"java.lang.Object\"/>"); 143 os.println ("<instanceof class=\"java.awt.Component\"/>"); 144 os.println ("<instance class=\"java.awt.Button\"/>"); 145 os.println ("</settings>"); 146 147 os.close (); 148 lock.releaseLock(); 149 return set; 150 } 151 } 152 | Popular Tags |