1 19 20 package org.netbeans.modules.settings.convertors; 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 InstanceDataObjectCopyTest extends org.netbeans.junit.NbTestCase { 47 private FileObject fo; 48 49 50 public InstanceDataObjectCopyTest (String testName) { 51 super (testName); 52 } 53 54 protected void setUp () throws java.lang.Exception { 55 clearWorkDir (); 56 Lookup.getDefault().lookup(ModuleInfo.class); 57 58 } 59 60 public void testSettingsFileOnNonSFSAfterCopyShouldHaveEditor () throws Exception { 61 doSettingsFileOnNonSFSAfterCopyShouldHaveEditor (true); 62 } 63 public void testSettingsFileOnNonSFSAfterCreateFTShouldHaveEditor () throws Exception { 64 doSettingsFileOnNonSFSAfterCopyShouldHaveEditor (false); 65 } 66 67 private void doSettingsFileOnNonSFSAfterCopyShouldHaveEditor (boolean copy) throws Exception { 68 clearWorkDir (); 69 LocalFileSystem lfs = new LocalFileSystem (); 70 lfs.setRootDirectory (getWorkDir ()); 71 72 FileObject set = createSettings (lfs.getRoot (), "x.settings"); 73 DataObject old = DataObject.find (set); 74 Date d = set.lastModified(); 75 76 InstanceCookie ic = (InstanceCookie)old.getCookie(InstanceCookie.class); 77 assertNotNull ("The cookie is there", ic); 78 Object instance = ic.instanceCreate(); 79 assertNotNull ("It produces a result", instance); 80 assertEquals ("It is Button", Button .class, instance.getClass ()); 81 82 FileObject tgt = FileUtil.createFolder(lfs.getRoot (), "moved"); 83 DataFolder fld = DataFolder.findFolder (tgt); 84 85 DataObject obj = copy ? old.copy (fld) : old.createFromTemplate(fld); 86 87 assertEquals ("No change in modifications", d, set.lastModified()); 88 assertEquals ("The same name", obj.getPrimaryFile().getNameExt (), set.getNameExt()); 89 90 assertEquals (InstanceDataObject.class, obj.getClass ()); 91 assertNotNull ("It has edit cookie", obj.getCookie (EditCookie.class)); 92 assertNotNull ("It has open cookie", obj.getCookie (OpenCookie.class)); 93 assertNotNull ("It has editor cookie", obj.getCookie (EditorCookie.class)); 94 95 Object o = obj.getNodeDelegate ().getPreferredAction (); 96 Class c = o == null ? Object .class : o.getClass (); 97 98 assertEquals ("Default actions should be open on non-SFS", org.openide.actions.OpenAction.class, c); 99 } 100 101 private FileObject createSettings (FileObject root, String name) throws IOException { 102 FileObject set = FileUtil.createData (root, name); 103 104 FileLock lock = set.lock (); 105 PrintStream os = new PrintStream (set.getOutputStream (lock)); 106 107 os.println ("<?xml version=\"1.0\"?>"); 108 os.println ("<!DOCTYPE settings PUBLIC \"-//NetBeans//DTD Session settings 1.0//EN\" \"http://www.netbeans.org/dtds/sessionsettings-1_0.dtd\">"); 109 os.println ("<settings version=\"1.0\">"); 110 os.println ("<instanceof class=\"java.io.Serializable\"/>"); 112 os.println ("<instanceof class=\"java.lang.Object\"/>"); 113 os.println ("<instanceof class=\"java.awt.Component\"/>"); 114 os.println ("<instance class=\"java.awt.Button\"/>"); 115 os.println ("</settings>"); 116 117 os.close (); 118 lock.releaseLock(); 119 return set; 120 } 121 } 122 | Popular Tags |