1 18 package org.apache.batik.test; 19 20 import java.io.OutputStreamWriter ; 21 import java.io.PrintWriter ; 22 import java.io.StringWriter ; 23 24 31 public class SimpleTestReportProcessor implements TestReportProcessor { 32 35 public static final String MESSAGES_TEST_SUITE_STATUS_TEST_PASSED 36 = "SimpleTestReportProcessor.messages.test.suite.status.testPassed"; 37 38 public static final String MESSAGES_TEST_SUITE_STATUS_TEST_FAILED 39 = "SimpleTestReportProcessor.messages.test.suite.status.testFailed"; 40 41 public static final String MESSAGES_TEST_SUITE_STATUS 42 = "SimpleTestReportProcessor.messages.test.suite.status"; 43 44 public static final String MESSAGES_TEST_SUITE_ERROR_CODE 45 = "SimpleTestReportProcessor.messages.test.suite.error.code"; 46 47 50 private PrintWriter printWriter; 51 52 55 public void setPrintWriter(PrintWriter printWriter){ 56 this.printWriter = printWriter; 57 } 58 59 63 public void processReport(TestReport report) 64 throws TestException{ 65 try{ 66 PrintWriter out = printWriter; 67 if(printWriter == null){ 68 out = new PrintWriter (new OutputStreamWriter (System.out)); 69 } 70 processReport(report, "", out); 71 out.flush(); 72 }catch(Exception e){ 73 StringWriter sw = new StringWriter (); 74 PrintWriter pw = new PrintWriter (sw); 75 e.printStackTrace(pw); 76 throw new TestException(INTERNAL_ERROR, 77 new Object [] { e.getClass().getName(), 78 e.getMessage(), 79 sw.toString() }, 80 e); 81 } 82 } 83 84 88 public void processReport(TestReport report, String prefix, PrintWriter out){ 89 String status = report.hasPassed() 90 ? Messages.formatMessage(MESSAGES_TEST_SUITE_STATUS_TEST_PASSED, null) 91 : Messages.formatMessage(MESSAGES_TEST_SUITE_STATUS_TEST_FAILED, null); 92 93 out.println(Messages.formatMessage(MESSAGES_TEST_SUITE_STATUS, 94 new Object []{ report.getTest().getName(), 95 status })); 96 97 if(!report.hasPassed()){ 98 out.println(Messages.formatMessage(MESSAGES_TEST_SUITE_ERROR_CODE, 99 new Object []{report.getErrorCode()})); 100 } 101 102 TestReport.Entry[] entries = report.getDescription(); 103 int n = entries != null ? entries.length : 0; 104 for(int i=0; i<n; i++){ 105 out.print(prefix + entries[i].getKey() + " : " ); 106 printValue(entries[i].getValue(), prefix + " ", out); 107 } 108 } 109 110 114 protected void printValue(Object value, String prefix, PrintWriter out){ 115 if(!(value instanceof TestReport)){ 116 out.println(value); 117 } 118 else{ 119 out.println(); 120 processReport((TestReport)value, prefix, out); 121 } 122 } 123 } 124 125 126 | Popular Tags |