Appendix E. The Reporting Context API

Table of Contents

E.1. The Klaros Report Context
E.2. KlarosScript Interface
E.3. Example Layout Template

E.1. The Klaros Report Context

Name Description Typ
date The time of report execution. java.util.Date
locale The localization selected by the user. java.util.Locale
activeProject The currently selected project or null if no project is selected. de.verit.klaros.model.KlarosConfiguration
activeIteration The currently selected iteration or null if no iteration is selected. de.verit.klaros.model.KlarosIteration
user The current user who creates the report. de.verit.klaros.model.KlarosUser
parameters A map of parameter names to parameter objects containing the user defined parameters entered when running the report. java.util.Map java.lang.String, 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} und #{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 for generating user defined reports.
 */
public interface KlarosScript {

    /**
     * This method starts the report generation.
     *
     * @param context
     *            The event context to provide all needed functions, properties
     *            and objects.
     * @throws KlarosScriptingException if executing the script fails
     */
    void execute(KlarosContext context) throws KlarosScriptingException;
}

E.3. Example Layout Template

<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 test results for " />
      </p:paragraph>
    </p:font>
  </ui:fragment>

  <!-- Test result 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="Test run 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 test result -->
        <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 test case 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>