01: package org.jzonic.webtester.writer;
02:
03: import java.io.FileWriter;
04: import java.io.IOException;
05: import java.util.List;
06:
07: import org.jzonic.webtester.WebTestResult;
08: import org.jzonic.webtester.WebTestSuiteResult;
09:
10: /**
11: * This class will write the result of a testcase or a testsuite
12: * to a file.
13: *
14: * @author Mecky
15: */
16: public class WebTestResultFileWriter extends
17: AbstractWebTestResultWriter {
18:
19: private String fileName;
20:
21: public WebTestResultFileWriter(String fileName) {
22: this .fileName = fileName;
23: }
24:
25: public void generateResult(WebTestResult result) {
26: generateResult(result, false);
27: }
28:
29: private void generateResult(WebTestResult result, boolean append) {
30: writeToFile(generateTestResult(result), append);
31: }
32:
33: /**
34: * @param append
35: * @param buffer
36: */
37: private void writeToFile(String text, boolean append) {
38: FileWriter writer;
39: try {
40: writer = new FileWriter(fileName, append);
41: writer.write(text);
42: writer.close();
43: } catch (IOException e) {
44: e.printStackTrace();
45: }
46: }
47:
48: /* (non-Javadoc)
49: * @see org.jzonic.webtester.WebTestResultWriter#generateResult(java.util.List)
50: */
51: public void generateResult(WebTestSuiteResult suiteResult) {
52: String header = generateSuiteHeader(suiteResult);
53: writeToFile(header, false);
54: List results = suiteResult.getTestResults();
55: for (int i = 0; i < results.size(); i++) {
56: WebTestResult result = (WebTestResult) results.get(i);
57: generateResult(result, true);
58: }
59:
60: }
61: }
|