1 | package org.apache.tools.ant.types;↵ | | 1 | package org.apache.tools.ant.types;↵
|
|
2 | import java.io.File;↵ | | 2 | import java.io.File;↵
|
|
3 | import org.apache.tools.ant.BuildException;↵ | | 3 | import org.apache.tools.ant.BuildException;↵
|
|
4 | /**↵ | | 4 | /**↵
|
5 | * JUnit 3 testcases for org.apache.tools.ant.types.TarFileSet.↵ | | 5 | * JUnit 3 testcases for org.apache.tools.ant.types.ZipFileSet.↵
|
6 | *↵ | | 6 | *↵
|
7 | * <p>This doesn't actually test much, mainly reference handling.↵ | | 7 | * <p>This doesn't actually test much, mainly reference handling.↵
|
8 | *↵ | | 8 | *↵
|
9 | */↵ | | 9 | */↵
|
|
10 | public class TarFileSetTest extends AbstractFileSetTest {↵ | | 10 | public class ZipFileSetTest extends AbstractFileSetTest {↵
|
|
11 | public TarFileSetTest(String name) {↵ | | 11 | public ZipFileSetTest(String name) {↵
|
12 | super(name);↵ | | 12 | super(name);↵
|
13 | }↵ | | 13 | }↵
|
|
14 | protected AbstractFileSet getInstance() {↵ | | 14 | protected AbstractFileSet getInstance() {↵
|
15 | return new TarFileSet();↵ | | 15 | return new ZipFileSet();↵
|
16 | }↵ | | 16 | }↵
|
17 | public final void testAttributes() {↵ | | 17 | public final void testAttributes() {↵
|
18 | TarFileSet f = (TarFileSet)getInstance();↵ | | 18 | ZipFileSet f = (ZipFileSet)getInstance();↵
|
19 | //check that dir and src are incompatible↵ | | 19 | //check that dir and src are incompatible↵
|
20 | f.setSrc(new File("example.tar"));↵ | | 20 | f.setSrc(new File("example.zip"));↵
|
21 | try {↵ | | 21 | try {↵
|
22 | f.setDir(new File("examples"));↵ | | 22 | f.setDir(new File("examples"));↵
|
23 | fail("can add dir to "↵ | | 23 | fail("can add dir to "↵
|
24 | + f.getDataTypeName()↵ | | 24 | + f.getDataTypeName()↵
|
25 | + " when a src is already present");↵ | | 25 | + " when a src is already present");↵
|
26 | } catch (BuildException be) {↵ | | 26 | } catch (BuildException be) {↵
|
27 | assertEquals("Cannot set both dir and src attributes",be.getMessage());↵ | | 27 | assertEquals("Cannot set both dir and src attributes",be.getMessage());↵
|
28 | }↵ | | 28 | }↵
|
29 | f = (TarFileSet)getInstance();↵ | | 29 | f = (ZipFileSet)getInstance();↵
|
30 | //check that dir and src are incompatible↵ | | 30 | //check that dir and src are incompatible↵
|
31 | f.setDir(new File("examples"));↵ | | 31 | f.setDir(new File("examples"));↵
|
32 | try {↵ | | 32 | try {↵
|
33 | f.setSrc(new File("example.tar"));↵ | | 33 | f.setSrc(new File("example.zip"));↵
|
34 | fail("can add src to "↵ | | 34 | fail("can add src to "↵
|
35 | + f.getDataTypeName()↵ | | 35 | + f.getDataTypeName()↵
|
36 | + " when a dir is already present");↵ | | 36 | + " when a dir is already present");↵
|
37 | } catch (BuildException be) {↵ | | 37 | } catch (BuildException be) {↵
|
38 | assertEquals("Cannot set both dir and src attributes",be.getMessage());↵ | | 38 | assertEquals("Cannot set both dir and src attributes",be.getMessage());↵
|
39 | }↵ | | 39 | }↵
|
40 | //check that fullpath and prefix are incompatible↵ | | 40 | //check that fullpath and prefix are incompatible↵
|
41 | f = (TarFileSet)getInstance();↵ | | 41 | f = (ZipFileSet)getInstance();↵
|
42 | f.setSrc(new File("example.tar"));↵ | | 42 | f.setSrc(new File("example.zip"));↵
|
43 | f.setPrefix("/examples");↵ | | 43 | f.setPrefix("/examples");↵
|
44 | try {↵ | | 44 | try {↵
|
45 | f.setFullpath("/doc/manual/index.html");↵ | | 45 | f.setFullpath("/doc/manual/index.html");↵
|
46 | fail("Can add fullpath to "↵ | | 46 | fail("Can add fullpath to "↵
|
47 | + f.getDataTypeName()↵ | | 47 | + f.getDataTypeName()↵
|
48 | + " when a prefix is already present");↵ | | 48 | + " when a prefix is already present");↵
|
49 | } catch (BuildException be) {↵ | | 49 | } catch (BuildException be) {↵
|
50 | assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());↵ | | 50 | assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());↵
|
51 | }↵ | | 51 | }↵
|
52 | f = (TarFileSet)getInstance();↵ | | 52 | f = (ZipFileSet)getInstance();↵
|
53 | f.setSrc(new File("example.tar"));↵ | | 53 | f.setSrc(new File("example.zip"));↵
|
54 | f.setFullpath("/doc/manual/index.html");↵ | | 54 | f.setFullpath("/doc/manual/index.html");↵
|
55 | try {↵ | | 55 | try {↵
|
56 | f.setPrefix("/examples");↵ | | 56 | f.setPrefix("/examples");↵
|
57 | fail("Can add prefix to "↵ | | 57 | fail("Can add prefix to "↵
|
58 | + f.getDataTypeName()↵ | | 58 | + f.getDataTypeName()↵
|
59 | + " when a fullpath is already present");↵ | | 59 | + " when a fullpath is already present");↵
|
60 | } catch (BuildException be) {↵ | | 60 | } catch (BuildException be) {↵
|
61 | assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());↵ | | 61 | assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage());↵
|
62 | }↵ | | 62 | }↵
|
63 | // check that reference tarfilesets cannot have specific attributes↵ | | 63 | // check that reference zipfilesets cannot have specific attributes↵
|
64 | f = (TarFileSet)getInstance();↵ | | 64 | f = (ZipFileSet)getInstance();↵
|
65 | f.setRefid(new Reference("test"));↵ | | 65 | f.setRefid(new Reference("test"));↵
|
66 | try {↵ | | 66 | try {↵
|
67 | f.setSrc(new File("example.tar"));↵ | | 67 | f.setSrc(new File("example.zip"));↵
|
68 | fail("Can add src to "↵ | | 68 | fail("Can add src to "↵
|
69 | + f.getDataTypeName()↵ | | 69 | + f.getDataTypeName()↵
|
70 | + " when a refid is already present");↵ | | 70 | + " when a refid is already present");↵
|
71 | } catch (BuildException be) {↵ | | 71 | } catch (BuildException be) {↵
|
72 | assertEquals("You must not specify more than one "↵ | | 72 | assertEquals("You must not specify more than one "↵
|
73 | + "attribute when using refid", be.getMessage());↵ | | 73 | + "attribute when using refid", be.getMessage());↵
|
74 | }↵ | | 74 | }↵
|
75 | // check that a reference tarfileset gets the same attributes as the original↵ | | 75 | // check that a reference zipfileset gets the same attributes as the original↵
|
76 | f = (TarFileSet)getInstance();↵ | | 76 | f = (ZipFileSet)getInstance();↵
|
77 | f.setSrc(new File("example.tar"));↵ | | 77 | f.setSrc(new File("example.zip"));↵
|
78 | f.setPrefix("/examples");↵ | | 78 | f.setPrefix("/examples");↵
|
79 | f.setFileMode("600");↵ | | 79 | f.setFileMode("600");↵
|
80 | f.setDirMode("530");↵ | | 80 | f.setDirMode("530");↵
|
81 | getProject().addReference("test",f);↵ | | 81 | getProject().addReference("test",f);↵
|
82 | TarFileSet zid=(TarFileSet)getInstance();↵ | | 82 | ZipFileSet zid=(ZipFileSet)getInstance();↵
|
83 | zid.setRefid(new Reference("test"));↵ | | 83 | zid.setRefid(new Reference("test"));↵
|
84 | assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject())));↵ | | 84 | assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject())));↵
|
85 | assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject())));↵ | | 85 | assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject())));↵
|
86 | assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject()));↵ | | 86 | assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject()));↵
|
87 | assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject()));↵ | | 87 | assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject()));↵
|
88 | } | | 88 | }
|