1 18 19 package org.apache.activemq.tool; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import java.io.File ; 25 import java.io.FileOutputStream ; 26 import java.io.IOException ; 27 import java.io.PrintWriter ; 28 import java.util.Enumeration ; 29 import java.util.Properties ; 30 31 public class ReportGenerator { 32 private static final Log log = LogFactory.getLog(ReportGenerator.class); 33 private String reportDirectory = null; 34 private String reportName = null; 35 private PrintWriter writer = null; 36 private File reportFile = null; 37 private Properties testSettings; 38 39 public ReportGenerator() { 40 } 41 42 public ReportGenerator(String reportDirectory, String reportName) { 43 this.setReportDirectory(reportDirectory); 44 this.setReportName(reportName); 45 } 46 47 public void startGenerateReport() { 48 49 50 File reportDir = new File (getReportDirectory()); 51 52 if (!reportDir.exists()) { 54 reportDir.mkdirs(); 55 } 56 57 58 if (reportDir != null) { 59 reportFile = new File (this.getReportDirectory() + File.separator + this.getReportName() + ".xml"); 60 } 61 62 try { 63 this.writer = new PrintWriter (new FileOutputStream (reportFile)); 64 } catch (IOException e1) { 65 e1.printStackTrace(); } 67 } 68 69 public void stopGenerateReport() { 70 writeWithIndent(0, "</test-report>"); 71 this.getWriter().flush(); 72 this.getWriter().close(); 73 log.info(" TEST REPORT OUTPUT : " + reportFile.getAbsolutePath()); 74 75 76 } 77 78 protected void addTestInformation() { 79 80 writeWithIndent(0, "<test-report>"); 81 writeWithIndent(2, "<test-information>"); 82 83 writeWithIndent(4, "<os-name>" + System.getProperty("os.name") + "</os-name>"); 84 writeWithIndent(4, "<java-version>" + System.getProperty("java.version") + "</java-version>"); 85 86 } 87 88 89 protected void addClientSettings() { 90 if (this.getTestSettings() != null) { 91 Enumeration keys = getTestSettings().propertyNames(); 92 93 writeWithIndent(4, "<test-settings>"); 94 95 String key; 96 while (keys.hasMoreElements()) { 97 key = (String ) keys.nextElement(); 98 writeWithIndent(6, "<" + key + ">" + getTestSettings().get(key) + "</" + key + ">"); 99 } 100 101 writeWithIndent(4, "</test-settings>"); 102 } 103 } 104 105 protected void endTestInformation() { 106 writeWithIndent(2, "</test-information>"); 107 108 } 109 110 protected void startTestResult(long checkpointInterval) { 111 long intervalInSec = checkpointInterval / 1000; 112 writeWithIndent(2, "<test-result checkpoint_interval_in_sec=" + intervalInSec + " >"); 113 } 114 115 protected void endTestResult() { 116 writeWithIndent(2, "</test-result>"); 117 } 118 119 120 protected void writeWithIndent(int indent, String result) { 121 StringBuffer buffer = new StringBuffer (); 122 123 for (int i = 0; i < indent; ++i) { 124 buffer.append(" "); 125 } 126 127 buffer.append(result); 128 writer.println(buffer.toString()); 129 } 130 131 public PrintWriter getWriter() { 132 return this.writer; 133 } 134 135 136 public String getReportDirectory() { 137 return reportDirectory; 138 } 139 140 public void setReportDirectory(String reportDirectory) { 141 this.reportDirectory = reportDirectory; 142 } 143 144 public String getReportName() { 145 return reportName; 146 } 147 148 149 public void setReportName(String reportName) { 150 this.reportName = reportName; 151 } 152 153 public Properties getTestSettings() { 154 return testSettings; 155 } 156 157 public void setTestSettings(Properties testSettings) { 158 this.testSettings = testSettings; 159 } 160 } 161 | Popular Tags |