You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/03/30 03:18:02 UTC
svn commit: r759826 -
/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
Author: sebb
Date: Mon Mar 30 01:18:02 2009
New Revision: 759826
URL: http://svn.apache.org/viewvc?rev=759826&view=rev
Log:
Add some tests with a single file archive
Modified:
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java?rev=759826&r1=759825&r2=759826&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java (original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java Mon Mar 30 01:18:02 2009
@@ -637,4 +637,94 @@
this.checkArchiveContent(result, archiveList);
}
+
+ /**
+ * Check can delete and add a file to an archive with a single file
+ *
+ * @throws Exception
+ */
+ public void testDeleteAddToOneFileArchive() throws Exception {
+ File input = this.createSingleEntryArchive("zip");
+
+ ArchiveOutputStream out = null;
+ ArchiveInputStream ais = null;
+ InputStream is = null;
+ File result = File.createTempFile("test", ".zip");
+ result.deleteOnExit();
+ ChangeSet changes = new ChangeSet();
+ try {
+
+ is = new FileInputStream(input);
+ ais = factory.createArchiveInputStream("zip", is);
+
+ out = factory.createArchiveOutputStream("zip",
+ new FileOutputStream(result));
+ changes.delete("testdata");
+ archiveListDelete("testdata");
+
+ ArchiveEntry entry = new ZipArchiveEntry("bla/test.txt");
+ changes.add(entry, new FileInputStream(getFile("test.txt")));
+ archiveList.add("bla/test.txt");
+
+ changes.perform(ais, out);
+ is.close();
+
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ if (ais != null) {
+ ais.close(); // will close is
+ } else if (is != null){
+ is.close();
+ }
+ }
+
+ this.checkArchiveContent(result, archiveList);
+ }
+
+ /**
+ * Check can add and delete a file to an archive with a single file
+ *
+ * @throws Exception
+ */
+ public void testAddDeleteToOneFileArchive() throws Exception {
+ File input = this.createSingleEntryArchive("zip");
+
+ ArchiveOutputStream out = null;
+ ArchiveInputStream ais = null;
+ InputStream is = null;
+ File result = File.createTempFile("test", ".zip");
+ result.deleteOnExit();
+ ChangeSet changes = new ChangeSet();
+ try {
+
+ is = new FileInputStream(input);
+ ais = factory.createArchiveInputStream("zip", is);
+
+ out = factory.createArchiveOutputStream("zip",
+ new FileOutputStream(result));
+ ArchiveEntry entry = new ZipArchiveEntry("bla/test.txt");
+ changes.add(entry, new FileInputStream(getFile("test.txt")));
+ archiveList.add("bla/test.txt");
+
+ changes.delete("testdata");
+ archiveListDelete("testdata");
+
+ changes.perform(ais, out);
+ is.close();
+
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ if (ais != null) {
+ ais.close(); // will close is
+ } else if (is != null){
+ is.close();
+ }
+ }
+
+ this.checkArchiveContent(result, archiveList);
+ }
}