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 java.io.FileInputStream;
022:
023: import org.apache.tools.ant.BuildFileTest;
024: import org.apache.tools.ant.input.PropertyFileInputHandler;
025:
026: public class InputTest extends BuildFileTest {
027:
028: public InputTest(String name) {
029: super (name);
030: }
031:
032: public void setUp() {
033: configureProject("src/etc/testcases/taskdefs/input.xml");
034: System.getProperties().put(
035: PropertyFileInputHandler.FILE_NAME_KEY,
036: getProject().resolveFile("input.properties")
037: .getAbsolutePath());
038: getProject().setInputHandler(new PropertyFileInputHandler());
039: }
040:
041: public void test1() {
042: executeTarget("test1");
043: }
044:
045: public void test2() {
046: executeTarget("test2");
047: }
048:
049: public void test3() {
050: expectSpecificBuildException("test3", "invalid input",
051: "Found invalid input test for \'"
052: + getKey("All data is"
053: + " going to be deleted from DB"
054: + " continue?") + "\'");
055: }
056:
057: public void test5() {
058: executeTarget("test5");
059: }
060:
061: public void test6() {
062: executeTarget("test6");
063: assertEquals("scott", project.getProperty("db.user"));
064: }
065:
066: public void testPropertyFileInlineHandler() {
067: executeTarget("testPropertyFileInlineHandler");
068: }
069:
070: public void testDefaultInlineHandler() {
071: stdin();
072: executeTarget("testDefaultInlineHandler");
073: }
074:
075: public void testGreedyInlineHandler() {
076: stdin();
077: executeTarget("testGreedyInlineHandler");
078: }
079:
080: public void testGreedyInlineHandlerClassname() {
081: stdin();
082: executeTarget("testGreedyInlineHandlerClassname");
083: }
084:
085: public void testGreedyInlineHandlerRefid() {
086: stdin();
087: executeTarget("testGreedyInlineHandlerRefid");
088: }
089:
090: private void stdin() {
091: try {
092: System.setIn(new FileInputStream(getProject().resolveFile(
093: "input.stdin")));
094: } catch (Exception e) {
095: throw e instanceof RuntimeException ? (RuntimeException) e
096: : new RuntimeException(e.getMessage());
097: }
098: }
099:
100: private String getKey(String key) {
101: return key; // XXX what is this for?
102: }
103:
104: }
|