KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > MasterFileSystemOnTopOfLocalFSTest


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.netbeans.modules.masterfs;
21
22 import java.beans.PropertyVetoException JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import junit.framework.Test;
26 import org.netbeans.junit.NbTestSuite;
27 import org.openide.filesystems.FileObjectTestHid;
28 import org.openide.filesystems.FileSystem;
29 import org.openide.filesystems.FileSystemTestHid;
30 import org.openide.filesystems.FileUtil;
31 import org.openide.filesystems.FileUtilTestHidden;
32 import org.openide.filesystems.LocalFileSystem;
33 import org.openide.filesystems.URLMapperTestHidden;
34
35 /**
36  * @author Radek Matous
37  */

38 public class MasterFileSystemOnTopOfLocalFSTest extends MasterFileSystemTest {
39     private static LocalFileSystem rootFs;
40     
41     public MasterFileSystemOnTopOfLocalFSTest(Test test) {
42         super(test);
43     }
44         
45     public static void main(String JavaDoc args[]) {
46         junit.textui.TestRunner.run(suite());
47     }
48         
49     public static Test suite() {
50         NbTestSuite suite = new NbTestSuite();
51         suite.addTestSuite(FileSystemTestHid.class);
52         suite.addTestSuite(FileObjectTestHid.class);
53         suite.addTestSuite(URLMapperTestHidden.class);
54         suite.addTestSuite(FileUtilTestHidden.class);
55         
56         
57         return new MasterFileSystemOnTopOfLocalFSTest(suite);
58     }
59     
60     protected FileSystem[] createFileSystem(String JavaDoc testName, String JavaDoc[] resources) throws IOException JavaDoc {
61         FileSystem[] fss = super.createFileSystem(testName, resources);
62         if (rootFs == null) {
63             for (int i = 0; i < fss.length && fss[i] != null; i++) {
64                 if (fss[i] instanceof MasterFileSystem) {
65                     File JavaDoc rootFile = getRoot(new File JavaDoc(getResourcePrefix(testName, resources)));
66                     rootFs = new LocalFileSystem();
67                     try {
68                         rootFs.setRootDirectory(rootFile);
69                     } catch (PropertyVetoException JavaDoc ex) {
70                         IOException JavaDoc iex = new IOException JavaDoc(ex.getLocalizedMessage());
71                         iex.initCause(ex);
72                         throw iex;
73                     }
74                     MountTable.getDefault().unmount(rootFile.getAbsolutePath());
75                     MountTable.getDefault().mount(rootFile.getAbsolutePath(), rootFs);
76                     break;
77                 }
78             }
79             
80         }
81         return fss;
82     }
83     
84     private static File JavaDoc getRoot(final File JavaDoc dir) {
85         File JavaDoc retval = dir;
86         for (; retval.getParentFile() != null; retval = retval.getParentFile());
87         assert retval != null;
88         return retval;
89     }
90 }
91
Popular Tags