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  
18  package org.apache.commons.vfs2.provider.res;
19  
20  import org.apache.commons.vfs2.AbstractProviderTestCase;
21  import org.apache.commons.vfs2.AbstractProviderTestConfig;
22  import org.apache.commons.vfs2.AbstractVfsTestCase;
23  import org.apache.commons.vfs2.FileName;
24  import org.apache.commons.vfs2.FileObject;
25  import org.apache.commons.vfs2.FileSystemException;
26  import org.apache.commons.vfs2.FileSystemManager;
27  import org.apache.commons.vfs2.ProviderTestSuite;
28  import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
29  import org.apache.commons.vfs2.provider.zip.ZipFileProvider;
30  import org.junit.Assert;
31  import org.junit.Test;
32  
33  /**
34   * Test cases for VFS-444.
35   */
36  public class Vfs444TestCase extends AbstractProviderTestConfig {
37  
38      public static class Vfs444Tests extends AbstractProviderTestCase {
39  
40          @Test
41          public void testResolveFullPathFile0() throws FileSystemException {
42              final FileObject result = getManager().resolveFile("res:test-data/test.zip");
43              Assert.assertTrue(result.exists());
44          }
45  
46          @Test
47          public void testResolveFullPathFile1() throws FileSystemException {
48              final FileObject result = getManager().resolveFile("res:/test-data/test.zip");
49              Assert.assertTrue(result.exists());
50          }
51  
52          @Test
53          public void testResolveFullPathFile2() throws FileSystemException {
54          	final FileObject result = getManager().resolveFile("res://test-data/test.zip");
55              Assert.assertTrue(result.exists());
56          }
57  
58          @Test
59          public void testResolveFullPathURI0() throws FileSystemException {
60              final FileName result = getManager().resolveURI("res:test-data/test.zip");
61              Assert.assertTrue(result.isFile());
62          }
63  
64          @Test
65          public void testResolveFullPathURI1() throws FileSystemException {
66              final FileName result = getManager().resolveURI("res:/test-data/test.zip");
67              Assert.assertTrue(result.isFile());
68          }
69  
70          @Test
71          public void testResolveFullPathURI2() throws FileSystemException {
72              final FileName result = getManager().resolveURI("res://test-data/test.zip");
73              Assert.assertTrue(result.isFile());
74          }
75  
76          @Test
77          public void testResolvePartialPath1() throws FileSystemException {
78              final FileName result = getManager().resolveURI("res:test-data");
79              Assert.assertTrue(result.isFile());
80          }
81  
82          @Test
83          public void testResolvePartialPath2() throws FileSystemException {
84              final FileName root = getManager().resolveURI("res:test-data");
85              final FileName file = getManager().resolveName(root, "test.zip");
86              final String uri = file.getURI();
87              final FileObject result = getManager().resolveFile(uri);
88              Assert.assertNotNull(result);
89              Assert.assertTrue(result.exists());
90          }
91      }
92  
93      public static junit.framework.Test suite() throws Exception {
94          final ProviderTestSuiteTestSuite.html#ProviderTestSuite">ProviderTestSuite suite = new ProviderTestSuite(new Vfs444TestCase(), true);
95          suite.addTests(Vfs444Tests.class);
96          return suite;
97      }
98  
99      /**
100      * Returns the base folder for tests.
101      */
102     @Override
103     public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
104         final String baseDir = AbstractVfsTestCase.getResourceTestDirectory();
105         return manager.resolveFile("zip:res:" + baseDir + "/test.zip");
106     }
107 
108     /**
109      * Prepares the file system manager. This implementation does nothing.
110      */
111     @Override
112     public void prepare(final DefaultFileSystemManager manager) throws Exception {
113         manager.addProvider("res", new ResourceFileProvider());
114         manager.addProvider("zip", new ZipFileProvider());
115     }
116 }