samples/unionfs/test/org/apidesign/unionfs/UnionFSTest.java
changeset 135 6a66df28018c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/unionfs/test/org/apidesign/unionfs/UnionFSTest.java	Sat Jun 14 09:56:56 2008 +0200
     1.3 @@ -0,0 +1,65 @@
     1.4 +package org.apidesign.unionfs;
     1.5 +
     1.6 +import java.util.Arrays;
     1.7 +import java.util.HashSet;
     1.8 +import java.util.Set;
     1.9 +import org.junit.After;
    1.10 +import org.junit.AfterClass;
    1.11 +import org.junit.Before;
    1.12 +import org.junit.BeforeClass;
    1.13 +import org.junit.Test;
    1.14 +import org.openide.filesystems.FileObject;
    1.15 +import static org.junit.Assert.*;
    1.16 +import org.openide.filesystems.FileSystem;
    1.17 +import org.xml.sax.SAXException;
    1.18 +
    1.19 +public class UnionFSTest {
    1.20 +
    1.21 +    public UnionFSTest() {
    1.22 +    }
    1.23 +
    1.24 +    @BeforeClass
    1.25 +    public static void setUpClass() throws Exception {
    1.26 +    }
    1.27 +
    1.28 +    @AfterClass
    1.29 +    public static void tearDownClass() throws Exception {
    1.30 +    }
    1.31 +
    1.32 +    @Before
    1.33 +    public void setUp() {
    1.34 +    }
    1.35 +
    1.36 +    @After
    1.37 +    public void tearDown() {
    1.38 +    }
    1.39 +
    1.40 +    @Test
    1.41 +    public void union() throws SAXException {
    1.42 +        FileSystem one = UnionFS.fromResource(UnionFSTest.class.getResource("fs-one.xml"));
    1.43 +        assertChildren("There is just one file in the folder", one, "Menu", "Open.instance");
    1.44 +        
    1.45 +        FileSystem two = UnionFS.fromResource(UnionFSTest.class.getResource("fs-two.xml"));
    1.46 +        assertChildren("There is just one file in the other folder", two, "Menu", "Close.instance");
    1.47 +        
    1.48 +        FileSystem union = UnionFS.union(one, two);
    1.49 +        assertChildren("There both in the union", union, "Menu", "Open.instance", "Close.instance");
    1.50 +    }
    1.51 +
    1.52 +    private static void assertChildren(String msg, FileSystem fs, String folder, String... expect) {
    1.53 +        Set<String> names = new HashSet<String>();
    1.54 +        names.addAll(Arrays.asList(expect));
    1.55 +        
    1.56 +        FileObject fo = fs.getRoot().getFileObject(folder);
    1.57 +        assertNotNull(msg + " folder " + folder + " has to exist", fo);
    1.58 +        
    1.59 +        for (FileObject ch : fo.getChildren()) {
    1.60 +            names.remove(ch.getNameExt());
    1.61 +        }
    1.62 +
    1.63 +        if (!names.isEmpty()) {
    1.64 +            fail(msg + " - expected files not found " + names);
    1.65 +        }
    1.66 +    }
    1.67 +
    1.68 +}
    1.69 \ No newline at end of file