1 19 20 package org.openide.loaders; 21 22 import junit.textui.TestRunner; 23 24 import org.openide.filesystems.*; 25 import java.io.IOException ; 26 import java.util.*; 27 import org.netbeans.junit.*; 28 29 34 public class MultiDataObjectFilesTest extends NbTestCase { 35 36 public MultiDataObjectFilesTest(String name) { 37 super(name); 38 } 39 40 public void testFilesSet () throws Exception { 41 DataLoader loader = DataLoader.getLoader(SimpleLoader.class); 42 AddLoaderManuallyHid.addRemoveLoader(loader, true); 43 44 45 String [] fsstruct = new String [] { 47 "A.primary", "A.a", "A.b", 48 "B.x0", "B.zx", "B.secondary", 49 "C.a0", "C.a5", "C.a1", "C.a4", 50 "A.primary0", "A.secondary", "A.zx", "A.x0", 51 "C.a2", "C.a3", "C.primary", 52 "B.primary", "B.b", "B.primary0", "B.a" 53 }; 54 55 TestUtilHid.destroyLocalFileSystem(getName()); 57 FileSystem fs = TestUtilHid.createLocalFileSystem(getWorkDir(), fsstruct); 58 59 DataFolder folder = DataFolder.findFolder(fs.getRoot()); 60 61 DataObject[] children = folder.getChildren(); 62 assertTrue ("DataObjects were not recognized correctly.", children.length == 3); 63 for (int i = 0; i < children.length; i++) { 64 DataObject obj = children[i]; 65 Set files = obj.files(); 66 67 Iterator it = files.iterator(); 68 FileObject primary = (FileObject) it.next(); 69 assertEquals("Primary file is not returned first for "+obj.getName(), primary, obj.getPrimaryFile()); 70 71 FileObject last = null; 72 while (it.hasNext()) { 73 FileObject current = (FileObject) it.next(); 74 if (last != null) { 75 assertTrue("FileObjects are not alphabetically", last.getNameExt().compareTo(current.getNameExt()) < 0); 76 } 77 last = current; 78 } 79 } 80 81 TestUtilHid.destroyLocalFileSystem(getName()); 82 } 83 84 public static final class SimpleLoader extends MultiFileLoader { 85 public SimpleLoader() { 86 super(SimpleObject.class); 87 } 88 protected String displayName() { 89 return "SimpleLoader"; 90 } 91 protected FileObject findPrimaryFile(FileObject fo) { 92 if (!fo.isFolder()) { 93 return fo.hasExt("primary") ? fo : FileUtil.findBrother(fo, "primary"); 94 } 95 return null; 96 } 97 protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { 98 return new SimpleObject(this, primaryFile); 99 } 100 protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) { 101 return new FileEntry(obj, primaryFile); 102 } 103 protected MultiDataObject.Entry createSecondaryEntry(MultiDataObject obj, FileObject secondaryFile) { 104 return new FileEntry(obj, secondaryFile); 105 } 106 } 107 108 public static final class SimpleObject extends MultiDataObject { 109 public SimpleObject(SimpleLoader l, FileObject fo) throws DataObjectExistsException { 110 super(fo, l); 111 } 112 } 113 114 } 115 | Popular Tags |