11.4. Example Report

11.4.1. Creating the Report Script
11.4.2. Creating a PDF Report Template

This section provides an example report, which retrieves test case results and displays them depending on their status.

11.4.1. Creating the Report Script

The following code snippet shows the basic structure of a report script with all required imports. The code to retrieve the data will be implemented in the execute method. A more detailed description of the Klaros-Test­management API can be found in de.verit.klaros.core.model.

  import de.verit.klaros.scripting.*;
  import de.verit.klaros.core.model.*;
  import java.util.*;

  public class TestScript implements KlarosScript {

    public void execute(KlarosContext context) {...
    }
  }

The next step is to retrieve the required data. The following code snippet shows how to build a query string to retrieve the data.

  StringBuffer query = new StringBuffer();
  query.append("select tcr from KlarosTestCaseResult tcr");
  List<?> tcr = context.executeQuery(query.toString());

The data is returned in a List object. This list must be stored in the context so that it can be accessed from the layout template:

  context.add("results", tcr);
[Note] Note

For more information on building queries please consult the HQL documentation.

The List object is stored in the context with the name results and can be accessed from the layout template by this name. If additional data is needed, execute the appropriate queries and store the processed data in the context using a different name.

11.4.2. Creating a PDF Report Template

The code snippets in this section show how to build a PDF layout template. For the official documentation on the layout language used, please refer to SeamPDF manual. More information regarding the object model can be found in de.verit.klaros.core.model.

The following code snippet shows the basic structure of a PDF layout template. Inside the <p:document> element, the content of the report is contained and grouped in chapters and sections.

  <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">
     ...
  </p:document>

Here the de.verit.klaros.core.model.KlarosUser parameter which is always present in the context is used via #{user.name} to specify the author of the PDF document.

The next code snippet shows how to define the report headers and footers. Here the current date and the de.verit.klaros.core.model.KlarosUser parameter in the context is used.

  <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 on #{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>

Next, the front page for the report is defined, showing a short summary of the report. To keep this example short, only a fragment with the user's name and email address is shown. For the complete script see Section E.3, “Example Layout Template”.

  <p:font style="bold" size="16">
    <p:paragraph alignment="center" spacingAfter="5">
      <p:text value="#{user.name} (#{user.email})"/>
    </p:paragraph>
  </p:font>