Appendix E. Reporting Resources

Table of Contents

E.1. Context Variables
E.2. KlarosScript Interface
E.3. Example

E.1. Context Variables

Name Description
date The current date.
locale The current locale set in the web frontend.
activeProject The currently selected KlarosConfiguration. If no project is selected this variable contains the null object.
user A KlarosUser object representing the active user.
parameters A Map of parameter objects representing the entered parameters when running the report. The map key consists of the parameter name attribute the value is of type de.verit.klaros.scripting.model.Parameter.

Table E.1. Context Variables


The context variables can be accessed via SeamPDF by e.g.:

<p:text value="#{date}" />
[Note] Note

#{user.name} and #{user.username} contain different values. The first provides the user's real name, while the latter provides the name the user is logged in with.

E.2. KlarosScript Interface

package de.verit.klaros.scripting;
/**
 * Public interface that all seam-pdf template scripts must implement be work
 * properly.
 */
public interface KlarosScript {
    /**
     * This functions gets called by the seam-pdf servlet to execute the script.
     *
     * @param context
     *            The event context to provide all needed functions, properties
     *            and objects.
     */
    void execute(KlarosContext context);
}

E.3. Example

<p:document xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://jboss.org/schema/seam/pdf"
  title="Klaros-Testmanagement Test Suite Report" marginMirroring="true"
  author="#{user.name}" creator="#{user.name}" pageSize="A4">
  <f:facet name="header">
    <p:font size="8">
      <p:header borderWidthBottom="0.1" borderColorBottom="black" borderWidthTop="0" alignment="center">
        <p:text value="Example report - generated #{date} by #{user.name}"/>
      </p:header>
      <p:footer borderWidthTop="0.1" borderColorTop="black" borderWidthBottom="0" alignment="center">
        <p:text value="Page " />
        <p:pageNumber />
      </p:footer>
    </p:font>
  </f:facet>
  <!-- print the frontpage -->
  <p:paragraph alignment="center" spacingAfter="100">
    <p:text value="" />
  </p:paragraph>
  <p:font style="bold" size="32">
    <p:paragraph alignment="center" spacingAfter="75">
      <p:text value="Test Case Report" />
    </p:paragraph>
  </p:font>
  <p:font style="normal" size="12">
    <p:paragraph alignment="center" spacingAfter="5">
      <p:text value="Created by" />
    </p:paragraph>
  </p:font>
  <p:font style="bold" size="16">
    <p:paragraph alignment="center" spacingAfter="5">
      <p:text value="#{user.name} (#{user.email})"/>
    </p:paragraph>
  </p:font>
  <p:font style="normal" size="12">
    <p:paragraph alignment="center" spacingAfter="5">
      <p:text value="at" />
    </p:paragraph>
  </p:font>
  <p:font style="bold" size="16">
    <p:paragraph alignment="center" spacingAfter="75">
      <p:text value="#{date}" />
    </p:paragraph>
  </p:font>
  <p:newPage/>
  <ui:fragment rendered="#{results != null}">
    <p:font style="normal" size="12">
      <p:paragraph alignment="left" spacingAfter="10">
        <p:text value="The testresults for " />
      </p:paragraph>
    </p:font>
  </ui:fragment>
  <!-- Testresult table -->
  <p:table columns="4" widths="1 1 3 3">
    <!-- create the headline with bold characters -->
    <p:font size="10" style="bold">
      <p:cell horizontalAlignment="center" verticalAlignment="top">
        <p:paragraph>
          <p:text value="Name" />
        </p:paragraph>
      </p:cell>
      <p:cell horizontalAlignment="center" verticalAlignment="top">
        <p:paragraph>
          <p:text value="Result" />
        </p:paragraph>
      </p:cell>
      <p:cell horizontalAlignment="center" verticalAlignment="top">
        <p:paragraph>
          <p:text value="Testrun description" />
        </p:paragraph>
      </p:cell>
      <p:cell horizontalAlignment="center" verticalAlignment="top">
        <p:paragraph>
          <p:text value="Summary" />
        </p:paragraph>
      </p:cell>
    </p:font>
    <!-- display the attributes of the test results -->
    <p:font size="8">
      <ui:repeat value="#{results}" var="tcr">
        <p:cell verticalAlignment="top" horizontalAlignment="left">
          <p:paragraph>
            <p:text value="#{tcr.testCase.name}" />
          </p:paragraph>
        </p:cell>
        <!-- decide which color has to be displayed, based on the testresult -->
        <ui:fragment rendered="#{tcr.error}">
          <p:cell backgroundColor="rgb(255,0,0)" verticalAlignment="top" horizontalAlignment="center">
            <p:paragraph>
              <p:text value="error" />
            </p:paragraph>
          </p:cell>
        </ui:fragment>
        <ui:fragment rendered="#{tcr.failure}">
          <p:cell backgroundColor="rgb(255,215,0)" verticalAlignment="top" horizontalAlignment="center">
            <p:paragraph>
              <p:text value="failure" />
            </p:paragraph>
          </p:cell>
        </ui:fragment>
        <ui:fragment rendered="#{tcr.passed}">
          <p:cell backgroundColor="rgb(0,255,0)" verticalAlignment="top" horizontalAlignment="center">
            <p:paragraph>
              <p:text value="passed" />
            </p:paragraph>
          </p:cell>
        </ui:fragment>
        <p:cell verticalAlignment="top" horizontalAlignment="left">
          <p:paragraph>
            <p:text value="#{tcr.description}" />
          </p:paragraph>
        </p:cell>
        <p:cell verticalAlignment="top" horizontalAlignment="left">
          <p:paragraph>
            <p:text value="#{tcr.summary}" />
          </p:paragraph>
        </p:cell>
        <!-- Print the testcase description below the result row.
             To differ from the next row use a bigger border for the bottom. -->
        <p:cell colspan="4" verticalAlignment="top" horizontalAlignment="left"
                borderWidthBottom="1" paddingBottom="3">
          <p:paragraph>
            <p:font size="6" style="bold">
              <p:text value="Testcase description:" />
            </p:font>
            <p:font size="6">
              <p:text value="#{tcr.testCase.description}" />
            </p:font>
          </p:paragraph>
        </p:cell>
      </ui:repeat>
    </p:font>
  </p:table>
</p:document>