1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package dev.aherscu.qa.jgiven.reporter;
18
19 import static dev.aherscu.qa.testing.utils.FileUtilsExtensions.*;
20
21 import java.io.*;
22
23 import org.apache.commons.io.*;
24 import org.testng.xml.*;
25
26 import com.google.gson.*;
27 import com.tngtech.jgiven.report.json.*;
28 import com.tngtech.jgiven.report.model.*;
29
30 import lombok.*;
31 import lombok.experimental.*;
32
33
34
35
36 @SuperBuilder(toBuilder = true)
37 @NoArgsConstructor(force = true)
38 @ToString(callSuper = true)
39 public class QaJGivenReporter
40 extends AbstractQaJgivenReporter<CompleteReportModel, QaJGivenReporter> {
41 public static final String DEFAULT_TEMPLATE_RESOURCE =
42 "/qa-jgiven-reporter.html";
43
44 public final String productName;
45 public final String productVersion;
46 public final String testDocumentId;
47 public final String testDocumentRev;
48 public final String specDocumentId;
49 public final String specDocumentRev;
50 public final String planDocumentId;
51 public final String planDocumentRev;
52 public final String traceabilityDocumentId;
53 public final String traceabilityDocumentRev;
54
55
56
57
58
59
60
61
62
63 @Override
64 protected QaJGivenReporter with(final XmlSuite xmlSuite) {
65 return ((QaJGivenReporter) super.with(xmlSuite))
66 .toBuilder()
67 .templateResource(templateResourceParamFrom(xmlSuite,
68 DEFAULT_TEMPLATE_RESOURCE))
69 .build();
70 }
71
72
73
74
75
76 @Override
77 @SneakyThrows
78 public void generate() {
79 val targetReportFile = new File(outputDirectory,
80
81
82 FilenameUtils.getName(templateResource));
83
84 val aggregatedReportModel = reportModel(targetReportFile)
85 .toBuilder()
86 .jgivenReport(
87 new ReportModelReader(
88 QaJGivenReportConfig.builder()
89 .sourceDir(sourceDirectory)
90 .targetDir(outputDirectory)
91 .build())
92 .readDirectory())
93 .screenshotScale(screenshotScale)
94 .datePattern(datePattern)
95 .testDocumentId(testDocumentId)
96 .testDocumentRev(testDocumentRev)
97 .specDocumentId(specDocumentId)
98 .specDocumentRev(specDocumentRev)
99 .planDocumentId(planDocumentId)
100 .planDocumentRev(planDocumentRev)
101 .traceabilityDocumentId(traceabilityDocumentId)
102 .traceabilityDocumentRev(traceabilityDocumentRev)
103 .productName(productName)
104 .productVersion(productVersion)
105 .build();
106
107 if (debug) {
108 try (val debugReportWriter = fileWriter(
109 new File(outputDirectory, "debug-report.json"))) {
110 new GsonBuilder()
111 .setPrettyPrinting()
112 .create()
113 .toJson(aggregatedReportModel, debugReportWriter);
114 }
115 }
116
117 try (val reportWriter = fileWriter(targetReportFile)) {
118 template()
119 .execute(aggregatedReportModel, reportWriter);
120 }
121
122
123
124
125
126
127
128
129 }
130
131 }