source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/ZipTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.4 KB
Line 
1/*
2 * Copyright 2000-2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs;
19import org.apache.tools.ant.BuildFileTest;
20
21import java.io.File;
22import java.io.IOException;
23import java.util.zip.ZipEntry;
24import java.util.zip.ZipFile;
25import java.util.Enumeration;
26
27/**
28 */
29public class ZipTest extends BuildFileTest {
30 //instance variable to allow cleanup
31 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// public void test4() {
53// expectBuildException("test4", "zip cannot include itself");
54// }
55
56 public void tearDown() {
57 try {
58 if ( zfPrefixAddsDir != null) {
59 zfPrefixAddsDir.close();
60 }
61
62 } catch (IOException e) {
63 //ignored
64 }
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 // Bugzilla Report 18403
111 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 // Bugzilla Report 19449
121 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 // Bugzilla Report 22865
131 public void testEmptySkip() {
132 executeTarget("testEmptySkip");
133 assertTrue("archive should get skipped",
134 !getProject().resolveFile("test3.zip").exists());
135 }
136 // Bugzilla Report 30365
137 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}
Note: See TracBrowser for help on using the repository browser.