KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > ChecksumTest


1 /*
2  * Copyright 2001,2003-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
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 JavaDoc;
24 import java.io.File JavaDoc;
25
26 /**
27  */

28 public class ChecksumTest extends BuildFileTest {
29
30     public ChecksumTest(String JavaDoc 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 JavaDoc {
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 JavaDoc shouldExist = project.resolveFile("checksum/checksums/foo/zap/Eenie.MD5");
67         File JavaDoc 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 JavaDoc 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