package at.gv.egiz.param_tests.serialization.html; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.egiz.param_tests.serialization.TestSummaryWriter; import at.gv.egiz.param_tests.testinfo.TestInfo; import at.gv.egiz.param_tests.testinfo.TestVerdict; /** * Concrete implementation of the TestSummaryWriter, which creates * HTML output and uses the Twitter-bootstrap framework. * * @author mtappler * */ public class HTMLTestSummaryWriter implements TestSummaryWriter { /** * the location of the test directory */ private String testDir; /** * the print writer which is used for writing */ private PrintWriter pw; /** * the logger for this class */ private static final Logger logger = LoggerFactory .getLogger(HTMLTestSummaryWriter.class); /** * Constructor which sets the test directory. * * @param testDir * location of the test directory */ public HTMLTestSummaryWriter(String testDir) { this.testDir = testDir; } public void writeHeader() { if (pw == null) return; pw.println(""); pw.println(""); pw.println(""); pw.println("Summary of test results"); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println("
"); pw.println("
"); pw.println("

Test result summary

"); pw.println("
"); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); } public void writeSummaryOfTest(TestInfo tInfo, String testType) { if (pw == null) return; pw.println(""); pw.println(String.format( "", tInfo .getBaseTestData().getTestDirectory(), tInfo .getBaseTestData().getTestName())); pw.println(String.format("", tInfo.getBaseTestData() .getTestDirectory())); pw.println(String.format("", testType)); pw.println(String.format("", verdictToLabel(tInfo.getVerdict()))); pw.println(""); } // intentionally package protected /** * Static method for creating bootstrap label for a test verdict. Since it * is technology dependent (HTML + bootstrap) it is defined as package * protected. * * @param verdict * the verdict of a test * @return HTML-string for a verdict label */ static String verdictToLabel(TestVerdict verdict) { switch (verdict) { case FAILED: return "Fail"; case INCONCLUSIVE: return "Inconclusive"; case SUCCEEDED: return "Success"; default: return "Unknown"; } } public void writeFooter() { if (pw == null) return; pw.println("
Test nameTest directoryTest typeVerdict
%s%s%s%s
"); pw.println(""); pw.println(""); pw.println("
"); pw.println(""); pw.println(""); } public void init() { OutputStream os; try { os = new FileOutputStream(testDir + "/index.html"); pw = new PrintWriter(new OutputStreamWriter(os, "UTF8")); } catch (FileNotFoundException e) { logger.debug("Could not find output file, not writing any summary", e); } catch (UnsupportedEncodingException e) { logger.debug("Used unsupported encoding for writing summary file.", e); } } public void close() { if (pw != null) pw.close(); } }