Author: sebb Date: Wed Apr 15 13:31:46 2009 New Revision: 765186 URL: http://svn.apache.org/viewvc?rev=765186&view=rev Log: Additional test cases
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=765186&r1=765185&r2=765186&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 Wed Apr 15 13:31:46 2009 @@ -46,7 +46,7 @@ Iterator it = archiveList.iterator(); while(it.hasNext()){ String entry = (String) it.next(); - if (entry.equals(prefix) || entry.startsWith(prefix+"/")){ + if (entry.startsWith(prefix+"/")){ // TODO won't work with folders it.remove(); } } @@ -144,6 +144,45 @@ } /** + * Tries to delete the folder "test.txt" from an archive file. + * This should not match any files/folders. + * + * @throws Exception + */ + public void testDeleteDir3() throws Exception { + final String archivename = "cpio"; + File input = this.createArchive(archivename); + + ArchiveOutputStream out = null; + ArchiveInputStream ais = null; + File result = File.createTempFile("test", "."+archivename); + result.deleteOnExit(); + try { + + final InputStream is = new FileInputStream(input); + ais = factory.createArchiveInputStream(archivename, is); + + out = factory.createArchiveOutputStream(archivename, + new FileOutputStream(result)); + + ChangeSet changes = new ChangeSet(); + changes.deleteDir("test.txt"); + archiveListDeleteDir("test.txt"); + ChangeSetPerformer performer = new ChangeSetPerformer(changes); + performer.perform(ais, out); + is.close(); + + } finally { + if (out != null) + out.close(); + if (ais != null) + ais.close(); + } + + this.checkArchiveContent(result, archiveList); + } + + /** * Tries to delete the file "bla/test5.xml" from an archive. This should * result in the deletion of "bla/test5.xml". * @@ -184,6 +223,46 @@ } /** + * Tries to delete the file "bla" from an archive. This should + * result in the deletion of nothing. + * + * @throws Exception + */ + public void testDeleteFile2() throws Exception { + final String archivename = "cpio"; + File input = this.createArchive(archivename); + + ArchiveOutputStream out = null; + ArchiveInputStream ais = null; + File result = File.createTempFile("test", "."+archivename); + result.deleteOnExit(); + try { + + final InputStream is = new FileInputStream(input); + ais = factory.createArchiveInputStream(archivename, is); + + out = factory.createArchiveOutputStream(archivename, + new FileOutputStream(result)); + + ChangeSet changes = new ChangeSet(); + changes.delete("bla"); + //archiveListDelete("bla"); + + ChangeSetPerformer performer = new ChangeSetPerformer(changes); + performer.perform(ais, out); + is.close(); + + } finally { + if (out != null) + out.close(); + if (ais != null) + ais.close(); + } + + this.checkArchiveContent(result, archiveList); + } + + /** * Tries to delete a directory with a file and adds a new directory with a * new file and with the same name. Should delete dir1/* and add * dir1/test.txt at the end