View Javadoc
1   /*
2    * The MIT License
3    *
4    * Copyright (c) 2004, The Codehaus
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of
7    * this software and associated documentation files (the "Software"), to deal in
8    * the Software without restriction, including without limitation the rights to
9    * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10   * of the Software, and to permit persons to whom the Software is furnished to do
11   * so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  package org.codehaus.plexus.archiver.tar;
25  
26  import java.io.File;
27  
28  import org.codehaus.plexus.archiver.Archiver;
29  import org.codehaus.plexus.archiver.TestSupport;
30  import org.codehaus.plexus.archiver.UnArchiver;
31  import org.codehaus.plexus.archiver.snappy.SnappyArchiver;
32  import org.junit.jupiter.api.Test;
33  
34  import static org.junit.jupiter.api.Assertions.assertEquals;
35  import static org.junit.jupiter.api.Assertions.assertTrue;
36  
37  /**
38   * Snappy tar archives
39   */
40  class TarSnappyUnArchiverTest extends TestSupport {
41  
42      @Test
43      void testExtract() throws Exception {
44          TarArchiver tarArchiver = (TarArchiver) lookup(Archiver.class, "tar");
45          tarArchiver.setLongfile(TarLongFileMode.posix);
46  
47          String fileName1 = "TarSnappyUnArchiverTest1.txt";
48          String fileName2 = "TarSnappyUnArchiverTest2.txt";
49          File file1InTar = getTestFile("target/output/" + fileName1);
50          File file2InTar = getTestFile("target/output/" + fileName2);
51          file1InTar.delete();
52          file2InTar.delete();
53  
54          tarArchiver.addFile(getTestFile("src/test/resources/manifests/manifest1.mf"), fileName1);
55          tarArchiver.addFile(getTestFile("src/test/resources/manifests/manifest2.mf"), fileName2, 0664);
56          tarArchiver.setDestFile(getTestFile("target/output/archive.tar"));
57          tarArchiver.createArchive();
58  
59          SnappyArchiver snappyArchiver = (SnappyArchiver) lookup(Archiver.class, "snappy");
60  
61          File testSnappyFile = getTestFile("target/output/archive.tar.snappy");
62          snappyArchiver.setDestFile(testSnappyFile);
63          snappyArchiver.addFile(getTestFile("target/output/archive.tar"), "dontcare");
64          snappyArchiver.createArchive();
65  
66          TarSnappyUnArchiver tarSnappyUnArchiver = (TarSnappyUnArchiver) lookup(UnArchiver.class, "tar.snappy");
67          tarSnappyUnArchiver.setDestDirectory(getTestFile("target/output"));
68          tarSnappyUnArchiver.setSourceFile(testSnappyFile);
69          tarSnappyUnArchiver.extract();
70  
71          assertTrue(file1InTar.exists());
72          assertTrue(file2InTar.exists());
73  
74          // make sure we place the source file back
75          assertEquals(testSnappyFile, tarSnappyUnArchiver.getSourceFile());
76      }
77  
78      @Test
79      void testLookup() throws Exception {
80          lookup(UnArchiver.class, "tar.snappy");
81      }
82  }