KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.ref.WeakReference JavaDoc;
23 import java.util.*;
24 import java.util.logging.Level JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26 import junit.framework.AssertionFailedError;
27 import junit.textui.TestRunner;
28 import org.openide.filesystems.FileSystem;
29 import java.util.Enumeration JavaDoc;
30 import org.openide.nodes.Node;
31 import org.openide.cookies.InstanceCookie;
32 import org.openide.filesystems.Repository;
33 import org.netbeans.junit.*;
34 import org.openide.filesystems.*;
35
36 /** Creation of data object is said to be slow due to
37  * poor implementation of BrokenDataShadow validate functionality.
38  * @author Jaroslav Tulach
39  */

40 public class DataShadowBrokenSlownessTest extends NbTestCase {
41     /** List of DataObject */
42     private List shadows, brokenShadows;
43     /** folder to work with */
44     private DataFolder folder;
45
46     private FileObject root;
47     /** keep some files */
48     private FileObject[] arr;
49     
50     public DataShadowBrokenSlownessTest (String JavaDoc name) {
51         super(name);
52     }
53     
54     public static NbTestSuite suite () {
55         return NbTestSuite.speedSuite (DataShadowBrokenSlownessTest.class, 10, 5);
56     }
57     
58     protected Level JavaDoc logLevel() {
59         return Level.INFO;
60     }
61     
62     protected void setUp() throws Exception JavaDoc {
63         clearWorkDir();
64         FileSystem lfs = TestUtilHid.createLocalFileSystem(getWorkDir (), new String JavaDoc[] {
65             "shadows/",
66             "brokenshadows",
67             "folder/original.txt",
68             "folder/orig.txt",
69             "modify/"
70         });
71         
72         
73         root = FileUtil.toFileObject(FileUtil.toFile(lfs.getRoot()));
74         
75         int count = getTestNumber ();
76         
77         shadows = createShadows (
78             DataObject.find (root.getFileObject("folder/original.txt")),
79             DataFolder.findFolder (lfs.findResource ("shadows")),
80             count
81         );
82         
83         brokenShadows = /*Collections.EMPTY_LIST; */createShadows (
84             DataObject.find (root.getFileObject("folder/orig.txt")),
85             DataFolder.findFolder (lfs.findResource ("shadows")),
86             count
87         );
88         
89         DataObject.find (root.getFileObject("folder/orig.txt")).delete ();
90         
91         ListIterator it = brokenShadows.listIterator ();
92         while (it.hasNext ()) {
93             DataObject obj = (DataObject)it.next ();
94             assertFalse ("Is not valid", obj.isValid ());
95             assertTrue ("Used to be shadow", obj instanceof DataShadow);
96             DataObject newObj = DataObject.find (obj.getPrimaryFile ());
97             assertTrue ("They are different", newObj != obj);
98             assertFalse ("It is not shadow, as it is broken", newObj instanceof DataShadow);
99             
100             it.set (newObj);
101         }
102         
103         FileObject files = lfs.findResource ("modify");
104         for (int i = 0; i < 200; i++) {
105             FileUtil.createData (files, "empty" + i + ".txt");
106         }
107         
108         arr = files.getChildren ();
109         assertEquals ("Children created", 200, arr.length);
110         
111         folder = DataFolder.findFolder (files);
112     }
113     
114     private static List createShadows (DataObject original, DataFolder target, int count) throws java.io.IOException JavaDoc {
115         ArrayList list = new ArrayList (count);
116         for (int i = 0; i < count; i++) {
117             DataShadow shad = DataShadow.create(target, original.getName()+i, original, "shadow");
118             list.add (shad);
119         }
120         return list;
121     }
122     
123     protected void tearDown() throws Exception JavaDoc {
124         DataShadow.waitUpdatesProcessed();
125         
126         WeakReference JavaDoc ref = new WeakReference JavaDoc(root);
127         this.root = null;
128         this.brokenShadows = null;
129         this.folder = null;
130         this.shadows = null;
131         this.arr = null;
132         try {
133             assertGC("Make sure the filesystem is gone", ref);
134         } catch (AssertionFailedError ex) {
135             Logger.getAnonymousLogger().log(Level.WARNING, null, ex);
136         }
137     }
138     public void test0 () throws java.io.IOException JavaDoc {
139         folder.delete ();
140     }
141
142     public void test10 () throws java.io.IOException JavaDoc {
143         folder.delete ();
144     }
145     
146     public void test99 () throws java.io.IOException JavaDoc {
147         folder.delete ();
148     }
149
150     public void test245 () throws java.io.IOException JavaDoc {
151         folder.delete ();
152     }
153     public void test987 () throws java.io.IOException JavaDoc {
154         folder.delete ();
155     }
156 }
157
Popular Tags