1 39 40 package com.sun.japex; 41 42 import java.io.*; 43 import java.text.*; 44 import java.util.Date ; 45 import java.net.URL ; 46 import javax.xml.transform.*; 47 import javax.xml.transform.stream.*; 48 49 public class Japex { 50 51 public static boolean HTML_OUTPUT = true; 52 public static Date TODAY = new Date (); 53 54 55 public Japex() { 56 } 57 58 61 public static void main(String [] args) { 62 if (args.length < 1 || args.length > 4) { 63 displayUsageAndExit(); 64 } 65 66 String configFile = null; 68 for (int i = 0; i < args.length; i++) { 69 if (args[i].equals("-nohtml")) { 70 HTML_OUTPUT = false; 71 } 72 else if (args[i].equals("-cp") || args[i].equals("-classpath")) { 73 i++; } 75 else { 76 configFile = args[i]; 77 } 78 } 79 80 if (configFile == null) { 81 displayUsageAndExit(); 82 } 83 84 new Japex().run(configFile); 85 } 86 87 private static void displayUsageAndExit() { 88 System.err.println("Usage: japex [-cp <classpath>] [-nohtml] config.xml"); 89 System.exit(1); 90 } 91 92 public void run(String configFile) { 93 try { 94 System.out.println("Running ..."); 95 96 TestSuite testSuite = new Engine().start(configFile); 98 99 String fileSep = System.getProperty("file.separator"); 101 DateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH_mm"); 102 String outputDir = testSuite.getParam(Constants.REPORTS_DIRECTORY) 103 + fileSep + df.format(TODAY); 104 new File(outputDir).mkdirs(); 105 106 StringBuffer report = new StringBuffer (); 108 testSuite.serialize(report); 109 110 System.out.println("Generating reports ..."); 112 System.out.println(" " + 113 new File(outputDir + "/" + "report.xml").toURL()); 114 OutputStreamWriter osr = new OutputStreamWriter( 115 new FileOutputStream( 116 new File(outputDir + fileSep + "report.xml"))); 117 osr.write(report.toString()); 118 osr.close(); 119 120 if (!HTML_OUTPUT) return; 122 123 final String resultChart = "result.jpg"; 125 testSuite.generateDriverChart(outputDir + fileSep 126 + resultChart); 127 final String testCaseChartBase = "testcase"; 128 int nOfCharts = testSuite.generateTestCaseCharts(outputDir 129 + fileSep + testCaseChartBase, ".jpg"); 130 131 StringBuffer extendedReport = new StringBuffer (); 133 extendedReport.append("<extendedTestSuiteReport " + 134 "xmlns=\"http://www.sun.com/japex/extendedTestSuiteReport\">\n") 135 .append(" <resultChart>" + resultChart + "</resultChart>\n"); 136 for (int i = 0; i < nOfCharts; i++) { 137 extendedReport.append(" <testCaseChart>" + 138 testCaseChartBase + i + ".jpg" + "</testCaseChart>\n"); 139 } 140 extendedReport.append(report); 141 extendedReport.append("</extendedTestSuiteReport>\n"); 142 143 TransformerFactory tf = TransformerFactory.newInstance(); 145 URL stylesheet = getClass().getResource("/resources/report.xsl"); 146 if (stylesheet != null) { 147 Transformer transformer = tf.newTransformer( 148 new StreamSource(stylesheet.toExternalForm())); 149 150 System.out.println(" " + 151 new File(outputDir + "/" + "report.html").toURL()); 152 transformer.transform( 153 new StreamSource(new StringReader(extendedReport.toString())), 154 new StreamResult(new FileOutputStream( 155 new File(outputDir + fileSep + "report.html")))); 156 157 URL css = getClass().getResource("/resources/report.css"); 159 if (css != null) { 160 InputStream is = css.openStream(); 161 FileOutputStream fos = new FileOutputStream( 162 new File(outputDir + fileSep + "report.css")); 163 164 int c; 165 while ((c = is.read()) != -1) { 166 fos.write(c); 167 } 168 is.close(); 169 fos.close(); 170 } 171 } 172 } 173 catch (RuntimeException e) { 174 throw e; 175 } 176 catch (Exception e) { 177 throw new RuntimeException (e); 178 } 179 } 180 181 } 182 | Popular Tags |