KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > registry > OrderingTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
34 import java.util.Collection JavaDoc;
35 import java.util.Iterator JavaDoc;
36
37 public class OrderingTest extends NbTestCase {
38     
39     private FileObject root = null;
40     
41     public OrderingTest(String JavaDoc name) {
42         super (name);
43     }
44     
45     public static void main(String JavaDoc[] args) {
46         TestRunner.run(new NbTestSuite(OrderingTest.class));
47     }
48     
49     protected void setUp () throws Exception JavaDoc {
50     }
51     
52     public void testDefaultOrdering() throws Exception JavaDoc {
53         URL JavaDoc u1 = getClass().getResource("data/layer1.xml");
54         URL JavaDoc 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 JavaDoc c = ctx.getOrderedNames();
64         Iterator JavaDoc it = c.iterator();
65         String JavaDoc[] arr = new String JavaDoc[]{"fileA", "file1", "fileB/", "file2", "fileC", "file3/", "fileD", "file4" };
66         int i=0;
67         while (it.hasNext()) {
68             String JavaDoc name = (String JavaDoc)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 JavaDoc name = (String JavaDoc)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 JavaDoc name = (String JavaDoc)it.next();
90             assertEquals("They must be the same", arr[i], name);
91             i++;
92         }
93     }
94     
95 }
96
Popular Tags