001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import java.io.File;
022: import java.io.IOException;
023: import java.util.zip.ZipEntry;
024: import java.util.zip.ZipException;
025: import java.util.zip.ZipFile;
026:
027: import org.apache.tools.ant.BuildFileTest;
028: import org.apache.tools.zip.UnixStat;
029:
030: /**
031: */
032: public class ZipTest extends BuildFileTest {
033: //instance variable to allow cleanup
034: ZipFile zfPrefixAddsDir = null;
035:
036: public ZipTest(String name) {
037: super (name);
038: }
039:
040: public void setUp() {
041: configureProject("src/etc/testcases/taskdefs/zip.xml");
042: }
043:
044: public void test1() {
045: expectBuildException("test1", "required argument not specified");
046: }
047:
048: public void test2() {
049: expectBuildException("test2", "required argument not specified");
050: }
051:
052: public void test3() {
053: expectBuildException("test3", "zip cannot include itself");
054: }
055:
056: // public void test4() {
057: // expectBuildException("test4", "zip cannot include itself");
058: // }
059:
060: public void tearDown() {
061: try {
062: if (zfPrefixAddsDir != null) {
063: zfPrefixAddsDir.close();
064: }
065:
066: } catch (IOException e) {
067: //ignored
068: }
069: executeTarget("cleanup");
070: }
071:
072: public void test5() {
073: executeTarget("test5");
074: }
075:
076: public void test6() {
077: executeTarget("test6");
078: }
079:
080: public void test7() {
081: executeTarget("test7");
082: }
083:
084: public void test8() {
085: executeTarget("test8");
086: }
087:
088: public void testZipgroupfileset() throws IOException {
089: executeTarget("testZipgroupfileset");
090:
091: ZipFile zipFile = new ZipFile(new File(getProjectDir(),
092: "zipgroupfileset.zip"));
093:
094: assertTrue(zipFile.getEntry("ant.xml") != null);
095: assertTrue(zipFile.getEntry("optional/jspc.xml") != null);
096: assertTrue(zipFile.getEntry("zip/zipgroupfileset3.zip") != null);
097:
098: assertTrue(zipFile.getEntry("test6.mf") == null);
099: assertTrue(zipFile.getEntry("test7.mf") == null);
100:
101: zipFile.close();
102: }
103:
104: public void testUpdateNotNecessary() {
105: executeTarget("testUpdateNotNecessary");
106: assertEquals(-1, getLog().indexOf("Updating"));
107: }
108:
109: public void testUpdateIsNecessary() {
110: expectLogContaining("testUpdateIsNecessary", "Updating");
111: }
112:
113: // Bugzilla Report 18403
114: public void testPrefixAddsDir() throws IOException {
115: executeTarget("testPrefixAddsDir");
116: File archive = getProject().resolveFile("test3.zip");
117: zfPrefixAddsDir = new ZipFile(archive);
118: ZipEntry ze = zfPrefixAddsDir.getEntry("test/");
119: assertNotNull("test/ has been added", ze);
120:
121: }
122:
123: // Bugzilla Report 19449
124: public void testFilesOnlyDoesntCauseRecreate()
125: throws InterruptedException {
126: executeTarget("testFilesOnlyDoesntCauseRecreateSetup");
127: long l = getProject().resolveFile("test3.zip").lastModified();
128: Thread.sleep(3000);
129: executeTarget("testFilesOnlyDoesntCauseRecreate");
130: assertEquals(l, getProject().resolveFile("test3.zip")
131: .lastModified());
132: }
133:
134: // Bugzilla Report 22865
135: public void testEmptySkip() {
136: executeTarget("testEmptySkip");
137: }
138:
139: // Bugzilla Report 30365
140: public void testZipEmptyDir() {
141: executeTarget("zipEmptyDir");
142: }
143:
144: // Bugzilla Report 40258
145: public void testZipEmptyDirFilesOnly() {
146: executeTarget("zipEmptyDirFilesOnly");
147: }
148:
149: public void testZipEmptyCreate() {
150: expectLogContaining("zipEmptyCreate", "Note: creating empty");
151: }
152:
153: // Bugzilla Report 25513
154: public void testCompressionLevel() {
155: executeTarget("testCompressionLevel");
156: }
157:
158: // Bugzilla Report 33412
159: public void testDefaultExcludesAndUpdate() throws ZipException,
160: IOException {
161: executeTarget("testDefaultExcludesAndUpdate");
162: ZipFile f = null;
163: try {
164: f = new ZipFile(getProject().resolveFile("test3.zip"));
165: assertNotNull("ziptest~ should be included", f
166: .getEntry("ziptest~"));
167: } finally {
168: if (f != null) {
169: f.close();
170: }
171: }
172: }
173:
174: public void testFileResource() {
175: executeTarget("testFileResource");
176: }
177:
178: public void testNonFileResource() {
179: executeTarget("testNonFileResource");
180: }
181:
182: public void testTarFileSet() throws IOException {
183: executeTarget("testTarFileSet");
184: org.apache.tools.zip.ZipFile zf = null;
185: try {
186: zf = new org.apache.tools.zip.ZipFile(getProject()
187: .resolveFile("test3.zip"));
188: org.apache.tools.zip.ZipEntry ze = zf
189: .getEntry("asf-logo.gif");
190: assertEquals(UnixStat.FILE_FLAG | 0446, ze.getUnixMode());
191: } finally {
192: if (zf != null) {
193: zf.close();
194: }
195: }
196: }
197: }
|