~ubuntu-branches/ubuntu/utopic/ant/utopic

« back to all changes in this revision

Viewing changes to src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-15 16:19:56 UTC
  • mfrom: (1.3.3) (5.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130515161956-vd4ht4u68rok767b
Tags: 1.9.1-1
* New upstream release
  - Refreshed the patches
  - Removed patch 0001-detect-classpath-based-JVM (merged upstream)
* Enabled hardening for the -gcj packages
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 *  contributor license agreements.  See the NOTICE file distributed with
4
 
 *  this work for additional information regarding copyright ownership.
5
 
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 *  (the "License"); you may not use this file except in compliance with
7
 
 *  the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
11
 
 *  Unless required by applicable law or agreed to in writing, software
12
 
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
 *  See the License for the specific language governing permissions and
15
 
 *  limitations under the License.
16
 
 *
17
 
 */
18
 
 
19
 
package org.apache.tools.ant.taskdefs;
20
 
 
21
 
import java.io.FileInputStream;
22
 
 
23
 
import org.apache.tools.ant.BuildFileTest;
24
 
import org.apache.tools.ant.input.PropertyFileInputHandler;
25
 
 
26
 
 
27
 
public class InputTest extends BuildFileTest {
28
 
 
29
 
    public InputTest(String name) {
30
 
        super(name);
31
 
    }
32
 
 
33
 
    public void setUp() {
34
 
        configureProject("src/etc/testcases/taskdefs/input.xml");
35
 
        System.getProperties()
36
 
            .put(PropertyFileInputHandler.FILE_NAME_KEY,
37
 
                 getProject().resolveFile("input.properties")
38
 
                 .getAbsolutePath());
39
 
        getProject().setInputHandler(new PropertyFileInputHandler());
40
 
    }
41
 
 
42
 
    public void test1() {
43
 
        executeTarget("test1");
44
 
    }
45
 
 
46
 
    public void test2() {
47
 
        executeTarget("test2");
48
 
    }
49
 
 
50
 
    public void test3() {
51
 
        expectSpecificBuildException("test3", "invalid input",
52
 
                                     "Found invalid input test for \'"
53
 
                                     + getKey("All data is"
54
 
                                              + " going to be deleted from DB"
55
 
                                              + " continue?")
56
 
                                     + "\'");
57
 
    }
58
 
 
59
 
    public void test5() {
60
 
        executeTarget("test5");
61
 
    }
62
 
 
63
 
    public void test6() {
64
 
        executeTarget("test6");
65
 
        assertEquals("scott", project.getProperty("db.user"));
66
 
    }
67
 
 
68
 
    public void testPropertyFileInlineHandler() {
69
 
        executeTarget("testPropertyFileInlineHandler");
70
 
    }
71
 
 
72
 
    public void testDefaultInlineHandler() {
73
 
        stdin();
74
 
        executeTarget("testDefaultInlineHandler");
75
 
    }
76
 
 
77
 
    public void testGreedyInlineHandler() {
78
 
        stdin();
79
 
        executeTarget("testGreedyInlineHandler");
80
 
    }
81
 
 
82
 
    public void testGreedyInlineHandlerClassname() {
83
 
        stdin();
84
 
        executeTarget("testGreedyInlineHandlerClassname");
85
 
    }
86
 
 
87
 
    public void testGreedyInlineHandlerRefid() {
88
 
        stdin();
89
 
        executeTarget("testGreedyInlineHandlerRefid");
90
 
    }
91
 
 
92
 
    private void stdin() {
93
 
        try {
94
 
            System.setIn(new FileInputStream(
95
 
                getProject().resolveFile("input.stdin")));
96
 
        } catch (Exception e) {
97
 
            throw e instanceof RuntimeException
98
 
                ? (RuntimeException) e : new RuntimeException(e.getMessage());
99
 
        }
100
 
    }
101
 
 
102
 
    private String getKey(String key) {
103
 
        return key; // XXX what is this for?
104
 
    }
105
 
 
106
 
}
 
1
/*
 
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 *  contributor license agreements.  See the NOTICE file distributed with
 
4
 *  this work for additional information regarding copyright ownership.
 
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 *  (the "License"); you may not use this file except in compliance with
 
7
 *  the License.  You may obtain a copy of the License at
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
11
 *  Unless required by applicable law or agreed to in writing, software
 
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 *  See the License for the specific language governing permissions and
 
15
 *  limitations under the License.
 
16
 *
 
17
 */
 
18
 
 
19
package org.apache.tools.ant.taskdefs;
 
20
 
 
21
import java.io.FileInputStream;
 
22
 
 
23
import org.apache.tools.ant.BuildFileTest;
 
24
import org.apache.tools.ant.input.PropertyFileInputHandler;
 
25
 
 
26
 
 
27
public class InputTest extends BuildFileTest {
 
28
 
 
29
    public InputTest(String name) {
 
30
        super(name);
 
31
    }
 
32
 
 
33
    public void setUp() {
 
34
        configureProject("src/etc/testcases/taskdefs/input.xml");
 
35
        System.getProperties()
 
36
            .put(PropertyFileInputHandler.FILE_NAME_KEY,
 
37
                 getProject().resolveFile("input.properties")
 
38
                 .getAbsolutePath());
 
39
        getProject().setInputHandler(new PropertyFileInputHandler());
 
40
    }
 
41
 
 
42
    public void test1() {
 
43
        executeTarget("test1");
 
44
    }
 
45
 
 
46
    public void test2() {
 
47
        executeTarget("test2");
 
48
    }
 
49
 
 
50
    public void test3() {
 
51
        expectSpecificBuildException("test3", "invalid input",
 
52
                                     "Found invalid input test for \'"
 
53
                                     + getKey("All data is"
 
54
                                              + " going to be deleted from DB"
 
55
                                              + " continue?")
 
56
                                     + "\'");
 
57
    }
 
58
 
 
59
    public void test5() {
 
60
        executeTarget("test5");
 
61
    }
 
62
 
 
63
    public void test6() {
 
64
        executeTarget("test6");
 
65
        assertEquals("scott", project.getProperty("db.user"));
 
66
    }
 
67
 
 
68
    public void testPropertyFileInlineHandler() {
 
69
        executeTarget("testPropertyFileInlineHandler");
 
70
    }
 
71
 
 
72
    public void testDefaultInlineHandler() {
 
73
        stdin();
 
74
        executeTarget("testDefaultInlineHandler");
 
75
    }
 
76
 
 
77
    public void testGreedyInlineHandler() {
 
78
        stdin();
 
79
        executeTarget("testGreedyInlineHandler");
 
80
    }
 
81
 
 
82
    public void testGreedyInlineHandlerClassname() {
 
83
        stdin();
 
84
        executeTarget("testGreedyInlineHandlerClassname");
 
85
    }
 
86
 
 
87
    public void testGreedyInlineHandlerRefid() {
 
88
        stdin();
 
89
        executeTarget("testGreedyInlineHandlerRefid");
 
90
    }
 
91
 
 
92
    private void stdin() {
 
93
        try {
 
94
            System.setIn(new FileInputStream(
 
95
                getProject().resolveFile("input.stdin")));
 
96
        } catch (Exception e) {
 
97
            throw e instanceof RuntimeException
 
98
                ? (RuntimeException) e : new RuntimeException(e.getMessage());
 
99
        }
 
100
    }
 
101
 
 
102
    private String getKey(String key) {
 
103
        return key; // XXX what is this for?
 
104
    }
 
105
 
 
106
}