KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > DataFolderRefreshTest


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.loaders;
21
22 import org.openide.filesystems.*;
23
24 import java.beans.*;
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Arrays JavaDoc;
29
30 import org.netbeans.junit.*;
31
32 /** Testing that a change in a pool triggers notification of a change in DataFolder's
33  * children.
34  *
35  * @author Jaroslav Tulach
36  */

37 public class DataFolderRefreshTest extends LoggingTestCaseHid {
38     private ArrayList JavaDoc hold = new ArrayList JavaDoc();
39     private org.openide.ErrorManager err;
40
41     private FileObject root;
42
43     /** Creates new DataFolderTest */
44     public DataFolderRefreshTest (String JavaDoc name) {
45         super (name);
46     }
47     
48     protected void setUp () throws Exception JavaDoc {
49         err = org.openide.ErrorManager.getDefault().getInstance("TEST-" + getName());
50
51         registerIntoLookup(new FolderInstanceTest.Pool());
52         
53         DataLoaderPool pool = DataLoaderPool.getDefault ();
54         assertNotNull (pool);
55         assertEquals (FolderInstanceTest.Pool.class, pool.getClass ());
56         
57         clearWorkDir ();
58         
59         root = FileUtil.createFolder(
60             Repository.getDefault().getDefaultFileSystem().getRoot(),
61             "dir"
62         );
63         
64         FileUtil.createData(root, "s1.simple");
65         FileUtil.createData(root, "s2.simple");
66     }
67
68     public void testIsChangeFired() throws Exception JavaDoc {
69         DataLoader l = DataLoader.getLoader(DataLoaderOrigTest.SimpleUniFileLoader.class);
70         err.log("Add loader: " + l);
71         FolderInstanceTest.Pool.setExtra(l);
72         err.log("Loader added");
73         
74         DataFolder f = DataFolder.findFolder(root);
75         class C implements PropertyChangeListener {
76             PropertyChangeEvent ev;
77             
78             public void propertyChange(PropertyChangeEvent evt) {
79                 assertNull("Only one event", this.ev);
80                 this.ev = evt;
81             }
82         }
83         
84         C c = new C();
85         f.addPropertyChangeListener(c);
86         
87         DataObject[] arr = f.getChildren();
88         
89         assertEquals("Two objects", 2, arr.length);
90         assertEquals("Loader1", arr[0].getLoader(), l);
91         assertEquals("Loader2", arr[1].getLoader(), l);
92         
93         FolderInstanceTest.Pool.setExtra(null);
94         
95         arr = f.getChildren();
96         
97         assertNotNull("A change event delivered", c.ev);
98         assertEquals("children", DataFolder.PROP_CHILDREN, c.ev.getPropertyName());
99         
100         
101         assertEquals("Two objects", 2, arr.length);
102         assertEquals("Loader1", arr[0].getLoader(), DataLoaderPool.getDefaultFileLoader());
103         assertEquals("Loader2", arr[1].getLoader(), DataLoaderPool.getDefaultFileLoader());
104     }
105 }
106
Popular Tags