KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > filesystems > MultiFileSystemMaskTest


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.openide.filesystems;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import org.netbeans.junit.NbTestCase;
27
28 // XXX should only *unused* mask files be listed when propagateMasks?
29
// XXX write similar test for ParsingLayerCacheManager (simulate propagateMasks)
30

31 /**
32  * Test that MultiFileSystem can mask files correctly.
33  * @author Jesse Glick
34  */

35 public class MultiFileSystemMaskTest extends NbTestCase {
36
37     public MultiFileSystemMaskTest(String JavaDoc name) {
38         super(name);
39     }
40
41     // XXX use this!
42
private static String JavaDoc childrenNames(FileSystem fs) {
43         FileObject folder = fs.findResource("folder");
44         return childrenNames(folder);
45     }
46     
47     private static String JavaDoc childrenNames(FileObject folder) {
48         FileObject[] kids = folder.getChildren();
49         List JavaDoc<String JavaDoc> l = new ArrayList JavaDoc<String JavaDoc>();
50         for (int i = 0; i < kids.length; i++) {
51             l.add(kids[i].getNameExt());
52         }
53         Collections.sort(l);
54         StringBuffer JavaDoc b = new StringBuffer JavaDoc();
55         Iterator JavaDoc i = l.iterator();
56         if (i.hasNext()) {
57             b.append(i.next());
58             while (i.hasNext()) {
59                 b.append('/');
60                 b.append(i.next());
61             }
62         }
63         return b.toString();
64     }
65     
66     /**
67      * Check that you can use one mask for more than one instance of a masked file.
68      */

69     public void testRepeatedMasks() throws Exception JavaDoc {
70         MultiFileSystem fs = new MultiFileSystem(new FileSystem[] {
71             TestUtilHid.createXMLFileSystem(getName() + "1", new String JavaDoc[] {
72                 "folder/file1_hidden",
73                 "folder/file2_hidden",
74             }),
75             TestUtilHid.createXMLFileSystem(getName() + "2", new String JavaDoc[] {
76                 "folder/file1",
77                 "folder/file2",
78             }),
79             TestUtilHid.createXMLFileSystem(getName() + "3", new String JavaDoc[] {
80                 "folder/file1",
81                 "folder/file3",
82             }),
83         });
84         fs.setPropagateMasks(false);
85         try {
86             assertEquals("folder/file1_hidden masked two occurrences of folder/file1 and folder/file2_hidden masked one occurrence of folder/file2",
87                 "file3",
88                 childrenNames(fs));
89         } finally {
90             TestUtilHid.destroyXMLFileSystem(getName() + "1");
91             TestUtilHid.destroyXMLFileSystem(getName() + "2");
92             TestUtilHid.destroyXMLFileSystem(getName() + "3");
93         }
94     }
95     public void testRepeatedMasksPropagate() throws Exception JavaDoc {
96         MultiFileSystem fs = new MultiFileSystem(new FileSystem[] {
97             TestUtilHid.createXMLFileSystem(getName() + "1", new String JavaDoc[] {
98                 "folder/file1_hidden",
99                 "folder/file2_hidden",
100             }),
101             TestUtilHid.createXMLFileSystem(getName() + "2", new String JavaDoc[] {
102                 "folder/file1",
103                 "folder/file2",
104             }),
105             TestUtilHid.createXMLFileSystem(getName() + "3", new String JavaDoc[] {
106                 "folder/file1",
107                 "folder/file3",
108             }),
109         });
110         fs.setPropagateMasks(true);
111         try {
112             assertEquals("folder/file1_hidden masked two occurrences of folder/file1 and folder/file2_hidden masked one occurrence of folder/file2",
113                 "file1_hidden/file2_hidden/file3",
114                 childrenNames(fs));
115         } finally {
116             TestUtilHid.destroyXMLFileSystem(getName() + "1");
117             TestUtilHid.destroyXMLFileSystem(getName() + "2");
118             TestUtilHid.destroyXMLFileSystem(getName() + "3");
119         }
120     }
121     
122     /**
123      * Check that a mask must precede the masked file in the delegates list.
124      */

125     public void testOutOfOrderMasks() throws Exception JavaDoc {
126         MultiFileSystem fs = new MultiFileSystem(new FileSystem[] {
127             TestUtilHid.createXMLFileSystem(getName() + "1", new String JavaDoc[] {
128                 "folder/file1",
129                 "folder/file2",
130             }),
131             TestUtilHid.createXMLFileSystem(getName() + "2", new String JavaDoc[] {
132                 "folder/file2_hidden",
133                 "folder/file3_hidden",
134             }),
135             TestUtilHid.createXMLFileSystem(getName() + "3", new String JavaDoc[] {
136                 "folder/file3",
137             }),
138         });
139         fs.setPropagateMasks(false);
140         try {
141             assertEquals("folder/file2_hidden did not mask an earlier file but folder/file3_hidden masked a later one",
142                 "file1/file2",
143                 childrenNames(fs));
144         } finally {
145             TestUtilHid.destroyXMLFileSystem(getName() + "1");
146             TestUtilHid.destroyXMLFileSystem(getName() + "2");
147             TestUtilHid.destroyXMLFileSystem(getName() + "3");
148         }
149     }
150     /* XXX never passed, not clear if it should anyway:
151     public void testOutOfOrderMasksPropagate() throws Exception {
152         MultiFileSystem fs = new MultiFileSystem(new FileSystem[] {
153             TestUtilHid.createXMLFileSystem(getName() + "1", new String[] {
154                 "folder/file1",
155                 "folder/file2",
156             }),
157             TestUtilHid.createXMLFileSystem(getName() + "2", new String[] {
158                 "folder/file2_hidden",
159                 "folder/file3_hidden",
160             }),
161             TestUtilHid.createXMLFileSystem(getName() + "3", new String[] {
162                 "folder/file3",
163             }),
164         });
165         fs.setPropagateMasks(true);
166         try {
167             System.err.println("tOOOMP: " + childrenNames(fs));//XXX
168             assertEquals("folder/file2_hidden did not mask an earlier file but folder/file3_hidden masked a later one",
169                 "file1/file2/file2_hidden/file3_hidden",
170                 childrenNames(fs));
171         } finally {
172             TestUtilHid.destroyXMLFileSystem(getName() + "1");
173             TestUtilHid.destroyXMLFileSystem(getName() + "2");
174             TestUtilHid.destroyXMLFileSystem(getName() + "3");
175         }
176     }
177      */

178     
179     /**
180      * Check that a mask cannot be parallel to the masked file in the delegates list.
181      */

182     public void testParallelMasks() throws Exception JavaDoc {
183         MultiFileSystem fs = new MultiFileSystem(new FileSystem[] {
184             TestUtilHid.createXMLFileSystem(getName() + "1", new String JavaDoc[] {
185                 "folder/file1",
186             }),
187             TestUtilHid.createXMLFileSystem(getName() + "2", new String JavaDoc[] {
188                 "folder/file2",
189                 "folder/file2_hidden",
190                 "folder/file3",
191             }),
192         });
193         fs.setPropagateMasks(false);
194         try {
195             assertEquals("folder/file2_hidden does not mask a file from the same layer",
196                 "file1/file2/file3",
197                 childrenNames(fs));
198         } finally {
199             TestUtilHid.destroyXMLFileSystem(getName() + "1");
200             TestUtilHid.destroyXMLFileSystem(getName() + "2");
201         }
202     }
203     /* XXX never passed, not clear if it should anyway:
204     public void testParallelMasksPropagate() throws Exception {
205         MultiFileSystem fs = new MultiFileSystem(new FileSystem[] {
206             TestUtilHid.createXMLFileSystem(getName() + "1", new String[] {
207                 "folder/file1",
208             }),
209             TestUtilHid.createXMLFileSystem(getName() + "2", new String[] {
210                 "folder/file2",
211                 "folder/file2_hidden",
212                 "folder/file3",
213             }),
214         });
215         fs.setPropagateMasks(true);
216         try {
217             System.err.println("tPMP: " + childrenNames(fs));//XXX
218             assertEquals("folder/file2_hidden does not mask a file from the same layer",
219                 "file1/file2/file2_hidden/file3",
220                 childrenNames(fs));
221         } finally {
222             TestUtilHid.destroyXMLFileSystem(getName() + "1");
223             TestUtilHid.destroyXMLFileSystem(getName() + "2");
224         }
225     }
226      */

227     
228     // XXX test create -> mask -> recreate in same MFS
229

230 }
231
Popular Tags