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.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              // Import the test tree
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  }