KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > ZipFileSetTest


1 /*
2  * Copyright 2003-2004 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
18 package org.apache.tools.ant.types;
19
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.Project;
22
23 import junit.framework.TestCase;
24 import junit.framework.AssertionFailedError;
25
26 import java.io.File JavaDoc;
27
28 /**
29  * JUnit 3 testcases for org.apache.tools.ant.types.ZipFileSet.
30  *
31  * <p>This doesn't actually test much, mainly reference handling.
32  *
33  */

34
35 public class ZipFileSetTest extends AbstractFileSetTest {
36
37     public ZipFileSetTest(String JavaDoc name) {
38         super(name);
39     }
40
41     protected AbstractFileSet getInstance() {
42         return new ZipFileSet();
43     }
44     public final void testAttributes() {
45         ZipFileSet f = (ZipFileSet)getInstance();
46         //check that dir and src are incompatible
47
f.setSrc(new File JavaDoc("example.zip"));
48         try {
49             f.setDir(new File JavaDoc("examples"));
50             fail("can add dir to "
51                     + f.getDataTypeName()
52                     + " when a src is already present");
53         } catch (BuildException be) {
54             assertEquals("Cannot set both dir and src attributes",be.getMessage());
55         }
56         f = (ZipFileSet)getInstance();
57         //check that dir and src are incompatible
58
f.setDir(new File JavaDoc("examples"));
59         try {
60             f.setSrc(new File JavaDoc("example.zip"));
61             fail("can add src to "
62                     + f.getDataTypeName()
63                     + " when a dir is already present");
64         } catch (BuildException be) {
65             assertEquals("Cannot set both dir and src attributes",be.getMessage());
66         }
67         //check that fullpath and prefix are incompatible
68
f = (ZipFileSet)getInstance();
69         f.setSrc(new File JavaDoc("example.zip"));
70         f.setPrefix("/examples");
71         try {
72             f.setFullpath("/doc/manual/index.html");
73             fail("Can add fullpath to "
74                     + f.getDataTypeName()
75                     + " when a prefix is already present");
76         } catch (BuildException be) {
77             assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());
78         }
79         f = (ZipFileSet)getInstance();
80         f.setSrc(new File JavaDoc("example.zip"));
81         f.setFullpath("/doc/manual/index.html");
82         try {
83             f.setPrefix("/examples");
84             fail("Can add prefix to "
85                     + f.getDataTypeName()
86                     + " when a fullpath is already present");
87         } catch (BuildException be) {
88             assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());
89         }
90         // check that reference zipfilesets cannot have specific attributes
91
f = (ZipFileSet)getInstance();
92         f.setRefid(new Reference("test"));
93         try {
94             f.setSrc(new File JavaDoc("example.zip"));
95             fail("Can add src to "
96                     + f.getDataTypeName()
97                     + " when a refid is already present");
98         } catch (BuildException be) {
99             assertEquals("You must not specify more than one "
100             + "attribute when using refid", be.getMessage());
101         }
102         // check that a reference zipfileset gets the same attributes as the original
103
f = (ZipFileSet)getInstance();
104         f.setSrc(new File JavaDoc("example.zip"));
105         f.setPrefix("/examples");
106         f.setFileMode("600");
107         f.setDirMode("530");
108         getProject().addReference("test",f);
109         ZipFileSet zid=(ZipFileSet)getInstance();
110         zid.setRefid(new Reference("test"));
111         assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject())));
112         assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject())));
113         assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject()));
114         assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject()));
115       }
116
117
118 }
119
Popular Tags