Skip to content

Commit

Permalink
Merge pull request #241 from vidurananayakkara/ReportImprove
Browse files Browse the repository at this point in the history
Fix issues in report generation
  • Loading branch information
vidurananayakkara authored Dec 15, 2017
2 parents 21ab098 + 4aeb511 commit 6f59e5d
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public void generateReport(String productName, String productVersion, String cha
AxisColumn uniqueAxisColumn = getGroupByColumn(groupBy);

// Construct report elements
List<ReportElement> reportElements = Collections.unmodifiableList(constructReportElements(productTestPlan));
List<ReportElement> reportElements = Collections
.unmodifiableList(constructReportElements(productTestPlan, uniqueAxisColumn));

// Break elements by group by (sorting also handled)
List<GroupBy> groupByList = groupReportElementsBy(uniqueAxisColumn, reportElements, showSuccess);
Expand All @@ -102,7 +103,8 @@ public void generateReport(String productName, String productVersion, String cha

// Write to HTML file
String fileName = StringUtil.concatStrings(productTestPlan.getProductName(), "-",
productTestPlan.getProductVersion(), "-", productTestPlan.getChannel(), HTML_EXTENSION);
productTestPlan.getProductVersion(), "-", productTestPlan.getChannel(), "-",
productTestPlan.getStartTimestamp(), "-", uniqueAxisColumn, HTML_EXTENSION);
writeHTMLToFile(fileName, htmlString);
}

