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