1 19 20 package org.openide.loaders; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import junit.extensions.*; 25 import junit.textui.TestRunner; 26 27 import org.openide.filesystems.*; 28 import junit.framework.*; 29 import org.netbeans.junit.*; 30 import java.io.IOException ; 31 import org.openide.loaders.DataLoader.RecognizedFiles; 32 import org.openide.nodes.Node; 33 import java.lang.ref.WeakReference ; 34 import java.io.*; 35 import java.util.*; 36 import java.beans.PropertyVetoException ; 37 import javax.swing.event.ChangeListener ; 38 import javax.swing.event.ChangeEvent ; 39 import org.openide.*; 40 import org.openide.util.Enumerations; 41 import org.openide.util.HelpCtx; 42 import org.openide.util.RequestProcessor; 43 import org.openide.nodes.CookieSet; 44 45 48 public class RejectOnCopyCreatesDefaultTest extends LoggingTestCaseHid { 49 FileSystem fs; 50 DataObject one; 51 DataFolder from; 52 DataFolder to; 53 ErrorManager err; 54 55 56 57 public RejectOnCopyCreatesDefaultTest (String name) { 58 super (name); 59 } 60 61 public void setUp() throws Exception { 62 clearWorkDir(); 63 64 SimpleLoader.active = true; 65 66 super.setUp(); 67 68 registerIntoLookup(new Pool()); 69 70 err = ErrorManager.getDefault().getInstance("TEST-" + getName()); 71 72 LocalFileSystem lfs = new LocalFileSystem(); 73 lfs.setRootDirectory(getWorkDir()); 74 fs = lfs; 75 FileUtil.createData(fs.getRoot(), "from/x.prima"); 76 FileUtil.createFolder(fs.getRoot(), "to/"); 77 78 one = DataObject.find(fs.findResource("from/x.prima")); 79 assertEquals(MultiDataObject.class, one.getClass()); 80 assertEquals(SimpleLoader.getLoader(SimpleLoader.class), one.getLoader()); 81 82 from = one.getFolder(); 83 to = DataFolder.findFolder(fs.findResource("to/")); 84 85 assertEquals("Nothing there", 0, to.getPrimaryFile().getChildren().length); 86 } 87 88 public void testCopyAndSee() throws Exception { 89 90 SimpleLoader.active = false; 91 92 DataObject copy = one.copy(to); 93 94 if (copy.getLoader() == one.getLoader()) { 95 fail("Loaders shall be different:\n" + one + "\nand:\n" + copy); 96 } 97 } 98 99 private static class Pool extends DataLoaderPool { 100 protected Enumeration loaders() { 101 return Enumerations.singleton(SimpleLoader.getLoader(SimpleLoader.class)); 102 } 103 } 104 105 public static final class SimpleLoader extends MultiFileLoader { 106 public SimpleLoader() { 107 super(MultiDataObject.class.getName()); 108 } 109 protected String displayName() { 110 return "SimpleLoader"; 111 } 112 113 public static boolean active = true; 114 115 protected FileObject findPrimaryFile(FileObject fo) { 116 if (!fo.isFolder() && active) { 117 return fo.hasExt("prima") ? fo : null; 118 } 119 return null; 120 } 121 protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { 122 return new MultiDataObject(primaryFile, this); 123 } 124 protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) { 125 return new FileEntry(obj, primaryFile); 126 } 127 protected MultiDataObject.Entry createSecondaryEntry(MultiDataObject obj, FileObject secondaryFile) { 128 return new FileEntry(obj, secondaryFile); 129 } 130 } 131 } 132 | Popular Tags |