Expand All @@ -124,8 +126,8 @@ private List<PerAxisHeader> createPerAxisHeaders(AxisColumn uniqueAxisColumn, Li
Map<String, List<ReportElement>> groupedReportElements =
getGroupedReportElementsByColumn(uniqueAxisColumn, reportElements);

List<PerAxisSummary> perAxisSummaries = new ArrayList<>();
for (Map.Entry<String, List<ReportElement>> entry : groupedReportElements.entrySet()) {
List<PerAxisSummary> perAxisSummaries = new ArrayList<>();

// Capture success and fail count
Map<Boolean, List<ReportElement>> groupedByTestStatusMap = entry.getValue().stream()
Expand Down Expand Up @@ -197,20 +199,27 @@ private List<ReportElement> processOverallResultForScenarioAxis(List<ReportEleme
.filter(ReportElement::isTestSuccess)
.collect(Collectors.toList());

List<ReportElement> filteredSuccessList = successList.stream()
.filter(reportElement -> {
for (ReportElement failListReportElement : failList) {
if (reportElement.getDeployment().equals(failListReportElement.getDeployment()) &&
constructInfraString(reportElement).equals(constructInfraString(failListReportElement))) {
return false;
}
}
return true;
})
.collect(Collectors.toList());
List<ReportElement> filteredSuccessList = new ArrayList<>(failList);

for (ReportElement successListReportElement : successList) {
boolean isBreakLoop = false;
for (ReportElement failListReportElement : failList) {
if (successListReportElement.getDeployment().equals(failListReportElement.getDeployment()) &&
constructInfraString(successListReportElement)
.equals(constructInfraString(failListReportElement))) {

failList.addAll(filteredSuccessList);
return failList;
// If same combination os found, omit this next time
failList.remove(failListReportElement);
isBreakLoop = true;
break;
}
}
if (isBreakLoop) {
continue;
}
filteredSuccessList.add(successListReportElement);
}
return filteredSuccessList;
}

/**
Expand All @@ -236,16 +245,21 @@ private List<ReportElement> processOverallResultForDeploymentAxis(List<ReportEle
List<ReportElement> filteredSuccessList = new ArrayList<>(failList);

for (ReportElement successListReportElement : successList) {
boolean isBreakLoop = false;
for (ReportElement failListReportElement : failList) {
if (constructInfraString(successListReportElement)
.equals(constructInfraString(failListReportElement)) &&
successListReportElement.getScenarioName().equals(failListReportElement.getScenarioName())) {

// If same combination os found, omit this next time
failList.remove(failListReportElement);
isBreakLoop = true;
break;
}
}
if (isBreakLoop) {
continue;
}
filteredSuccessList.add(successListReportElement);
}
return filteredSuccessList;
Expand All @@ -271,20 +285,26 @@ private List<ReportElement> processOverallResultForInfrastructureAxis(List<Repor
.filter(ReportElement::isTestSuccess)
.collect(Collectors.toList());

List<ReportElement> filteredSuccessList = successList.stream()
.filter(reportElement -> {
for (ReportElement failListReportElement : failList) {
if (reportElement.getDeployment().equals(failListReportElement.getDeployment()) &&
reportElement.getScenarioName().equals(failListReportElement.getScenarioName())) {
return false;
}
}
return true;
})
.collect(Collectors.toList());
List<ReportElement> filteredSuccessList = new ArrayList<>(failList);

for (ReportElement successListReportElement : successList) {
boolean isBreakLoop = false;
for (ReportElement failListReportElement : failList) {
if (successListReportElement.getDeployment().equals(failListReportElement.getDeployment()) &&
successListReportElement.getScenarioName().equals(failListReportElement.getScenarioName())) {

failList.addAll(filteredSuccessList);
return failList;
// If same combination os found, omit this next time
failList.remove(failListReportElement);
isBreakLoop = true;
break;
}
}
if (isBreakLoop) {
continue;
}
filteredSuccessList.add(successListReportElement);
}
return filteredSuccessList;
}

/**
Expand Down Expand Up @@ -541,10 +561,11 @@ private AxisColumn getGroupByColumn(String groupBy) throws ReportingException {
/**
* Returns constructed the report elements for the report.
*
* @param productTestPlan product test plan to construct the report elements
* @param productTestPlan product test plan to construct the report elements
* @param groupByAxisColumn grouped by column name
* @return constructed report elements
*/
private List<ReportElement> constructReportElements(ProductTestPlan productTestPlan) {
private List<ReportElement> constructReportElements(ProductTestPlan productTestPlan, AxisColumn groupByAxisColumn) {
List<TestPlan> testPlans = productTestPlan.getTestPlans();
List<ReportElement> reportElements = new ArrayList<>();

Expand All @@ -553,7 +574,8 @@ private List<ReportElement> constructReportElements(ProductTestPlan productTestP

// If infra is failed then there are no test scenarios
if (infraStatus.equals(InfraResult.Status.INFRASTRUCTURE_ERROR)) {
ReportElement reportElement = createReportElement(testPlan, null, null);
ReportElement reportElement = createReportElement(testPlan, null, null,
groupByAxisColumn);
reportElements.add(reportElement);
continue;
}
Expand All @@ -565,7 +587,8 @@ private List<ReportElement> constructReportElements(ProductTestPlan productTestP
// Test cases
List<TestCase> testCases = testScenario.getTestCases();
for (TestCase testCase : testCases) {
ReportElement reportElement = createReportElement(testPlan, testScenario, testCase);
ReportElement reportElement =
createReportElement(testPlan, testScenario, testCase, groupByAxisColumn);
reportElements.add(reportElement);
}
}
Expand All @@ -576,18 +599,20 @@ private List<ReportElement> constructReportElements(ProductTestPlan productTestP
/**
* Creates and returns an {@link ReportElement} instance for the given params.
*
* @param testPlan test plan
* @param testScenario test scenario (can be null if the infra is failed)
* @param testCase test case (can be null if the infra is failed)
* @param testPlan test plan
* @param testScenario test scenario (can be null if the infra is failed)
* @param testCase test case (can be null if the infra is failed)
* @param groupByAxisColumn grouped by column name
* @return {@link ReportElement} for the given params
*/
private ReportElement createReportElement(TestPlan testPlan, TestScenario testScenario, TestCase testCase) {
private ReportElement createReportElement(TestPlan testPlan, TestScenario testScenario, TestCase testCase,
AxisColumn groupByAxisColumn) {
InfraCombination infraCombination = testPlan.getInfraResult().getInfraCombination();
InfraResult.Status infraStatus = testPlan.getInfraResult().getStatus();
boolean isInfraSuccess = !infraStatus.equals(InfraResult.Status.INFRASTRUCTURE_ERROR) &&
!infraStatus.equals(InfraResult.Status.INFRASTRUCTURE_DESTROY_ERROR);

ReportElement reportElement = new ReportElement();
ReportElement reportElement = new ReportElement(groupByAxisColumn);

// Information related to the test plan.
reportElement.setDeployment(testPlan.getDeploymentPattern());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class GroupBy {
private final String groupByColumnKey;
private final String groupByColumnValue;
private final List<ReportElement> reportElements;
private final boolean isGroupByDeployment;
private final boolean isGroupByInfrastructure;
private final boolean isGroupByScenario;
private final String parsedReportElementsString;

/**
Expand All @@ -55,6 +58,11 @@ public GroupBy(String groupByColumnValue, List<ReportElement> reportElements, Ax
this.groupByColumnValue = groupByColumnValue;
this.reportElements = reportElements;

// Group by column booleans
isGroupByDeployment = axisColumn.equals(AxisColumn.DEPLOYMENT);
isGroupByInfrastructure = axisColumn.equals(AxisColumn.INFRASTRUCTURE);
isGroupByScenario = axisColumn.equals(AxisColumn.SCENARIO);

// Render report elements
Map<String, Object> reportElementsMap = new HashMap<>();
reportElementsMap.put(REPORT_ELEMENT_TEMPLATE_KEY, reportElements);
Expand Down Expand Up @@ -89,6 +97,33 @@ public List<ReportElement> getReportElements() {
return reportElements;
}

/**
* Returns whether the grouping is done by the deployment column.
*
* @return {@code true} if grouped by deployment, {@code false} otherwise
*/
public boolean isGroupByDeployment() {
return isGroupByDeployment;
}

/**
* Returns whether the grouping is done by the infrastructure column.
*
* @return {@code true} if grouped by infrastructure, {@code false} otherwise
*/
public boolean isGroupByInfrastructure() {
return isGroupByInfrastructure;
}

/**
* Returns whether the grouping is done by the scenario column.
*
* @return {@code true} if grouped by scenario, {@code false} otherwise
*/
public boolean isGroupByScenario() {
return isGroupByScenario;
}

/**
* Returns the HTML group by elements string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.wso2.testgrid.common.Database;
import org.wso2.testgrid.common.InfraCombination;
import org.wso2.testgrid.common.OperatingSystem;
import org.wso2.testgrid.reporting.AxisColumn;

/**
* Bean class to maintain a single report element in a report.
Expand All @@ -28,6 +29,9 @@
*/
public class ReportElement {

private final boolean isGroupByDeployment;
private final boolean isGroupByInfrastructure;
private final boolean isGroupByScenario;
private String deployment;
private String operatingSystem;
private String database;
Expand All @@ -38,6 +42,17 @@ public class ReportElement {
private boolean isInfraSuccess;
private boolean isTestSuccess;

/**
* Constructs an instance of {@link ReportElement} for the given parameters.
*
* @param axisColumn axis column grouped by
*/
public ReportElement(AxisColumn axisColumn) {
isGroupByDeployment = axisColumn.equals(AxisColumn.DEPLOYMENT);
isGroupByInfrastructure = axisColumn.equals(AxisColumn.INFRASTRUCTURE);
isGroupByScenario = axisColumn.equals(AxisColumn.SCENARIO);
}

/**
* Returns the name of the deployment.
*
Expand Down Expand Up @@ -199,4 +214,32 @@ public boolean isTestSuccess() {
public void setTestSuccess(boolean testSuccess) {
isTestSuccess = testSuccess;
}


/**
* Returns whether the grouping is done by the deployment column.
*
* @return {@code true} if grouped by deployment, {@code false} otherwise
*/
public boolean isGroupByDeployment() {
return isGroupByDeployment;
}

/**
* Returns whether the grouping is done by the infrastructure column.
*
* @return {@code true} if grouped by infrastructure, {@code false} otherwise
*/
public boolean isGroupByInfrastructure() {
return isGroupByInfrastructure;
}

/**
* Returns whether the grouping is done by the scenario column.
*
* @return {@code true} if grouped by scenario, {@code false} otherwise
*/
public boolean isGroupByScenario() {
return isGroupByScenario;
}
}
24 changes: 15 additions & 9 deletions reporting/src/main/resources/templates/group_by.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
<tr>
<th style="width: 5%">
</th>
<th style="width: 12.5%">
<span>Deployment</span>
</th>
<th style="width: 12.5%">
<span>Infrastructure</span>
</th>
<th style="width: 12.5%">
<span>Scenario</span>
</th>
{{^isGroupByDeployment}}
<th style="width: 12.5%">
<span>Deployment</span>
</th>
{{/isGroupByDeployment}}
{{^isGroupByInfrastructure}}
<th style="width: 12.5%">
<span>Infrastructure</span>
</th>
{{/isGroupByInfrastructure}}
{{^isGroupByScenario}}
<th style="width: 12.5%">
<span>Scenario</span>
</th>
{{/isGroupByScenario}}
<th style="width: 12.5%">
<span>Test case</span>
</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
</table>
<br/>
<br/>
<br/>

<!-- Summaries -->
<table class="reportTable">
Expand All @@ -46,6 +45,5 @@
{{{parsedAxisSummariesString}}}
</table>
<br/>
<br/>
<!-- End of summaries -->
{{/perAxis}}
4 changes: 1 addition & 3 deletions reporting/src/main/resources/templates/report.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<tr>
<td valign="middle"
style="text-align: right; width: 12%; padding-right: 50px;">
<img style="height: 150px;"
<img style="height: 120px;"
src="http://www.robertsmania.com/G90/my_testpatterns/1080_Grid_01.jpg"/>
</td>
<td style=" padding: 1% 5%; font-family: arial; font-size: 16px; line-height: 24px; text-align: left;">
Expand Down Expand Up @@ -182,10 +182,8 @@
<br/>
<hr/>
<br/>
<br/>

<!-- Detailed Report -->
<br/>
<span class="mainTitle">Detailed Report</span>
<br/>
<br/>
Expand Down
Loading

0 comments on commit 6f59e5d

Please sign in to comment.