To provide a graphical overview it is sometimes necessary to add a chart to the Report. The required data can be prepared by the Groovy script and stored in the context. Then the report template can pass the data to the charting component of SeamPDF. This section explains how to create a chart as shown in Figure 9.8, “A Pie Chart Example”
As mentioned before, the Groovy script is not only used to retrieve
the data, but it can also be used to prepare the data for the Report.
The following listing shows a possible way to prepare the data for a pie chart.
For every possible result a List object is created, then the
de.verit.klaros.core.model.KlarosTestCaseResult retrieved
before are stored in one of the lists depending on the test result. Next the lists
are added to the context.
List<KlarosTestCaseResult> error = new ArrayList<KlarosTestCaseResult>();
List<KlarosTestCaseResult> failure = new ArrayList<KlarosTestCaseResult>();
List<KlarosTestCaseResult> success = new ArrayList<KlarosTestCaseResult>();
// Iterate over the results and retrieve the status
Iterator<KlarosTestCaseResult> iter = (Iterator<KlarosTestCaseResult>) tcr.iterator();
while (iter.hasNext()) {
KlarosTestCaseResult result = iter.next();
if (result.isError()) error.add(result);
else if (result.isFailure()) failure.add(result);
else if (result.isPassed()) success.add(result);
}
context.add("error", error);
context.add("failure", failure);
context.add("success", success);
The de.verit.klaros.core.model.KlarosTestCaseResult are split into three lists depending on the test case result. These lists can then be accessed from the context by their corresponding key.