1 19 20 package org.openide.loaders; 21 22 import java.util.Enumeration ; 23 import junit.framework.TestCase; 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.FileUtil; 26 import org.openide.filesystems.Repository; 27 28 32 public class DataFolderCopyMoreWindowsLikeTest extends TestCase { 33 DataFolder target; 34 DataFolder source; 35 DataFolder sub; 36 37 public DataFolderCopyMoreWindowsLikeTest(String testName) { 38 super (testName); 39 } 40 41 protected void setUp() throws Exception { 42 FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot (); 43 FileObject[] arr = root.getChildren (); 44 for (int i = 0; i < arr.length; i++) { 45 arr[i].delete (); 46 } 47 48 target = DataFolder.findFolder (FileUtil.createFolder (root, "Target")); 49 source = DataFolder.findFolder (FileUtil.createFolder (root, "Source")); 50 sub = DataFolder.findFolder (FileUtil.createFolder (root, "Source/Sub/")); 51 FileUtil.createData (root, "Source/Sub/A.txt"); 52 } 53 54 public void testCopyIntoTheSameFolderCreatesFolderNamed2 () throws Exception { 55 sub.copy (source); 56 57 assertFO ("Sibling to Sub created", "/Source/Sub_1/A.txt"); 58 } 59 60 public void testCopyIntoDifferentEmptyFolderIsWithotuRenames () throws Exception { 61 sub.copy (target); 62 63 assertFO ("A.txt name preserved", "/Target/Sub/A.txt"); 64 } 65 66 public void testCopyIntoDifferentNonEmptyFolderCreatesSibling () throws Exception { 67 FileUtil.createData (Repository.getDefault ().getDefaultFileSystem ().getRoot(), "Target/Sub/A.txt"); 68 69 sub.copy (target); 70 71 assertFO ("A_1.txt sibling created", "/Target/Sub/A_1.txt"); 72 } 73 74 public void testMoveIntoTheSameFolderIsForbiden() throws Exception { 75 FileObject old = source.getPrimaryFile (); 76 77 sub.move (source); 78 79 assertEquals ("No change", old, source.getPrimaryFile ()); 80 } 81 82 private static void assertFO (String msg, String name) { 83 FileObject fo = Repository.getDefault ().getDefaultFileSystem ().findResource (name); 84 if (fo == null) { 85 StringBuffer sb = new StringBuffer (msg); 86 sb.append (" - cannot find "); 87 sb.append (name); 88 Enumeration en = Repository.getDefault ().getDefaultFileSystem ().getRoot ().getChildren (true); 89 while (en.hasMoreElements ()) { 90 sb.append ('\n'); 91 sb.append (" "); 92 sb.append (en.nextElement ()); 93 } 94 fail (sb.toString ()); 95 } 96 } 97 98 } 99 | Popular Tags |