Author: bodewig Date: Wed Aug 17 03:45:08 2011 New Revision: 1158497 URL: http://svn.apache.org/viewvc?rev=1158497&view=rev Log: (mostly failing) testcase for dump stream. COMPRESS-132
Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java - copied, changed from r1158491, commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java Copied: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java (from r1158491, commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java) URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java?p2=commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java&p1=commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java&r1=1158491&r2=1158497&rev=1158497&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/DumpTestCase.java Wed Aug 17 03:45:08 2011 @@ -18,92 +18,102 @@ */ package org.apache.commons.compress.archivers; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; - -import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; -import org.apache.commons.compress.utils.IOUtils; +import java.util.ArrayList; import org.apache.commons.compress.AbstractTestCase; +import org.apache.commons.compress.archivers.dump.DumpArchiveInputStream; +import org.apache.commons.compress.utils.IOUtils; -public final class JarTestCase extends AbstractTestCase { - public void testJarArchiveCreation() throws Exception { - final File output = new File(dir, "bla.jar"); - - final File file1 = getFile("test1.xml"); - final File file2 = getFile("test2.xml"); - - final OutputStream out = new FileOutputStream(output); - - final ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("jar", out); - - os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml")); - IOUtils.copy(new FileInputStream(file1), os); - os.closeArchiveEntry(); - - os.putArchiveEntry(new ZipArchiveEntry("testdata/test2.xml")); - IOUtils.copy(new FileInputStream(file2), os); - os.closeArchiveEntry(); +public final class DumpTestCase extends AbstractTestCase { - os.close(); + public void testDumpUnarchiveAll() throws Exception { + unarchiveAll(getFile("bla.dump")); } + public void testCompressedDumpUnarchiveAll() throws Exception { + unarchiveAll(getFile("bla.z.dump")); + } - public void testJarUnarchive() throws Exception { - final File input = getFile("bla.jar"); + private void unarchiveAll(final File input) throws Exception { final InputStream is = new FileInputStream(input); - final ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("jar", is); - - ZipArchiveEntry entry = (ZipArchiveEntry)in.getNextEntry(); - File o = new File(dir, entry.getName()); - o.getParentFile().mkdirs(); - OutputStream out = new FileOutputStream(o); - IOUtils.copy(in, out); - out.close(); - - entry = (ZipArchiveEntry)in.getNextEntry(); - o = new File(dir, entry.getName()); - o.getParentFile().mkdirs(); - out = new FileOutputStream(o); - IOUtils.copy(in, out); - out.close(); - - entry = (ZipArchiveEntry)in.getNextEntry(); - o = new File(dir, entry.getName()); - o.getParentFile().mkdirs(); - out = new FileOutputStream(o); - IOUtils.copy(in, out); - out.close(); + ArchiveInputStream in = null; + OutputStream out = null; + try { + in = new ArchiveStreamFactory() + .createArchiveInputStream("dump", is); + + ArchiveEntry entry = in.getNextEntry(); + while (entry != null) { + File archiveEntry = new File(dir, entry.getName()); + archiveEntry.getParentFile().mkdirs(); + if (entry.isDirectory()) { + archiveEntry.mkdir(); + entry = in.getNextEntry(); + continue; + } + out = new FileOutputStream(archiveEntry); + IOUtils.copy(in, out); + out.close(); + out = null; + entry = in.getNextEntry(); + } + } finally { + if (out != null) { + out.close(); + } + if (in != null) { + in.close(); + } + is.close(); + } + } - in.close(); - is.close(); + public void YtestArchiveDetection() throws Exception { + archiveDetection(getFile("bla.dump")); } - public void testJarUnarchiveAll() throws Exception { - final File input = getFile("bla.jar"); - final InputStream is = new FileInputStream(input); - final ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("jar", is); + public void YtestCompressedArchiveDetection() throws Exception { + archiveDetection(getFile("bla.z.dump")); + } - ArchiveEntry entry = in.getNextEntry(); - while (entry != null) { - File archiveEntry = new File(dir, entry.getName()); - archiveEntry.getParentFile().mkdirs(); - if(entry.isDirectory()){ - archiveEntry.mkdir(); - entry = in.getNextEntry(); - continue; - } - OutputStream out = new FileOutputStream(archiveEntry); - IOUtils.copy(in, out); - out.close(); - entry = in.getNextEntry(); + private void archiveDetection(final File f) throws Exception { + final InputStream is = new FileInputStream(f); + try { + assertEquals(DumpArchiveInputStream.class, + new ArchiveStreamFactory() + .createArchiveInputStream(new BufferedInputStream(is)) + .getClass()); + } finally { + is.close(); } + } + + public void XtestCheckArchive() throws Exception { + checkDumpArchive(getFile("bla.dump")); + } - in.close(); - is.close(); + public void XtestCheckCompressedArchive() throws Exception { + checkDumpArchive(getFile("bla.z.dump")); } + private void checkDumpArchive(final File f) throws Exception { + ArrayList<String> expected = new ArrayList<String>(); + expected.add("."); + expected.add("./lost+found"); + expected.add("./test1.xml"); + expected.add("./test2.xml"); + final InputStream is = new FileInputStream(f); + try { + checkArchiveContent(new DumpArchiveInputStream(is), + expected); + } finally { + is.close(); + } + } }