1 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 ; 27 28 34 35 public class ZipFileSetTest extends AbstractFileSetTest { 36 37 public ZipFileSetTest(String 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 f.setSrc(new File ("example.zip")); 48 try { 49 f.setDir(new File ("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 f.setDir(new File ("examples")); 59 try { 60 f.setSrc(new File ("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 f = (ZipFileSet)getInstance(); 69 f.setSrc(new File ("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 ("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 f = (ZipFileSet)getInstance(); 92 f.setRefid(new Reference("test")); 93 try { 94 f.setSrc(new File ("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 f = (ZipFileSet)getInstance(); 104 f.setSrc(new File ("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 |