KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.junit.*;
23 import junit.textui.TestRunner;
24
25 /**
26  * Test that MultiFileSystem does not refresh more than it needs to
27  * when you call setDelegates.
28  * @see "#29354"
29  * @author Jesse Glick
30  */

31 public class MultiFileSystemRefreshTest extends NbTestCase implements FileChangeListener {
32
33     public MultiFileSystemRefreshTest(String JavaDoc name) {
34         super(name);
35     }
36
37     public static void main(String JavaDoc[] args) {
38         TestRunner.run(new NbTestSuite(MultiFileSystemRefreshTest.class));
39     }
40
41     private FileSystem fs1, fs2;
42     protected void setUp() throws Exception JavaDoc {
43         super.setUp();
44         fs1 = TestUtilHid.createLocalFileSystem("mfsrefresh1"+getName() + "1", new String JavaDoc[] {
45             "a/b/c.txt",
46             "a/b/d.txt",
47             "e/f.txt",
48         });
49         fs2 = TestUtilHid.createLocalFileSystem("mfsrefresh2"+getName() + "2", new String JavaDoc[] {
50             "e/g.txt",
51         });
52     }
53     protected void tearDown() throws Exception JavaDoc {
54         TestUtilHid.destroyLocalFileSystem(getName() + "1");
55         TestUtilHid.destroyLocalFileSystem(getName() + "2");
56         super.tearDown();
57     }
58     
59     private int count;
60     
61     public void testSetDelegatesFiring() throws Exception JavaDoc {
62         MultiFileSystem mfs = new MultiFileSystem(new FileSystem[] {fs1, fs2});
63         //mfs.addFileChangeListener(this);
64
FileObject a = mfs.findResource("a");
65         assertNotNull(a);
66         assertEquals(1, a.getChildren().length);
67         a.addFileChangeListener(this);
68         FileObject e = mfs.findResource("e");
69         assertNotNull(e);
70         assertEquals(2, e.getChildren().length);
71         e.addFileChangeListener(this);
72         count = 0;
73         mfs.setDelegates(new FileSystem[] {fs1});
74         System.err.println("setDelegates done");
75         assertEquals(1, a.getChildren().length);
76         assertEquals(1, e.getChildren().length);
77         assertEquals(1, count);
78     }
79     
80     public void fileAttributeChanged(FileAttributeEvent fe) {
81         System.err.println("attr changed: " + fe);
82         count++;
83     }
84     
85     public void fileChanged(FileEvent fe) {
86         System.err.println("changed: " + fe);
87         count++;
88     }
89     
90     public void fileDataCreated(FileEvent fe) {
91         System.err.println("created: " + fe);
92         count++;
93     }
94     
95     public void fileDeleted(FileEvent fe) {
96         System.err.println("deleted: " + fe);
97         count++;
98     }
99     
100     public void fileFolderCreated(FileEvent fe) {
101         System.err.println("folder created: " + fe);
102         count++;
103     }
104     
105     public void fileRenamed(FileRenameEvent fe) {
106         System.err.println("renamed: " + fe);
107         count++;
108     }
109     
110 }
111
Popular Tags