001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.openide.loaders;
043:
044: import java.util.logging.Logger;
045: import org.openide.filesystems.*;
046:
047: import java.beans.*;
048: import java.io.File;
049: import java.io.IOException;
050: import java.util.ArrayList;
051: import java.util.Arrays;
052:
053: import org.netbeans.junit.*;
054:
055: /** Test recognition of objects in folders, and folder ordering.
056: *
057: * @author Vita Stejskal, Jesse Glick
058: */
059: public class DataReadOnlyTest extends LoggingTestCaseHid {
060: private ArrayList hold = new ArrayList();
061:
062: /** Creates new DataFolderTest */
063: public DataReadOnlyTest(String name) {
064: super (name);
065: }
066:
067: protected void setUp() throws Exception {
068: clearWorkDir();
069: }
070:
071: public void testDeleteReadOnlyIssue81241() throws Exception {
072: String fsstruct[] = new String[] { "temp/a/b/test.txt",
073: "where/", };
074:
075: FileSystem lfs = TestUtilHid.createLocalFileSystem(
076: getWorkDir(), fsstruct);
077:
078: FileObject fo = lfs.findResource("temp/a/b/test.txt");
079: DataObject obj = DataObject.find(fo);
080:
081: assertEquals("Found the right one", fo, obj.getPrimaryFile());
082:
083: File f = FileUtil.toFile(fo);
084: assertNotNull("File found", f);
085: assertTrue("File exists", f.exists());
086:
087: if (!f.setReadOnly()) {
088: // if the read only operation does not succeeds, then the test has to end
089: Logger.getAnonymousLogger().warning(
090: "Cannot set read only: " + f);
091: return;
092: }
093:
094: assertFalse("Is read only", f.canWrite());
095:
096: DataFolder folder = obj.getFolder().getFolder();
097: assertNotNull("Folder found", folder);
098:
099: DataFolder target = DataFolder.findFolder(lfs
100: .findResource("where"));
101:
102: folder.move(target);
103:
104: assertTrue("File is not moved", f.exists());
105: assertTrue("Remains valid", fo.isValid());
106:
107: DataObject[] arr = target.getChildren();
108: assertEquals("One children", 1, arr.length);
109:
110: if (arr[0] instanceof DataFolder) {
111: DataFolder subF = (DataFolder) arr[0];
112: arr = subF.getChildren();
113: } else {
114: fail("Shall be a folder: " + arr[0]);
115: }
116:
117: assertEquals("One children", 1, arr.length);
118:
119: if (arr[0] instanceof DataFolder) {
120: DataFolder subF = (DataFolder) arr[0];
121: arr = subF.getChildren();
122: } else {
123: fail("Shall be a folder: " + arr[0]);
124: }
125:
126: assertEquals("No children in target subfolder: "
127: + Arrays.asList(arr), 0, arr.length);
128:
129: arr = folder.getChildren();
130: assertEquals("One children in orig folder", 1, arr.length);
131:
132: if (arr[0] instanceof DataFolder) {
133: DataFolder subF = (DataFolder) arr[0];
134: arr = subF.getChildren();
135: } else {
136: fail("Shall be a folder: " + arr[0]);
137: }
138:
139: assertEquals("One children in orig subfolder", 1, arr.length);
140: assertEquals("Named correctly", "test.txt", arr[0]
141: .getPrimaryFile().getNameExt());
142: }
143: }
|