1 19 20 package org.netbeans.core.registry; 21 22 import junit.textui.TestRunner; 23 import org.netbeans.api.registry.Context; 24 import org.netbeans.api.registry.fs.FileSystemContextFactory; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.junit.NbTestSuite; 27 import org.netbeans.spi.registry.BasicContext; 28 import org.netbeans.spi.registry.SpiUtils; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileSystem; 31 import org.openide.filesystems.XMLFileSystem; 32 33 import java.net.URL ; 34 import java.util.Collection ; 35 import java.util.Iterator ; 36 37 public class OrderingTest extends NbTestCase { 38 39 private FileObject root = null; 40 41 public OrderingTest(String name) { 42 super (name); 43 } 44 45 public static void main(String [] args) { 46 TestRunner.run(new NbTestSuite(OrderingTest.class)); 47 } 48 49 protected void setUp () throws Exception { 50 } 51 52 public void testDefaultOrdering() throws Exception { 53 URL u1 = getClass().getResource("data/layer1.xml"); 54 URL u2 = getClass().getResource("data/layer2.xml"); 55 56 FileSystem xfs1 = new XMLFileSystem( u1 ); 57 FileSystem xfs2 = new XMLFileSystem( u2 ); 58 FileSystem mfs = new TestMFS( new FileSystem[] { xfs1, xfs2 } ); 59 60 BasicContext rootCtx = FileSystemContextFactory.createContext(mfs.getRoot()); 61 Context cotoxo = SpiUtils.createContext(rootCtx); 62 Context ctx = cotoxo.getSubcontext("folder1"); 63 Collection c = ctx.getOrderedNames(); 64 Iterator it = c.iterator(); 65 String [] arr = new String []{"fileA", "file1", "fileB/", "file2", "fileC", "file3/", "fileD", "file4" }; 66 int i=0; 67 while (it.hasNext()) { 68 String name = (String )it.next(); 69 assertEquals("They must be the same", arr[i], name); 70 i++; 71 } 72 73 ctx = cotoxo.getSubcontext("folder2"); 74 c = ctx.getOrderedNames(); 75 System.err.println("c="+c); 76 it = c.iterator(); 77 i=0; 78 while (it.hasNext()) { 79 String name = (String )it.next(); 80 assertEquals("They must be the same", arr[i], name); 81 i++; 82 } 83 84 ctx = cotoxo.getSubcontext("folder3"); 85 c = ctx.getOrderedNames(); 86 it = c.iterator(); 87 i=0; 88 while (it.hasNext()) { 89 String name = (String )it.next(); 90 assertEquals("They must be the same", arr[i], name); 91 i++; 92 } 93 } 94 95 } 96 | Popular Tags |