From ffd1e0da6b73e2737f5cad0a6d3e82dbc3de206f Mon Sep 17 00:00:00 2001
From: Andreas Fitzek Detailed test results " + baseData.getTestName()
+ + "
");
+ pw.println("");
+ basicTestDataPanel
+ .append("
");
+ basicTestDataPanel
+ .append(""
+ + baseTestInfo.getStdOut() + "
");
+ basicTestDataPanel.append(""
+ + baseTestInfo.getStdErr() + "
");
+ basicTestDataPanel.append("");
+ sb.append(createDescription("Input file", baseData.getPdfFile()));
+ sb.append(createDescription("Output file", baseData.getOutputFile()));
+ sb.append(createDescription("Signature profile", baseData.getProfilID()));
+ sb.append(createDescription("Connector Type", baseData
+ .getConnectorData().getConnectorType()));
+ if (baseData.getConnectorData().getConnectorParameters().size() > 0) {
+ StringBuilder connectorParameters = new StringBuilder();
+ connectorParameters.append("
");
+ return sb.toString();
+ }
+
+ /**
+ * Helper for writing a bootstrap panel with some title and content.
+ *
+ * @param pw
+ * ");
+ for (Entry
");
+ sb.append(createDescription("Connector Parameters",
+ connectorParameters.toString()));
+ }
+ sb.append(createDescription("Test Type", getTestType()));
+ sb.append("PrintWriter
-object to which the panel should be
+ * written
+ * @param panelTitle
+ * title of the panel
+ * @param panelBody
+ * panel content
+ */
+ protected void writePanel(PrintWriter pw, String panelTitle,
+ String panelBody) {
+ pw.println("" + panelTitle + "
");
+ pw.println(""
+ + HTMLTestSummaryWriter.verdictToLabel(baseTestInfo
+ .getVerdict()) + "
");
+ if (baseTestInfo.getVerdict().equals(TestVerdict.FAILED)
+ || baseTestInfo.getVerdict().equals(TestVerdict.INCONCLUSIVE)) {
+ panelBody.append(createExceptionDataString(baseTestInfo
+ .getFailCause()));
+ }
+ writePanel(pw, "Test result", panelBody.toString());
+
+ }
+
+ /**
+ * This method creates a HTML-representation for data contained in a
+ * throwable.
+ *
+ * @param t
+ * Throwable
-object which should be displayed
+ * @return HTML-string for the throwable
+ */
+ protected String createExceptionDataString(Throwable t) {
+ StringBuilder exceptionData = new StringBuilder();
+ exceptionData.append("");
+ exceptionData.append(createDescription("Cause", t.toString()));
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ t.printStackTrace(pw);
+ exceptionData.append(createDescription("Stacktrace", sw.toString()));
+ exceptionData.append("
");
+ return exceptionData.toString();
+ }
+
+ /**
+ * Helper method for creating an item of a definition list.
+ *
+ * @param term
+ * the term of the item (the key)
+ * @param definition
+ * the definition of the item (the value)
+ * @return an HTML-string for the definition list item
+ */
+ protected String createDescription(String term, String definition) {
+ return String.format("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("Test result summary
");
+ 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("Test name ");
+ pw.println("Test directory ");
+ pw.println("Test type ");
+ pw.println("Verdict ");
+ pw.println("");
+ pw.println(String.format(
+ " ");
+ }
+
+ // 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("%s ", tInfo
+ .getBaseTestData().getTestDirectory(), tInfo
+ .getBaseTestData().getTestName()));
+ pw.println(String.format("%s ", tInfo.getBaseTestData()
+ .getTestDirectory()));
+ pw.println(String.format("%s ", testType));
+ pw.println(String.format("%s ",
+ verdictToLabel(tInfo.getVerdict())));
+ pw.println("TestInfoSerializer.baseTestInfo
+ */
+ private PDFATestInfo testInfo;
+
+ /**
+ * Default contructor used for registering it as prototype.
+ */
+ public PDFAHTMLSerizalier() {
+ this(null);
+ }
+
+ /**
+ * Package protected constructor used for cloning
+ *
+ * @param testInfo
+ */
+ PDFAHTMLSerizalier(PDFATestInfo testInfo) {
+ this.testInfo = testInfo;
+ }
+
+ @Override
+ public PDFATestInfo createTestInfo() {
+ testInfo = new PDFATestInfo();
+ baseTestInfo = testInfo;
+ return testInfo;
+ }
+
+ @Override
+ public TestInfoSerializerValidation status before signing
");
+ writeValidationResult(pw, testInfo.getResultBeforeSign());
+ if (testInfo.getResultAfterSign() != null) {
+ pw.println("Validation status after signing
");
+ writeValidationResult(pw, testInfo.getResultAfterSign());
+ }
+ }
+
+ /**
+ * This method writes the validation result to the given print writer, i.e.
+ * an information about the success of the validation or an exception which
+ * was thrown during the validation or a list of validation errors.
+ *
+ * @param pw
+ * the PrintWriter
-object to which the HTML-code is
+ * written
+ * @param validationResult
+ * the pair which defines the result of a validation
+ */
+ private void writeValidationResult(PrintWriter pw,
+ Pair
The document conforms to the PDF-A standard.
"); + } else { + ListWith to the PDF-A standard, " + + "the document contains the following errors:
"); + conformanceString + .append("Error code | "); + conformanceString.append("Error details | "); + conformanceString.append("Warning | "); + conformanceString.append("
---|
TestInfoSerializer.baseTestInfo
+ */
+ private SignaturePositionTestInfo testInfo;
+
+ /**
+ * Default contructor used for registering it as prototype.
+ */
+ public SignaturePositionHTMLSerializer() {
+ this(null);
+ }
+
+ /**
+ * Package protected constructor used for cloning
+ *
+ * @param testInfo
+ */
+ SignaturePositionHTMLSerializer(SignaturePositionTestInfo testInfo) {
+ this.testInfo = testInfo;
+ }
+
+ @Override
+ public SignaturePositionTestInfo createTestInfo() {
+ testInfo = new SignaturePositionTestInfo();
+ baseTestInfo = testInfo;
+ return testInfo;
+ }
+
+ @Override
+ public TestInfoSerializerThis image was not captured correctly. " + + "The test may have been aborted before because of an IO error.
"; + return imageString; + } + + @Override + public String getTestType() { + return "Signature Position"; + } + + @Override + protected void writeTestSpecificParameters(PrintWriter pw) { + + SignaturePositionParameters additionalParameters = testInfo + .getAdditionParameters(); + StringBuilder panelBody = new StringBuilder(); + + panelBody.append("