1 20 package org.apache.cactus.integration.ant; 21 22 import java.net.URL ; 23 24 import org.apache.cactus.integration.ant.container.ContainerRunner; 25 import org.apache.cactus.integration.ant.container.GenericContainer; 26 import org.apache.cactus.integration.ant.util.AntLog; 27 import org.apache.cactus.integration.ant.util.DefaultAntTaskFactory; 28 import org.apache.tools.ant.BuildException; 29 import org.apache.tools.ant.Task; 30 31 57 public class RunServerTestsTask extends Task 58 { 59 60 62 65 private GenericContainer container = new GenericContainer(); 66 67 70 private GenericContainer.Hook testHook; 71 72 75 private URL testURL; 76 77 80 private long timeout = 180000; 81 82 84 87 public void execute() throws BuildException 88 { 89 if (!this.container.isStartUpSet()) 90 { 91 throw new BuildException("You must specify either a nested [start] " 92 + "element or the [starttarget] attribute"); 93 } 94 95 if (!this.container.isShutDownSet()) 96 { 97 throw new BuildException("You must specify either a nested [stop] " 98 + "element or the [stoptarget] attribute"); 99 } 100 101 if (this.testHook == null) 102 { 103 throw new BuildException("You must specify either a nested [test] " 104 + "element or the [testtarget] attribute"); 105 } 106 107 if (this.testURL == null) 109 { 110 throw new BuildException( 111 "The [testurl] attribute must be specified"); 112 } 113 114 this.container.setAntTaskFactory(new DefaultAntTaskFactory( 115 getProject(), getTaskName(), getLocation(), getOwningTarget())); 116 117 ContainerRunner runner = new ContainerRunner(this.container); 118 runner.setLog(new AntLog(this)); 119 runner.setURL(this.testURL); 120 runner.setTimeout(this.timeout); 121 runner.startUpContainer(); 122 try 123 { 124 this.testHook.execute(); 125 } 126 finally 127 { 128 runner.shutDownContainer(); 129 } 130 } 131 132 134 139 public final GenericContainer.Hook createStart() 140 { 141 if (this.container.isStartUpSet()) 142 { 143 throw new BuildException( 144 "This task supports only one nested [start] element"); 145 } 146 return this.container.createStartUp(); 147 } 148 149 154 public void setStartTarget(String theStartTarget) 155 { 156 if (this.container.isStartUpSet()) 157 { 158 throw new BuildException("Either specify the [starttarget] " 159 + "attribute or the nested [start] element, but not both"); 160 } 161 this.container.setStartUpTarget(theStartTarget); 162 } 163 164 169 public final GenericContainer.Hook createStop() 170 { 171 if (this.container.isShutDownSet()) 172 { 173 throw new BuildException( 174 "This task supports only one nested [stop] element"); 175 } 176 return this.container.createShutDown(); 177 } 178 179 184 public void setStopTarget(String theStopTarget) 185 { 186 if (this.container.isShutDownSet()) 187 { 188 throw new BuildException("Either specify the [stoptarget] " 189 + "attribute or the nested [stop] element, but not both"); 190 } 191 this.container.setShutDownTarget(theStopTarget); 192 } 193 194 199 public final GenericContainer.Hook createTest() 200 { 201 if (this.testHook != null) 202 { 203 throw new BuildException( 204 "This task supports only one nested [test] element"); 205 } 206 this.testHook = container.new Hook(); 207 return this.testHook; 208 } 209 210 215 public void setTestTarget(String theTestTarget) 216 { 217 if (this.testHook != null) 218 { 219 throw new BuildException("Either specify the [testtarget] " 220 + "attribute or the nested [test] element, but not both"); 221 } 222 this.testHook = container.new Hook(); 223 this.testHook.setTarget(theTestTarget); 224 } 225 226 231 public void setTestURL(URL theTestURL) 232 { 233 this.testURL = theTestURL; 234 } 235 236 240 public void setTimeout(long theTimeout) 241 { 242 this.timeout = theTimeout; 243 } 244 245 } 246 | Popular Tags |