View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider.ram;
18  
19  import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile;
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.vfs2.AbstractProviderTestConfig;
26  import org.apache.commons.vfs2.FileObject;
27  import org.apache.commons.vfs2.FileSystemManager;
28  import org.apache.commons.vfs2.ProviderTestSuite;
29  import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
30  import org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider;
31  
32  /**
33   * Tests for the RAM file system.
34   */
35  public class RamProviderTestCase extends AbstractProviderTestConfig {
36  
37      /** Logger */
38      private static final Log log = LogFactory.getLog(RamProviderTestCase.class);
39  
40      /**
41       * Creates the test suite for the ram file system.
42       */
43      public static Test suite() throws Exception {
44          return new ProviderTestSuite(new RamProviderTestCase());
45      }
46  
47      private boolean inited;
48  
49      /**
50       * Returns the base folder for tests.
51       */
52      @Override
53      public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
54          if (!inited) {
55              // Import the test tree
56              final FileObject fo = manager.resolveFile("ram:/");
57              final RamFileSystem fs = (RamFileSystem) fo.getFileSystem();
58              fs.importTree(getTestDirectoryFile());
59              fo.close();
60  
61              inited = true;
62          }
63  
64          final String uri = "ram:/";
65          return manager.resolveFile(uri);
66      }
67  
68      /**
69       * Prepares the file system manager.
70       *
71       * Imports test data from the disk.
72       *
73       * @throws Exception
74       */
75      @Override
76      public void prepare(final DefaultFileSystemManager manager) throws Exception {
77          try {
78              manager.addProvider("ram", new RamFileProvider());
79              manager.addProvider("file", new DefaultLocalFileProvider());
80          } catch (final Exception e) {
81              log.error(e);
82              throw e;
83          }
84      }
85  
86  }