1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs.provider.ram.test;
18
19 import java.io.File;
20
21 import junit.framework.Test;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.commons.vfs.FileObject;
26 import org.apache.commons.vfs.FileSystemManager;
27 import org.apache.commons.vfs.impl.DefaultFileSystemManager;
28 import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
29 import org.apache.commons.vfs.provider.ram.RamFileProvider;
30 import org.apache.commons.vfs.provider.ram.RamFileSystem;
31 import org.apache.commons.vfs.test.AbstractProviderTestConfig;
32 import org.apache.commons.vfs.test.ProviderTestConfig;
33 import org.apache.commons.vfs.test.ProviderTestSuite;
34 import org.apache.commons.AbstractVfsTestCase;
35
36 /***
37 * Tests for the RAM file system.
38 */
39 public class RamProviderTestCase extends AbstractProviderTestConfig implements
40 ProviderTestConfig
41 {
42 private boolean inited = false;
43
44 /*** logger */
45 private static Log log = LogFactory.getLog(RamProviderTestCase.class);
46
47 /***
48 * Creates the test suite for the ram file system.
49 */
50 public static Test suite() throws Exception
51 {
52 return new ProviderTestSuite(new RamProviderTestCase());
53 }
54
55 /***
56 * Prepares the file system manager.
57 *
58 * Imports test data from the disk.
59 *
60 * @throws Exception
61 *
62 */
63 public void prepare(final DefaultFileSystemManager manager)
64 throws Exception
65 {
66 try
67 {
68 manager.addProvider("ram", new RamFileProvider());
69 manager.addProvider("file", new DefaultLocalFileProvider());
70 }
71 catch (Exception e)
72 {
73 log.error(e);
74 throw e;
75 }
76 }
77
78 /***
79 * Returns the base folder for tests.
80 */
81 public FileObject getBaseTestFolder(final FileSystemManager manager)
82 throws Exception
83 {
84 if (!inited)
85 {
86
87 FileObject fo = manager.resolveFile("ram:/");
88 RamFileSystem fs = (RamFileSystem) fo.getFileSystem();
89 fs.importTree(new File(AbstractVfsTestCase.getTestDirectory()));
90 fo.close();
91
92 inited=true;
93 }
94
95 final String uri = "ram:/";
96 return manager.resolveFile(uri);
97 }
98 }