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 org.apache.tools.ant.BuildFileTest;
022: import org.apache.tools.ant.util.FileUtils;
023:
024: import java.io.IOException;
025:
026: /**
027: */
028: public class UnzipTest extends BuildFileTest {
029:
030: /** Utilities used for file operations */
031: private static final FileUtils FILE_UTILS = FileUtils
032: .getFileUtils();
033:
034: public UnzipTest(String name) {
035: super (name);
036: }
037:
038: public void setUp() {
039: configureProject("src/etc/testcases/taskdefs/unzip.xml");
040: }
041:
042: public void tearDown() {
043: executeTarget("cleanup");
044: }
045:
046: public void test1() {
047: expectBuildException("test1", "required argument not specified");
048: }
049:
050: public void test2() {
051: expectBuildException("test2", "required argument not specified");
052: }
053:
054: public void test3() {
055: expectBuildException("test3", "required argument not specified");
056: }
057:
058: public void testRealTest() throws java.io.IOException {
059: executeTarget("realTest");
060: assertLogoUncorrupted();
061: }
062:
063: /**
064: * test that the logo gif file has not been corrupted
065: * @throws IOException
066: */
067: private void assertLogoUncorrupted() throws IOException {
068: assertTrue(FILE_UTILS.contentEquals(project
069: .resolveFile("../asf-logo.gif"), project
070: .resolveFile("asf-logo.gif")));
071: }
072:
073: public void testTestZipTask() throws java.io.IOException {
074: executeTarget("testZipTask");
075: assertLogoUncorrupted();
076: }
077:
078: public void testTestUncompressedZipTask()
079: throws java.io.IOException {
080: executeTarget("testUncompressedZipTask");
081: assertLogoUncorrupted();
082: }
083:
084: /*
085: * PR 11100
086: */
087: public void testPatternSetExcludeOnly() {
088: executeTarget("testPatternSetExcludeOnly");
089: assertFileMissing("1/foo is excluded", "unziptestout/1/foo");
090: assertFileExists("2/bar is not excluded", "unziptestout/2/bar");
091: }
092:
093: /*
094: * PR 11100
095: */
096: public void testPatternSetIncludeOnly() {
097: executeTarget("testPatternSetIncludeOnly");
098: assertFileMissing("1/foo is not included", "unziptestout/1/foo");
099: assertFileExists("2/bar is included", "unziptestout/2/bar");
100: }
101:
102: /*
103: * PR 11100
104: */
105: public void testPatternSetIncludeAndExclude() {
106: executeTarget("testPatternSetIncludeAndExclude");
107: assertFileMissing("1/foo is not included", "unziptestout/1/foo");
108: assertFileMissing("2/bar is excluded", "unziptestout/2/bar");
109: }
110:
111: /*
112: * PR 38973
113: */
114: public void testTwoPatternSets() {
115: executeTarget("testTwoPatternSets");
116: assertFileMissing("1/foo is not included", "unziptestout/1/foo");
117: assertFileExists("2/bar is included", "unziptestout/2/bar");
118: }
119:
120: /*
121: * PR 38973
122: */
123: public void testTwoPatternSetsWithExcludes() {
124: executeTarget("testTwoPatternSetsWithExcludes");
125: assertFileMissing("1/foo is not included", "unziptestout/1/foo");
126: assertFileMissing("2/bar is excluded", "unziptestout/2/bar");
127: }
128:
129: /*
130: * PR 16213
131: */
132: public void testSelfExtractingArchive() {
133: executeTarget("selfExtractingArchive");
134: }
135:
136: /*
137: * PR 20969
138: */
139: public void testPatternSetSlashOnly() {
140: executeTarget("testPatternSetSlashOnly");
141: assertFileMissing("1/foo is not included", "unziptestout/1/foo");
142: assertFileExists("\"2/bar is included", "unziptestout/2/bar");
143: }
144:
145: /*
146: * PR 10504
147: */
148: public void testEncoding() {
149: executeTarget("encodingTest");
150: assertFileExists("foo has been properly named",
151: "unziptestout/foo");
152: }
153:
154: /*
155: * PR 21996
156: */
157: public void testFlattenMapper() {
158: executeTarget("testFlattenMapper");
159: assertFileMissing("1/foo is not flattened",
160: "unziptestout/1/foo");
161: assertFileExists("foo is flattened", "unziptestout/foo");
162: }
163:
164: /**
165: * assert that a file exists, relative to the project
166: * @param message message if there is no mpatch
167: * @param filename filename to resolve against the project
168: */
169: private void assertFileExists(String message, String filename) {
170: assertTrue(message, getProject().resolveFile(filename).exists());
171: }
172:
173: /**
174: * assert that a file doesnt exist, relative to the project
175: *
176: * @param message message if there is no mpatch
177: * @param filename filename to resolve against the project
178: */
179: private void assertFileMissing(String message, String filename) {
180: assertTrue(message, !getProject().resolveFile(filename)
181: .exists());
182: }
183:
184: /**
185: * PR 21996
186: */
187: public void testGlobMapper() {
188: executeTarget("testGlobMapper");
189: assertFileMissing("1/foo is not mapped", "unziptestout/1/foo");
190: assertFileExists("1/foo is mapped", "unziptestout/1/foo.txt");
191: }
192:
193: public void testTwoMappers() {
194: expectBuildException("testTwoMappers",
195: Expand.ERROR_MULTIPLE_MAPPERS);
196: }
197:
198: public void testResourceCollections() {
199: executeTarget("testResourceCollection");
200: assertFileExists("junit.jar has been extracted",
201: "unziptestout/junit/framework/Assert.class");
202: }
203:
204: public void testDocumentationClaimsOnCopy() {
205: executeTarget("testDocumentationClaimsOnCopy");
206: assertFileMissing("1/foo is excluded", "unziptestout/1/foo");
207: assertFileExists("2/bar is not excluded", "unziptestout/2/bar");
208: }
209: }
|