alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.core.registry;

import junit.textui.TestRunner;
import org.netbeans.api.registry.Context;
import org.netbeans.api.registry.fs.FileSystemContextFactory;
import org.netbeans.junit.NbTestCase;
import org.netbeans.junit.NbTestSuite;
import org.netbeans.spi.registry.BasicContext;
import org.netbeans.spi.registry.SpiUtils;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.XMLFileSystem;

import java.net.URL;
import java.util.Collection;
import java.util.Iterator;

public class OrderingTest extends NbTestCase {
    
    private FileObject root = null;
    
    public OrderingTest(String name) {
        super (name);
    }
    
    public static void main(String[] args) {
        TestRunner.run(new NbTestSuite(OrderingTest.class));
    }
    
    protected void setUp () throws Exception {
    }
    
    public void testDefaultOrdering() throws Exception {
        URL u1 = getClass().getResource("data/layer1.xml");
        URL u2 = getClass().getResource("data/layer2.xml");
               
        FileSystem xfs1 = new XMLFileSystem( u1 );
        FileSystem xfs2 = new XMLFileSystem( u2 );        
        FileSystem mfs = new TestMFS( new FileSystem[] { xfs1, xfs2 } );
    
        BasicContext rootCtx = FileSystemContextFactory.createContext(mfs.getRoot());
        Context cotoxo = SpiUtils.createContext(rootCtx);
        Context ctx = cotoxo.getSubcontext("folder1");
        Collection c = ctx.getOrderedNames();
        Iterator it = c.iterator();
        String[] arr = new String[]{"fileA", "file1", "fileB/", "file2", "fileC", "file3/", "fileD", "file4" };
        int i=0;
        while (it.hasNext()) {
            String name = (String)it.next();
            assertEquals("They must be the same", arr[i], name);
            i++;
        }
        
        ctx = cotoxo.getSubcontext("folder2");
        c = ctx.getOrderedNames();
        System.err.println("c="+c);
        it = c.iterator();
        i=0;
        while (it.hasNext()) {
            String name = (String)it.next();
            assertEquals("They must be the same", arr[i], name);
            i++;
        }

        ctx = cotoxo.getSubcontext("folder3");
        c = ctx.getOrderedNames();
        it = c.iterator();
        i=0;
        while (it.hasNext()) {
            String name = (String)it.next();
            assertEquals("They must be the same", arr[i], name);
            i++;
        }
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.