1 17 18 package org.apache.tools.ant; 19 20 import java.util.Vector ; 21 22 import org.apache.tools.ant.taskdefs.Exit; 23 24 27 public class ExecutorTest extends BuildFileTest implements BuildListener { 28 private static final String SINGLE_CHECK 29 = "org.apache.tools.ant.helper.SingleCheckExecutor"; 30 private static final Vector targetNames; 31 static { 32 targetNames = new Vector (); 33 targetNames.add("a"); 34 targetNames.add("b"); 35 } 36 37 private int targetCount; 38 39 40 public void targetStarted(BuildEvent event) { 41 targetCount++; 42 } 43 public void buildStarted(BuildEvent event) {} 44 public void buildFinished(BuildEvent event) {} 45 public void targetFinished(BuildEvent event) {} 46 public void taskStarted(BuildEvent event) {} 47 public void taskFinished(BuildEvent event) {} 48 public void messageLogged(BuildEvent event) {} 49 50 public ExecutorTest(String name) { 51 super(name); 52 } 53 54 public void setUp() { 55 configureProject("src/etc/testcases/core/executor.xml"); 56 targetCount = 0; 57 getProject().addBuildListener(this); 58 } 59 60 private Project getProject(String e) { 61 return getProject(e, false); 62 } 63 64 private Project getProject(String e, boolean f) { 65 return getProject(e, f, false); 66 } 67 68 private Project getProject(String e, boolean f, boolean k) { 69 Project p = getProject(); 70 p.setNewProperty("ant.executor.class", e); 71 p.setKeepGoingMode(k); 72 if (f) { 73 p.setNewProperty("failfoo", "foo"); 74 } 75 return p; 76 } 77 78 public void testDefaultExecutor() { 79 getProject().executeTargets(targetNames); 80 assertEquals(targetCount, 4); 81 } 82 83 public void testSingleCheckExecutor() { 84 getProject(SINGLE_CHECK).executeTargets(targetNames); 85 assertEquals(targetCount, 3); 86 } 87 88 public void testDefaultFailure() { 89 try { 90 getProject(null, true).executeTargets(targetNames); 91 fail("should fail"); 92 } catch (BuildException e) { 93 assertTrue(e.getMessage().equals("failfoo")); 94 assertEquals(targetCount, 1); 95 } 96 } 97 98 public void testSingleCheckFailure() { 99 try { 100 getProject(SINGLE_CHECK, true).executeTargets(targetNames); 101 fail("should fail"); 102 } catch (BuildException e) { 103 assertTrue(e.getMessage().equals("failfoo")); 104 assertEquals(targetCount, 1); 105 } 106 } 107 108 public void testKeepGoingDefault() { 109 try { 110 getProject(null, true, true).executeTargets(targetNames); 111 fail("should fail"); 112 } catch (BuildException e) { 113 assertTrue(e.getMessage().equals("failfoo")); 114 assertEquals(targetCount, 2); 115 } 116 } 117 118 public void testKeepGoingSingleCheck() { 119 try { 120 getProject(SINGLE_CHECK, true, true).executeTargets(targetNames); 121 fail("should fail"); 122 } catch (BuildException e) { 123 assertTrue(e.getMessage().equals("failfoo")); 124 assertEquals(targetCount, 1); 125 } 126 } 127 128 } 129 130 | Popular Tags |