KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.logging.Logger JavaDoc;
23 import org.openide.filesystems.*;
24
25 import java.beans.*;
26 import java.io.File JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Arrays JavaDoc;
30
31 import org.netbeans.junit.*;
32
33 /** Test recognition of objects in folders, and folder ordering.
34  *
35  * @author Vita Stejskal, Jesse Glick
36  */

37 public class DataReadOnlyTest extends LoggingTestCaseHid {
38     private ArrayList JavaDoc hold = new ArrayList JavaDoc();
39
40     /** Creates new DataFolderTest */
41     public DataReadOnlyTest (String JavaDoc name) {
42         super (name);
43     }
44
45     protected void setUp () throws Exception JavaDoc {
46         clearWorkDir ();
47     }
48     
49     public void testDeleteReadOnlyIssue81241() throws Exception JavaDoc {
50         String JavaDoc fsstruct [] = new String JavaDoc [] {
51             "temp/a/b/test.txt",
52             "where/",
53         };
54         
55         FileSystem lfs = TestUtilHid.createLocalFileSystem(getWorkDir(), fsstruct);
56
57         FileObject fo = lfs.findResource ("temp/a/b/test.txt");
58         DataObject obj = DataObject.find(fo);
59         
60         assertEquals ("Found the right one", fo, obj.getPrimaryFile());
61         
62         File JavaDoc f = FileUtil.toFile(fo);
63         assertNotNull("File found", f);
64         assertTrue("File exists", f.exists());
65         
66         if (!f.setReadOnly()) {
67             // if the read only operation does not succeeds, then the test has to end
68
Logger.getAnonymousLogger().warning("Cannot set read only: " + f);
69             return;
70         }
71         
72         assertFalse("Is read only", f.canWrite());
73         
74         DataFolder folder = obj.getFolder().getFolder();
75         assertNotNull("Folder found", folder);
76         
77         
78         DataFolder target = DataFolder.findFolder(lfs.findResource("where"));
79         
80         folder.move(target);
81         
82         assertTrue("File is not moved", f.exists());
83         assertTrue("Remains valid", fo.isValid());
84         
85         DataObject[] arr = target.getChildren();
86         assertEquals("One children", 1, arr.length);
87         
88         if (arr[0] instanceof DataFolder) {
89             DataFolder subF = (DataFolder)arr[0];
90             arr = subF.getChildren();
91         } else {
92             fail("Shall be a folder: " + arr[0]);
93         }
94
95         assertEquals("One children", 1, arr.length);
96         
97         if (arr[0] instanceof DataFolder) {
98             DataFolder subF = (DataFolder)arr[0];
99             arr = subF.getChildren();
100         } else {
101             fail("Shall be a folder: " + arr[0]);
102         }
103         
104         assertEquals("No children in target subfolder: " + Arrays.asList(arr), 0, arr.length);
105
106         arr = folder.getChildren();
107         assertEquals("One children in orig folder", 1, arr.length);
108         
109         if (arr[0] instanceof DataFolder) {
110             DataFolder subF = (DataFolder)arr[0];
111             arr = subF.getChildren();
112         } else {
113             fail("Shall be a folder: " + arr[0]);
114         }
115
116         assertEquals("One children in orig subfolder", 1, arr.length);
117         assertEquals("Named correctly", "test.txt", arr[0].getPrimaryFile().getNameExt());
118     }
119 }
120
Popular Tags