|
| 1 | +/* |
| 2 | + * Copyright 2016 Codehaus. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.codehaus.plexus.archiver.tar; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | +import static junit.framework.TestCase.assertEquals; |
| 20 | +import static junit.framework.TestCase.assertTrue; |
| 21 | +import org.codehaus.plexus.PlexusTestCase; |
| 22 | +import static org.codehaus.plexus.PlexusTestCase.getTestFile; |
| 23 | +import org.codehaus.plexus.archiver.Archiver; |
| 24 | +import org.codehaus.plexus.archiver.UnArchiver; |
| 25 | +import org.codehaus.plexus.archiver.xz.XZArchiver; |
| 26 | + |
| 27 | +/** |
| 28 | + * |
| 29 | + * @author philip.lourandos |
| 30 | + */ |
| 31 | +public class TarXzUnArchiverTest extends PlexusTestCase { |
| 32 | + |
| 33 | + public void testExtract() |
| 34 | + throws Exception |
| 35 | + { |
| 36 | + TarArchiver tarArchiver = (TarArchiver) lookup( Archiver.ROLE, "tar" ); |
| 37 | + tarArchiver.setLongfile(TarLongFileMode.posix ); |
| 38 | + |
| 39 | + String fileName1 = "TarBZip2UnArchiverTest1.txt"; |
| 40 | + String fileName2 = "TarBZip2UnArchiverTest2.txt"; |
| 41 | + File file1InTar = getTestFile( "target/output/" + fileName1 ); |
| 42 | + File file2InTar = getTestFile( "target/output/" + fileName2 ); |
| 43 | + file1InTar.delete(); |
| 44 | + file2InTar.delete(); |
| 45 | + |
| 46 | + assertFalse(file1InTar.exists()); |
| 47 | + assertFalse(file2InTar.exists()); |
| 48 | + |
| 49 | + File testXZFile = getTestFile( "target/output/archive.tar.xz" ); |
| 50 | + assertFalse(testXZFile.exists()); |
| 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 | + XZArchiver xzArchiver = (XZArchiver) lookup( Archiver.ROLE, "xz" ); |
| 58 | + |
| 59 | + assertTrue(testXZFile.exists()); |
| 60 | + xzArchiver.setDestFile( testXZFile ); |
| 61 | + xzArchiver.addFile( getTestFile( "target/output/archive.tar" ), "dontcare" ); |
| 62 | + xzArchiver.createArchive(); |
| 63 | + |
| 64 | + TarXZUnArchiver tarXZUnArchiver = (TarXZUnArchiver) lookup( UnArchiver.ROLE, "tar.xz" ); |
| 65 | + |
| 66 | + tarXZUnArchiver.setDestDirectory( getTestFile( "target/output" ) ); |
| 67 | + tarXZUnArchiver.setSourceFile( testXZFile ); |
| 68 | + tarXZUnArchiver.extract(); |
| 69 | + |
| 70 | + assertTrue( file1InTar.exists() ); |
| 71 | + assertTrue( file2InTar.exists() ); |
| 72 | + |
| 73 | + assertEquals( testXZFile, tarXZUnArchiver.getSourceFile() ); |
| 74 | + } |
| 75 | + |
| 76 | + public void testLookup() throws Exception |
| 77 | + { |
| 78 | + assertNotNull( lookup( UnArchiver.ROLE, "tar.xz" ) ); |
| 79 | + } |
| 80 | +} |
0 commit comments