Added
Link Here
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. |
5 |
* |
6 |
* The contents of this file are subject to the terms of either the GNU |
7 |
* General Public License Version 2 only ("GPL") or the Common |
8 |
* Development and Distribution License("CDDL") (collectively, the |
9 |
* "License"). You may not use this file except in compliance with the |
10 |
* License. You can obtain a copy of the License at |
11 |
* http://www.netbeans.org/cddl-gplv2.html |
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
13 |
* specific language governing permissions and limitations under the |
14 |
* License. When distributing the software, include this License Header |
15 |
* Notice in each file and include the License file at |
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this |
17 |
* particular file as subject to the "Classpath" exception as provided |
18 |
* by Sun in the GPL Version 2 section of the License file that |
19 |
* accompanied this code. If applicable, add the following below the |
20 |
* License Header, with the fields enclosed by brackets [] replaced by |
21 |
* your own identifying information: |
22 |
* "Portions Copyrighted [year] [name of copyright owner]" |
23 |
* |
24 |
* Contributor(s): |
25 |
* |
26 |
* The Original Software is NetBeans. The Initial Developer of the Original |
27 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun |
28 |
* Microsystems, Inc. All Rights Reserved. |
29 |
* |
30 |
* If you wish your version of this file to be governed by only the CDDL |
31 |
* or only the GPL Version 2, indicate your decision by adding |
32 |
* "[Contributor] elects to include this software in this distribution |
33 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
34 |
* single choice of license, a recipient has the option to distribute |
35 |
* your version of this file under either the CDDL, the GPL Version 2 or |
36 |
* to extend the choice of license to its licensees as provided above. |
37 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
38 |
* Version 2 license, then the option applies only if the new code is |
39 |
* made subject to such option by the copyright holder. |
40 |
*/ |
41 |
|
42 |
package org.openide.filesystems; |
43 |
|
44 |
import java.io.IOException; |
45 |
import java.net.URL; |
46 |
import org.netbeans.junit.*; |
47 |
|
48 |
|
49 |
public class MutilFileSystemLayeredDeliveryTest extends NbTestCase { |
50 |
MultiFileSystem down; |
51 |
MultiFileSystem top; |
52 |
LocalFileSystem lfs; |
53 |
|
54 |
public MutilFileSystemLayeredDeliveryTest(String test) { |
55 |
super(test); |
56 |
} |
57 |
|
58 |
@Override |
59 |
protected void setUp() throws Exception { |
60 |
down = new MultiFileSystem(); |
61 |
FileSystem mfs = new MultiFileSystem(new FileSystem[] { down }); |
62 |
for (int i = 0; i < 5; i++) { |
63 |
mfs = new MultiFileSystem(new FileSystem[] { |
64 |
mfs |
65 |
}); |
66 |
} |
67 |
lfs = new LocalFileSystem(); |
68 |
lfs.setRootDirectory(getWorkDir()); |
69 |
top = new MultiFileSystem (new FileSystem[] {lfs,mfs}); |
70 |
} |
71 |
|
72 |
public void testHowManyChanges() throws Exception { |
73 |
L l = new L(); |
74 |
|
75 |
FileObject fo = FileUtil.createFolder(top.getRoot(), "testMethodValue"); |
76 |
FileObject mv = FileUtil.createFolder(top.getRoot(), "testMV"); |
77 |
fo.addFileChangeListener(l); |
78 |
mv.addFileChangeListener(l); |
79 |
assertEquals("No children yet", 0, fo.getChildren().length); |
80 |
assertNull("No value for ", fo.getAttribute("value1")); |
81 |
assertEquals("No children yet", 0, mv.getChildren().length); |
82 |
assertNull("No value for ", mv.getAttribute("value1")); |
83 |
|
84 |
|
85 |
final FileSystem fs = FileUtil.createMemoryFileSystem(); |
86 |
down.setDelegates(fs); |
87 |
FileUtil.runAtomicAction(new Runnable() { |
88 |
public void run() { |
89 |
try { |
90 |
final FileObject tmv = fs.getRoot().createFolder("testMethodValue"); |
91 |
final FileObject tmv2 = fs.getRoot().createFolder("testMV"); |
92 |
for (int i = 0; i < 10; i++) { |
93 |
tmv.setAttribute("value" + i, i); |
94 |
tmv2.setAttribute("value" + i, i); |
95 |
} |
96 |
} catch (IOException ex) { |
97 |
fail(ex.getMessage()); |
98 |
} |
99 |
} |
100 |
}); |
101 |
|
102 |
assertNotNull("Some value for ", fo.getAttribute("value1")); |
103 |
|
104 |
assertEquals("Ten changes", 20, l.change); |
105 |
assertEquals("One Run", 1, l.run); |
106 |
|
107 |
l.change = 0; |
108 |
l.run = 0; |
109 |
|
110 |
final FileSystem fs2 = FileUtil.createMemoryFileSystem(); |
111 |
final FileObject tmv = fs2.getRoot().createFolder("testMethodValue"); |
112 |
final FileObject tmv2 = fs2.getRoot().createFolder("testMV"); |
113 |
down.setDelegates(fs2); |
114 |
|
115 |
assertEquals("No attributes", false, fo.getAttributes().hasMoreElements()); |
116 |
assertEquals("No attributes", false, mv.getAttributes().hasMoreElements()); |
117 |
|
118 |
assertEquals("Two changes", 2, l.change); |
119 |
assertEquals("One Run", 1, l.run); |
120 |
} |
121 |
|
122 |
private static class L implements FileChangeListener, Runnable { |
123 |
int change; |
124 |
int run; |
125 |
|
126 |
private void event(FileEvent ev) { |
127 |
change++; |
128 |
int prev = run; |
129 |
ev.runWhenDeliveryOver(this); |
130 |
assertEquals("Delivery is not immediate", prev, run); |
131 |
} |
132 |
|
133 |
public void run() { |
134 |
run++; |
135 |
} |
136 |
|
137 |
|
138 |
public void fileFolderCreated(FileEvent fe) { |
139 |
event(fe); |
140 |
} |
141 |
|
142 |
public void fileDataCreated(FileEvent fe) { |
143 |
event(fe); |
144 |
} |
145 |
|
146 |
public void fileChanged(FileEvent fe) { |
147 |
event(fe); |
148 |
} |
149 |
|
150 |
public void fileDeleted(FileEvent fe) { |
151 |
event(fe); |
152 |
} |
153 |
|
154 |
public void fileRenamed(FileRenameEvent fe) { |
155 |
event(fe); |
156 |
} |
157 |
|
158 |
public void fileAttributeChanged(FileAttributeEvent fe) { |
159 |
event(fe); |
160 |
} |
161 |
} // end of L |
162 |
} |