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;
18  
19  import static org.apache.commons.vfs2.VfsTestUtils.getTestResource;
20  import static org.junit.jupiter.api.Assertions.assertNotNull;
21  import static org.junit.jupiter.api.Assertions.assertSame;
22  import static org.junit.jupiter.api.Assertions.assertTrue;
23  
24  import java.io.File;
25  
26  import org.junit.jupiter.api.Test;
27  
28  /**
29   * Test cases for the VFS factory.
30   */
31  public class FileSystemManagerFactoryTest {
32  
33      private void check(final FileSystemManager manager, FileObject file) throws FileSystemException {
34          assertNotNull(file);
35          assertTrue(file.exists());
36          assertSame(FileType.FILE, file.getType());
37          assertTrue(file.isFile());
38  
39          // Expand it
40          file = manager.createFileSystem(file);
41          assertNotNull(file);
42          assertTrue(file.exists());
43          assertSame(FileType.FOLDER, file.getType());
44          assertTrue(file.isFolder());
45      }
46  
47      /**
48       * Sanity test.
49       */
50      @Test
51      public void testDefaultInstance() throws Exception {
52          // Locate the default manager
53          final FileSystemManager manager = VFS.getManager();
54  
55          // Lookup a test jar file
56          final File jarFile = getTestResource("test.jar");
57          // File
58          final FileObject file = manager.toFileObject(jarFile);
59          check(manager, file);
60          // Path
61          final FileObject path = manager.toFileObject(jarFile.toPath());
62          check(manager, file);
63          // URI
64          final FileObject file2 = manager.resolveFile(jarFile.toURI());
65          check(manager, file2);
66          // URL
67          final FileObject file3 = manager.resolveFile(jarFile.toURI().toURL());
68          check(manager, file3);
69      }
70  
71  }