1 | /*
|
---|
2 | * Copyright 2003-2004 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.types;
|
---|
19 |
|
---|
20 | import org.apache.tools.ant.BuildException;
|
---|
21 | import org.apache.tools.ant.BuildFileTest;
|
---|
22 | import org.apache.tools.ant.Project;
|
---|
23 | import org.apache.tools.ant.Task;
|
---|
24 | import org.apache.tools.ant.taskdefs.condition.Condition;
|
---|
25 |
|
---|
26 | public class AddTypeTest extends BuildFileTest {
|
---|
27 |
|
---|
28 | public AddTypeTest(String name) {
|
---|
29 | super(name);
|
---|
30 | }
|
---|
31 |
|
---|
32 | public void setUp() {
|
---|
33 | configureProject("src/etc/testcases/types/addtype.xml");
|
---|
34 | }
|
---|
35 |
|
---|
36 | public void testAddPath() {
|
---|
37 | executeTarget("addpath");
|
---|
38 | }
|
---|
39 |
|
---|
40 | public void testAddCondition() {
|
---|
41 | executeTarget("addcondition");
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void testAddFilter() {
|
---|
45 | executeTarget("addfilter");
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void testAddSelector() {
|
---|
49 | executeTarget("addselector");
|
---|
50 | }
|
---|
51 |
|
---|
52 | public void testNestedA() {
|
---|
53 | expectLogContaining("nested.a", "add A called");
|
---|
54 | }
|
---|
55 |
|
---|
56 | public void testNestedB() {
|
---|
57 | expectLogContaining("nested.b", "add B called");
|
---|
58 | }
|
---|
59 |
|
---|
60 | public void testNestedC() {
|
---|
61 | expectLogContaining("nested.c", "add C called");
|
---|
62 | }
|
---|
63 |
|
---|
64 | public void testNestedAB() {
|
---|
65 | expectBuildExceptionContaining(
|
---|
66 | "nested.ab", "Should have got ambiguous", "ambiguous");
|
---|
67 | }
|
---|
68 |
|
---|
69 | public void testConditionType() {
|
---|
70 | expectLogContaining("condition.type", "beforeafter");
|
---|
71 | }
|
---|
72 |
|
---|
73 | public void testConditionTask() {
|
---|
74 | expectLogContaining("condition.task", "My Condition execution");
|
---|
75 | }
|
---|
76 | public void testConditionConditionType() {
|
---|
77 | expectLogContaining("condition.condition.type", "My Condition eval");
|
---|
78 | }
|
---|
79 | public void testConditionConditionTask() {
|
---|
80 | expectBuildExceptionContaining(
|
---|
81 | "condition.condition.task", "task masking condition",
|
---|
82 | "doesn't support the nested");
|
---|
83 | }
|
---|
84 |
|
---|
85 | public void testAddConfigured() {
|
---|
86 | expectLogContaining(
|
---|
87 | "myaddconfigured", "value is Value Setexecute: value is Value Set");
|
---|
88 | }
|
---|
89 |
|
---|
90 | public void testNamespace() {
|
---|
91 | executeTarget("namespacetest");
|
---|
92 | }
|
---|
93 |
|
---|
94 | // The following will be used as types and tasks
|
---|
95 |
|
---|
96 | public static interface A {}
|
---|
97 | public static interface B {}
|
---|
98 | public static interface C extends A {}
|
---|
99 | public static interface AB extends A, B {}
|
---|
100 |
|
---|
101 | public static class AImpl implements A{}
|
---|
102 | public static class BImpl implements B{}
|
---|
103 | public static class CImpl implements C{}
|
---|
104 | public static class ABImpl implements AB{}
|
---|
105 |
|
---|
106 | public static class NestedContainer
|
---|
107 | extends Task
|
---|
108 | {
|
---|
109 | public void add(A el) {
|
---|
110 | log("add A called");
|
---|
111 | }
|
---|
112 | public void add(B el) {
|
---|
113 | log("add B called");
|
---|
114 | }
|
---|
115 | public void add(C el) {
|
---|
116 | log("add C called");
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | public static class MyCondition
|
---|
121 | implements Condition
|
---|
122 | {
|
---|
123 | Project project;
|
---|
124 | public void setProject(Project project) {
|
---|
125 | this.project = project;
|
---|
126 | }
|
---|
127 | public boolean eval() {
|
---|
128 | project.log("My Condition eval");
|
---|
129 | return true;
|
---|
130 | }
|
---|
131 | public void execute() {
|
---|
132 | project.log("My Condition execution");
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | public static class MyValue
|
---|
137 | {
|
---|
138 | private String text = "NOT SET YET";
|
---|
139 | public void addText(String text) {
|
---|
140 | this.text = text;
|
---|
141 | }
|
---|
142 | public String toString() {
|
---|
143 | return text;
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | public static class MyAddConfigured
|
---|
148 | extends Task
|
---|
149 | {
|
---|
150 | MyValue value;
|
---|
151 | public void addConfigured(MyValue value) {
|
---|
152 | log("value is " + value);
|
---|
153 | this.value = value;
|
---|
154 | }
|
---|
155 | public void execute() {
|
---|
156 | log("execute: value is " + value);
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | }
|
---|