001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import org.apache.tools.ant.BuildFileTest;
022:
023: import java.io.*;
024:
025: import junit.framework.AssertionFailedError;
026:
027: /**
028: */
029: public class ReplaceTest extends BuildFileTest {
030:
031: public ReplaceTest(String name) {
032: super (name);
033: }
034:
035: public void setUp() {
036: configureProject("src/etc/testcases/taskdefs/replace.xml");
037: }
038:
039: public void test1() {
040: expectBuildException("test1", "required argument not specified");
041: }
042:
043: public void test2() {
044: expectBuildException("test2", "required argument not specified");
045: }
046:
047: public void test3() {
048: expectBuildException("test3", "required argument not specified");
049: }
050:
051: public void test4() {
052: expectBuildException("test4", "empty token not allowed");
053: }
054:
055: public void test5() {
056: executeTarget("test5");
057: }
058:
059: public void test6() {
060: expectBuildException("test6", "required argument not specified");
061: }
062:
063: public void test7() {
064: expectBuildException("test7", "empty token not allowed");
065: }
066:
067: public void test8() {
068: executeTarget("test8");
069: }
070:
071: public void test9() throws IOException {
072: executeTarget("test9");
073: String tmpdir = project.getProperty("tmp.dir");
074: assertEqualContent(new File(tmpdir, "result.txt"), new File(
075: tmpdir, "output.txt"));
076: }
077:
078: public void tearDown() {
079: executeTarget("cleanup");
080: }
081:
082: public void assertEqualContent(File expect, File result)
083: throws AssertionFailedError, IOException {
084: if (!result.exists()) {
085: fail("Expected file " + result + " doesn\'t exist");
086: }
087:
088: InputStream inExpect = null;
089: InputStream inResult = null;
090: try {
091: inExpect = new BufferedInputStream(new FileInputStream(
092: expect));
093: inResult = new BufferedInputStream(new FileInputStream(
094: result));
095:
096: int expectedByte = inExpect.read();
097: while (expectedByte != -1) {
098: assertEquals(expectedByte, inResult.read());
099: expectedByte = inExpect.read();
100: }
101: assertEquals("End of file", -1, inResult.read());
102: } finally {
103: if (inResult != null) {
104: inResult.close();
105: }
106: if (inExpect != null) {
107: inExpect.close();
108: }
109: }
110: }
111: }
|