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.tar;
18  
19  import java.io.File;
20  import java.io.IOException;
21  
22  import org.apache.commons.vfs2.FileObject;
23  import org.apache.commons.vfs2.FileSystemManager;
24  import org.apache.commons.vfs2.VFS;
25  import org.junit.Assert;
26  import org.junit.Test;
27  
28  /**
29   * test use DefaultFileSystemManager.createFileSystem method to create tar,tgz,tbz2 file system
30   *
31   * @since 2.7.0
32   **/
33  public class CreateFileSystemTestCase {
34  
35      private FileObject createFileSystem(final String testFilePath) throws IOException {
36  
37          final File testFile = new File(testFilePath);
38          final FileSystemManager manager = VFS.getManager();
39  
40          // create fileSystem and return fileObject
41          try (FileObject localFileObject = manager.resolveFile(testFile.getAbsolutePath())) {
42              return manager.createFileSystem(localFileObject);
43          }
44      }
45  
46      @Test
47      public void testTarFile() throws IOException {
48  
49          final String testFilePath = "src/test/resources/test-data/test.tar";
50          try (FileObject fileObject = createFileSystem(testFilePath)) {
51              Assert.assertTrue(fileObject instanceof TarFileObject);
52          }
53      }
54  
55      @Test
56      public void testTbz2File() throws IOException {
57  
58          final String testFilePath = "src/test/resources/test-data/test.tbz2";
59          try (FileObject fileObject = createFileSystem(testFilePath)) {
60              Assert.assertTrue(fileObject instanceof TarFileObject);
61          }
62      }
63  
64      @Test
65      public void testTgzFile() throws IOException {
66  
67          final String testFilePath = "src/test/resources/test-data/test.tgz";
68          try (FileObject fileObject = createFileSystem(testFilePath)) {
69              Assert.assertTrue(fileObject instanceof TarFileObject);
70          }
71      }
72  }