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  import org.codehaus.plexus.PlexusTestCase;
28  import org.codehaus.plexus.archiver.Archiver;
29  import org.codehaus.plexus.archiver.UnArchiver;
30  import org.codehaus.plexus.archiver.snappy.SnappyArchiver;
31  
32  /**
33   * Snappy tar archives
34   */
35  public class TarSnappyUnArchiverTest
36      extends PlexusTestCase
37  {
38  
39      public void testExtract()
40          throws Exception
41      {
42          TarArchiver tarArchiver = (TarArchiver) lookup( Archiver.ROLE, "tar" );
43          tarArchiver.setLongfile( TarLongFileMode.posix );
44  
45          String fileName1 = "TarSnappyUnArchiverTest1.txt";
46          String fileName2 = "TarSnappyUnArchiverTest2.txt";
47          File file1InTar = getTestFile( "target/output/" + fileName1 );
48          File file2InTar = getTestFile( "target/output/" + fileName2 );
49          file1InTar.delete();
50          file2InTar.delete();
51  
52          tarArchiver.addFile( getTestFile( "src/test/resources/manifests/manifest1.mf" ), fileName1 );
53          tarArchiver.addFile( getTestFile( "src/test/resources/manifests/manifest2.mf" ), fileName2, 0664 );
54          tarArchiver.setDestFile( getTestFile( "target/output/archive.tar" ) );
55          tarArchiver.createArchive();
56  
57          SnappyArchiver snappyArchiver = (SnappyArchiver) lookup( Archiver.ROLE, "snappy" );
58  
59          File testSnappyFile = getTestFile( "target/output/archive.tar.snappy" );
60          snappyArchiver.setDestFile( testSnappyFile );
61          snappyArchiver.addFile( getTestFile( "target/output/archive.tar" ), "dontcare" );
62          snappyArchiver.createArchive();
63  
64          TarSnappyUnArchiver tarSnappyUnArchiver = (TarSnappyUnArchiver) lookup( UnArchiver.ROLE, "tar.snappy" );
65          tarSnappyUnArchiver.setDestDirectory( getTestFile( "target/output" ) );
66          tarSnappyUnArchiver.setSourceFile( testSnappyFile );
67          tarSnappyUnArchiver.extract();
68  
69          assertTrue( file1InTar.exists() );
70          assertTrue( file2InTar.exists() );
71  
72          //make sure we place the source file back
73          assertEquals( testSnappyFile, tarSnappyUnArchiver.getSourceFile() );
74      }
75  
76      public void testLookup()
77          throws Exception
78      {
79          lookup( UnArchiver.ROLE, "tar.snappy" );
80      }
81  
82  }