9.3.  Example Report

9.3.1. Creating the Groovy Script
9.3.2. Creating the Report Template
9.3.3. Creating a Chart
9.3.3.1. Pie Chart Groovy Script
9.3.3.2. Pie Chart Template Script
9.3.4. Including Images

This section provides an example Report, which shows how to retrieve test case results and how to display them depending on their status.

9.3.1. Creating the Groovy Script

The following code snippet shows the frame for a Groovy script with the required imports. The code to retrieve the data must be implemented in the execute method. A more detailed description of the Klaros-Testmanagement 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 in the data retrieval process is to actually get the required data. The following code snippet shows how to build a query string and how to get 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 that must be stored in the context so that it can later be accessed from the report template. The code snippet below shows how to store the list in the context. For more information on building queries please consult the HQL documentation.

  context.add("results", tcr);
    

The List object is stored in the context with the name "results" and can be accessed from the report template by this name. If more data is required, execute more queries to retrieve the data or process the already retrieved data and store the processed data in the context with a different name.

[Note]Note

It is possible to store more than one object in the context. Just use a different name for each object.