Added
Link Here
|
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 |
import java.io.IOException; |
22 |
import junit.framework.TestCase; |
23 |
import org.openide.util.lookup.Lookups; |
24 |
import org.openide.util.lookup.ProxyLookup; |
25 |
/** |
26 |
* Tests FileUtil.getConfigurationData(), etc. |
27 |
* |
28 |
* @author Tim Boudreau |
29 |
*/ |
30 |
public class FileUtilSfsMethodsTest extends TestCase { |
31 |
|
32 |
public FileUtilSfsMethodsTest (String name) { |
33 |
super (name); |
34 |
} |
35 |
|
36 |
protected void setUp() throws java.lang.Exception { |
37 |
System.setProperty ("org.openide.util.Lookup", |
38 |
"org.openide.filesystems.FileUtilSfsMethodsTest$MyLkp"); |
39 |
} |
40 |
|
41 |
protected String[] getResources(String testName) { |
42 |
return new String[] { "somefolder/somefile.txt" }; |
43 |
} |
44 |
|
45 |
public void testGetConfigurationData() throws Exception { |
46 |
System.out.println("testGetConfigurationData"); |
47 |
FileObject f = FileUtil.getConfigurationFolder("folder"); |
48 |
assertNotNull (f); |
49 |
FileObject f1 = FileUtil.getConfigurationFile ("folder/file.txt"); |
50 |
assertNotNull (f1); |
51 |
assertEquals (f1, f.getFileObject ("file.txt")); |
52 |
} |
53 |
|
54 |
public void testCreateConfigurationFile() throws Exception { |
55 |
System.out.println("testCreateConfigurationFile"); |
56 |
FileObject f = FileUtil.getConfigurationFile("somewhere/file2.txt"); |
57 |
assertNotNull (f); |
58 |
Exception ioe = null; |
59 |
FileObject f1 = null; |
60 |
try { |
61 |
f1 = FileUtil.getConfigurationFile ("somewhere/file2.txt"); |
62 |
} catch (Exception e) { |
63 |
ioe = e; |
64 |
} |
65 |
assertNull (ioe); |
66 |
assertNotNull (f1); |
67 |
assertEquals (f, f1); |
68 |
ioe = null; |
69 |
try { |
70 |
f = FileUtil.getConfigurationFolder ("somewhere"); |
71 |
} catch (Exception e) { |
72 |
ioe = e; |
73 |
} |
74 |
assertNull (ioe); |
75 |
assertEquals (f, f1.getParent()); |
76 |
|
77 |
f = FileUtil.getConfigurationFolder("folder"); |
78 |
FileObject nue = f.createData ("hello.txt"); |
79 |
assertEquals (nue, FileUtil.getConfigurationFile("folder/hello.txt")); |
80 |
assertNotNull (f.getFileObject ("hello.txt")); |
81 |
assertTrue (f.getFileObject ("hello.txt").isData()); |
82 |
assertFalse (f.getFileObject ("hello.txt").isFolder()); |
83 |
} |
84 |
|
85 |
public void testCreateConfigurationFolder() throws Exception { |
86 |
System.out.println("testCreateConfigurationFolder"); |
87 |
FileObject f = FileUtil.getConfigurationFolder ("other"); |
88 |
assertNotNull (f); |
89 |
Exception ioe = null; |
90 |
FileObject f1 = null; |
91 |
try { |
92 |
f1 = FileUtil.getConfigurationFolder("other"); |
93 |
} catch (Exception e) { |
94 |
ioe = e; |
95 |
} |
96 |
assertNull (ioe); |
97 |
assertEquals (f, f1); |
98 |
} |
99 |
|
100 |
private static class MyRepo extends Repository { |
101 |
static FileSystem sysfs; |
102 |
public MyRepo () { |
103 |
super(sysfs = FileUtil.createMemoryFileSystem()); |
104 |
try { |
105 |
FileObject fld = sysfs.getRoot().createFolder("folder"); |
106 |
fld.createData("file.txt"); |
107 |
} catch (IOException ioe) { |
108 |
throw new Error (ioe); |
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
public static final class MyLkp extends ProxyLookup { |
114 |
public MyLkp () { |
115 |
super (Lookups.singleton (new MyRepo())); |
116 |
} |
117 |
} |
118 |
} |