01: package org.jzonic.webtester.tasks;
02:
03: import java.io.File;
04:
05: import org.apache.tools.ant.BuildException;
06: import org.apache.tools.ant.Task;
07: import org.jzonic.webtester.WebTestFileReader;
08: import org.jzonic.webtester.WebTestResult;
09: import org.jzonic.webtester.WebTestSuiteResult;
10: import org.jzonic.webtester.writer.WebTestResultConsoleWriter;
11: import org.jzonic.webtester.writer.WebTestResultFileWriter;
12: import org.jzonic.webtester.writer.WebTestResultWriter;
13:
14: /**
15: * @author Mecky
16: */
17: public class WebTesterTask extends Task {
18:
19: private String testFileName;
20: private String outputFile;
21: private String dirName;
22:
23: // The method executing the task
24: public void execute() throws BuildException {
25: WebTestFileReader reader = new WebTestFileReader();
26: if (testFileName == null && dirName == null) {
27: throw new BuildException(
28: "You must either define a test file or a directory");
29: }
30: if (testFileName != null) {
31: WebTestResult result = reader.parseFile(testFileName);
32: if (outputFile == null) {
33: WebTestResultConsoleWriter writer = new WebTestResultConsoleWriter();
34: writer.generateResult(result);
35: } else {
36: WebTestResultFileWriter writer = new WebTestResultFileWriter(
37: outputFile);
38: writer.generateResult(result);
39: }
40: }
41: if (dirName != null) {
42: File theDir = new File(dirName);
43: if (theDir.isDirectory()) {
44: String[] files = theDir.list();
45: WebTestSuiteResult results = reader.runSuite(theDir,
46: files);
47: WebTestResultWriter writer = null;
48: if (outputFile == null) {
49: writer = new WebTestResultConsoleWriter();
50: } else {
51: writer = new WebTestResultFileWriter(outputFile);
52: }
53: writer.generateResult(results);
54: }
55: }
56: }
57:
58: public void setFile(String fileName) {
59: testFileName = fileName;
60: }
61:
62: public void setOutputFile(String outputFile) {
63: this .outputFile = outputFile;
64: }
65:
66: public void setDir(String dirName) {
67: this.dirName = dirName;
68: }
69: }
|