1 17 18 package org.apache.tools.ant.taskdefs; 19 import org.apache.tools.ant.BuildFileTest; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.util.zip.ZipEntry ; 24 import java.util.zip.ZipFile ; 25 import java.util.Enumeration ; 26 27 29 public class ZipTest extends BuildFileTest { 30 ZipFile zfPrefixAddsDir = null; 32 public ZipTest(String name) { 33 super(name); 34 } 35 36 public void setUp() { 37 configureProject("src/etc/testcases/taskdefs/zip.xml"); 38 } 39 40 public void test1() { 41 expectBuildException("test1", "required argument not specified"); 42 } 43 44 public void test2() { 45 expectBuildException("test2", "required argument not specified"); 46 } 47 48 public void test3() { 49 expectBuildException("test3", "zip cannot include itself"); 50 } 51 52 56 public void tearDown() { 57 try { 58 if ( zfPrefixAddsDir != null) { 59 zfPrefixAddsDir.close(); 60 } 61 62 } catch (IOException e) { 63 } 65 executeTarget("cleanup"); 66 } 67 68 public void test5() { 69 executeTarget("test5"); 70 } 71 72 73 public void test6() { 74 executeTarget("test6"); 75 } 76 77 78 public void test7() { 79 executeTarget("test7"); 80 } 81 82 public void test8() { 83 executeTarget("test8"); 84 } 85 86 public void testZipgroupfileset() throws IOException { 87 executeTarget("testZipgroupfileset"); 88 89 ZipFile zipFile = new ZipFile (new File (getProjectDir(), "zipgroupfileset.zip")); 90 91 assertTrue(zipFile.getEntry("ant.xml") != null); 92 assertTrue(zipFile.getEntry("optional/jspc.xml") != null); 93 assertTrue(zipFile.getEntry("zip/zipgroupfileset3.zip") != null); 94 95 assertTrue(zipFile.getEntry("test6.mf") == null); 96 assertTrue(zipFile.getEntry("test7.mf") == null); 97 98 zipFile.close(); 99 } 100 101 public void testUpdateNotNecessary() { 102 executeTarget("testUpdateNotNecessary"); 103 assertEquals(-1, getLog().indexOf("Updating")); 104 } 105 106 public void testUpdateIsNecessary() { 107 expectLogContaining("testUpdateIsNecessary", "Updating"); 108 } 109 110 public void testPrefixAddsDir() throws IOException { 112 executeTarget("testPrefixAddsDir"); 113 File archive = getProject().resolveFile("test3.zip"); 114 zfPrefixAddsDir = new ZipFile (archive); 115 ZipEntry ze = zfPrefixAddsDir.getEntry("test/"); 116 assertNotNull("test/ has been added", ze); 117 118 } 119 120 public void testFilesOnlyDoesntCauseRecreate() 122 throws InterruptedException { 123 executeTarget("testFilesOnlyDoesntCauseRecreateSetup"); 124 long l = getProject().resolveFile("test3.zip").lastModified(); 125 Thread.currentThread().sleep(3000); 126 executeTarget("testFilesOnlyDoesntCauseRecreate"); 127 assertEquals(l, getProject().resolveFile("test3.zip").lastModified()); 128 } 129 130 public void testEmptySkip() { 132 executeTarget("testEmptySkip"); 133 assertTrue("archive should get skipped", 134 !getProject().resolveFile("test3.zip").exists()); 135 } 136 public void testZipEmptyDir() { 138 executeTarget("zipEmptyDir"); 139 assertTrue("archive should be created", 140 getProject().resolveFile("test3.zip").exists()); 141 } 142 public void testZipEmptyCreate() { 143 expectLogContaining("zipEmptyCreate", "Note: creating empty"); 144 assertTrue("archive should be created", 145 getProject().resolveFile("test3.zip").exists()); 146 147 } 148 } 149 | Popular Tags |