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;
020:
021: import java.util.Vector;
022:
023: /**
024: * Executor tests
025: */
026: public class ExecutorTest extends BuildFileTest implements
027: BuildListener {
028: private static final String SINGLE_CHECK = "org.apache.tools.ant.helper.SingleCheckExecutor";
029: private static final Vector targetNames;
030: static {
031: targetNames = new Vector();
032: targetNames.add("a");
033: targetNames.add("b");
034: }
035:
036: private int targetCount;
037:
038: /* BuildListener stuff */
039: public void targetStarted(BuildEvent event) {
040: targetCount++;
041: }
042:
043: public void buildStarted(BuildEvent event) {
044: }
045:
046: public void buildFinished(BuildEvent event) {
047: }
048:
049: public void targetFinished(BuildEvent event) {
050: }
051:
052: public void taskStarted(BuildEvent event) {
053: }
054:
055: public void taskFinished(BuildEvent event) {
056: }
057:
058: public void messageLogged(BuildEvent event) {
059: }
060:
061: public ExecutorTest(String name) {
062: super (name);
063: }
064:
065: public void setUp() {
066: configureProject("src/etc/testcases/core/executor.xml");
067: targetCount = 0;
068: getProject().addBuildListener(this );
069: }
070:
071: private Project getProject(String e) {
072: return getProject(e, false);
073: }
074:
075: private Project getProject(String e, boolean f) {
076: return getProject(e, f, false);
077: }
078:
079: private Project getProject(String e, boolean f, boolean k) {
080: Project p = getProject();
081: p.setNewProperty("ant.executor.class", e);
082: p.setKeepGoingMode(k);
083: if (f) {
084: p.setNewProperty("failfoo", "foo");
085: }
086: return p;
087: }
088:
089: public void testDefaultExecutor() {
090: getProject().executeTargets(targetNames);
091: assertEquals(targetCount, 4);
092: }
093:
094: public void testSingleCheckExecutor() {
095: getProject(SINGLE_CHECK).executeTargets(targetNames);
096: assertEquals(targetCount, 3);
097: }
098:
099: public void testDefaultFailure() {
100: try {
101: getProject(null, true).executeTargets(targetNames);
102: fail("should fail");
103: } catch (BuildException e) {
104: assertTrue(e.getMessage().equals("failfoo"));
105: assertEquals(targetCount, 1);
106: }
107: }
108:
109: public void testSingleCheckFailure() {
110: try {
111: getProject(SINGLE_CHECK, true).executeTargets(targetNames);
112: fail("should fail");
113: } catch (BuildException e) {
114: assertTrue(e.getMessage().equals("failfoo"));
115: assertEquals(targetCount, 1);
116: }
117: }
118:
119: public void testKeepGoingDefault() {
120: try {
121: getProject(null, true, true).executeTargets(targetNames);
122: fail("should fail");
123: } catch (BuildException e) {
124: assertTrue(e.getMessage().equals("failfoo"));
125: assertEquals(targetCount, 2);
126: }
127: }
128:
129: public void testKeepGoingSingleCheck() {
130: try {
131: getProject(SINGLE_CHECK, true, true).executeTargets(
132: targetNames);
133: fail("should fail");
134: } catch (BuildException e) {
135: assertTrue(e.getMessage().equals("failfoo"));
136: assertEquals(targetCount, 1);
137: }
138: }
139:
140: }
|