KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
23
24 public class MultiFileObjectTestHid extends TestBaseHid {
25     private static String JavaDoc[] resources = new String JavaDoc [] {
26         "/fold10/fold11/fold12",
27         "/fold20/fold21/fold22",
28         "/fold20/fold23.txt"
29     };
30
31     public MultiFileObjectTestHid(String JavaDoc testName) {
32         super(testName);
33     }
34
35
36     protected String JavaDoc[] getResources (String JavaDoc testName) {
37         return resources;
38     }
39
40     /** #18820*/
41     public void testDeleteMask() throws IOException JavaDoc {
42         FileSystem mfs = new MultiFileSystem (new FileSystem[] {this.testedFS});
43         FileSystem wfs;
44         FileSystem [] allFs = this.allTestedFS;
45         if (allFs.length > 1 && !allFs[1].isReadOnly())
46             wfs = allFs[1];
47         else return;
48         String JavaDoc resource = "/fold20/fold23.txt";
49         String JavaDoc resource_hidden = "/fold20/fold23.txt_hidden";
50         
51         FileObject fo = mfs.findResource(resource);
52         fo.delete();
53                 
54         FileObject hidd = wfs.findResource(resource_hidden);
55         if (hidd == null) return;
56        /** only if mask necessary*/
57         hidd.delete();
58
59         fo = mfs.findResource(resource);
60         fsAssert(resource+" should be present after deleting mask",fo != null);
61     }
62     
63
64     /** */
65     public void testDeleteFolder() throws IOException JavaDoc {
66         FileSystem mfs = this.testedFS;
67
68         FileObject testFo = mfs.findResource("/fold20/fold21/fold22");
69         fsAssert("/fold20/fold21/fold22 should be present",testFo != null);
70         
71         FileObject toDel = mfs.findResource("/fold20");
72         fsAssert("/fold20 should be present",toDel != null);
73         
74         FileObject parent = toDel.getParent();
75         
76         toDel.delete();
77         
78         toDel = mfs.findResource("/fold20");
79         fsAssert("/fold20 should not be present",toDel == null);
80         
81
82         parent.createFolder("fold20");
83         toDel = mfs.findResource("/fold20");
84         fsAssert("/fold20 should be present",toDel != null);
85         
86       
87         /** this assert is goal of this test. Not whole hierarchy should not appear
88          * after deleting and recreation of any folder
89          */

90         testFo = mfs.findResource("/fold20/fold21/fold22");
91         fsAssert("/fold20/fold21/fold22 should not be present",testFo == null);
92     }
93     
94     public void testBug19425 () throws IOException JavaDoc {
95         String JavaDoc whereRes = "/fold10";
96         String JavaDoc whatRes = "/fold20/fold23.txt";
97         
98         FileSystem mfs = this.allTestedFS[0];
99         FileSystem lfsLayer = this.allTestedFS[1];
100         FileSystem xfsLayer = this.allTestedFS[2];
101         
102         boolean needsMask = (xfsLayer.findResource (whatRes) != null);
103         
104
105         FileObject where = mfs.findResource (whereRes);
106         FileObject what = mfs.findResource (whatRes);
107         
108         fsAssert ("Expected resource: " + whereRes, whereRes != null);
109         fsAssert ("Expected resource: " + whatRes, whatRes != null);
110
111         FileLock fLock = what.lock();
112         try {
113             what.move (fLock,where,what.getName(),what.getExt());
114             if (needsMask)
115                 fsAssert ("Must exist mask", lfsLayer.findResource(whatRes+"_hidden") != null);
116             else
117                 fsAssert ("Mustn`t exist mask", lfsLayer.findResource(whatRes+"_hidden") == null);
118                 
119         } finally {
120             fLock.releaseLock();
121         }
122     }
123     
124     /** null delegates are acceptable*/
125     public void testSetDelegates() throws IOException JavaDoc {
126         FileSystem mfs = this.testedFS;
127         MultiFileSystem mfs2 = new MultiFileSystem (new FileSystem[] {mfs});
128
129         try {
130             mfs2.setDelegates(new FileSystem[] {mfs,null});
131         } catch (NullPointerException JavaDoc npe) {
132             fsFail ("Null delegates should be supported");
133         }
134     }
135     
136 }
137
Popular Tags