1 17 18 package org.apache.tools.ant.taskdefs; 19 20 import org.apache.tools.ant.BuildFileTest; 21 import org.apache.tools.ant.util.FileUtils; 22 23 import java.io.IOException ; 24 import java.io.File ; 25 26 28 public class ChecksumTest extends BuildFileTest { 29 30 public ChecksumTest(String name) { 31 super(name); 32 } 33 34 public void setUp() { 35 configureProject("src/etc/testcases/taskdefs/checksum.xml"); 36 } 37 38 public void tearDown() { 39 executeTarget("cleanup"); 40 } 41 42 public void testCreateMd5() throws IOException { 43 FileUtils fileUtils = FileUtils.newFileUtils(); 44 executeTarget("createMd5"); 45 assertTrue(fileUtils.contentEquals(project.resolveFile("expected/asf-logo.gif.md5"), 46 project.resolveFile("../asf-logo.gif.MD5"))); 47 } 48 49 public void testSetProperty() { 50 executeTarget("setProperty"); 51 assertEquals("0541d3df42520911f268abc730f3afe0", 52 project.getProperty("logo.MD5")); 53 assertTrue(!project.resolveFile("../asf-logo.gif.MD5").exists()); 54 } 55 56 public void testVerifyTotal() { 57 executeTarget("verifyTotal"); 58 assertEquals("ef8f1477fcc9bf93832c1a74f629c626", 59 project.getProperty("total")); 60 } 61 62 public void testVerifyChecksumdir() { 63 executeTarget("verifyChecksumdir"); 64 assertEquals("ef8f1477fcc9bf93832c1a74f629c626", 65 project.getProperty("total")); 66 File shouldExist = project.resolveFile("checksum/checksums/foo/zap/Eenie.MD5"); 67 File shouldNotExist = project.resolveFile("checksum/foo/zap/Eenie.MD5"); 68 assertTrue( "Checksums should be written to " + shouldExist.getAbsolutePath(), shouldExist.exists()); 69 assertTrue( "Checksums should not be written to " + shouldNotExist.getAbsolutePath(), !shouldNotExist.exists()); 70 } 71 72 public void testVerifyAsTask() { 73 testVerify("verifyAsTask"); 74 assertNotNull(project.getProperty("no.logo.MD5")); 75 assertEquals("false", project.getProperty("no.logo.MD5")); 76 } 77 78 public void testVerifyAsCondition() { 79 testVerify("verifyAsCondition"); 80 assertNull(project.getProperty("no.logo.MD5")); 81 } 82 83 public void testVerifyFromProperty() { 84 assertNull(getProject().getProperty("verify")); 85 expectPropertySet("verifyFromProperty", "verify", "true"); 86 } 87 88 public void testVerifyChecksumdirNoTotal() { 89 executeTarget("verifyChecksumdirNoTotal"); 90 } 91 private void testVerify(String target) { 92 assertNull(project.getProperty("logo.MD5")); 93 assertNull(project.getProperty("no.logo.MD5")); 94 executeTarget(target); 95 assertNotNull(project.getProperty("logo.MD5")); 96 assertEquals("true", project.getProperty("logo.MD5")); 97 } 98 99 } 100 | Popular Tags |