KickJava   Java API By Example, From Geeks To Geeks.

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


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.File JavaDoc;
23 import java.io.FileOutputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.jar.JarOutputStream JavaDoc;
26 import java.util.zip.ZipEntry JavaDoc;
27 import junit.framework.Test;
28 import org.netbeans.junit.NbTestSuite;
29
30 /**
31  * @author rm111737
32  */

33 public class JarFileSystemTest extends FileSystemFactoryHid {
34      JarFileSystem jfs;
35     /** Creates new JarFileSystemTest */
36     public JarFileSystemTest(Test test) {
37         super(test);
38     }
39
40     public static void main(String JavaDoc args[]) {
41         junit.textui.TestRunner.run(suite());
42     }
43
44
45     public static Test suite() {
46         NbTestSuite suite = new NbTestSuite();
47         suite.addTestSuite(RepositoryTestHid.class);
48         suite.addTestSuite(FileSystemTestHid.class);
49         suite.addTestSuite(FileObjectTestHid.class);
50         /*failing tests*/
51         suite.addTestSuite(URLMapperTestHidden.class);
52         suite.addTestSuite(URLMapperTestInternalHidden.class);
53         suite.addTestSuite(FileUtilTestHidden.class);
54         
55         return new JarFileSystemTest(suite);
56     }
57     protected void destroyFileSystem (String JavaDoc testName) throws IOException JavaDoc {}
58     
59     protected FileSystem[] createFileSystem (String JavaDoc testName, String JavaDoc[] resources) throws IOException JavaDoc{
60         File JavaDoc jar = TestUtilHid.locationOfTempFolder("jfstest");
61         jar.mkdir();
62         
63         File JavaDoc f = new File JavaDoc (jar,"jfstest.jar");
64         if (!f.exists()) {
65             f.getParentFile().mkdirs();
66             f.createNewFile();
67         }
68         JarOutputStream JavaDoc jos = new JarOutputStream JavaDoc (new FileOutputStream JavaDoc (f));
69         
70         for (int i = 0; i < resources.length; i++) {
71             String JavaDoc entryName = resources[i];
72             if (entryName.startsWith("/")) entryName = entryName.substring(1);
73             jos.putNextEntry(new ZipEntry JavaDoc (entryName));
74         }
75         
76         
77        jos.close();
78         
79         jfs = new JarFileSystem ();
80         try {
81             jfs.setJarFile(f);
82         } catch (Exception JavaDoc ex) {}
83                 
84         return new FileSystem[] {jfs};
85     }
86 }
87
Popular Tags