Skip to content

Commit

Permalink
Add source code navigation and details filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Sep 27, 2019
1 parent eaa36d4 commit 412405b
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author Ullrich Hafner
*/
public class AnalysisResult extends PageObject {
private static final String[] DRY_TOOLS = new String[] {"cpd", "simian", "dupfinder"};
private static final String[] DRY_TOOLS = {"cpd", "simian", "dupfinder"};

private final String id;

Expand Down Expand Up @@ -132,8 +132,8 @@ public void openTab(final Tab tab) {
public IssuesTable openIssuesTable() {
openTab(Tab.ISSUES);

WebElement issuesTable = find(By.id("issues"));
return new IssuesTable(issuesTable, this, getIssuesTableType());
WebElement issuesTab = find(By.id("issuesContent"));
return new IssuesTable(issuesTab, this, getIssuesTableType());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,31 @@ public class IssuesTable {
private final List<AbstractIssuesTableRow> tableRows = new ArrayList<>();
private final List<String> headers;
private final WebElement tableElement;
private final WebElement issuesTab;
private final IssuesTableRowType type;

/**
* Creates an IssuesTable of a specific type.
*
* @param element
* the WebElement representing the issues-table
* @param issuesTab
* the WebElement containing the issues-tab
* @param resultDetailsPage
* the AnalysisResult on which the issues-table is displayed on
* @param type
* the type of the issues-table (e.g. Default or DRY)
*/
public IssuesTable(final WebElement element, final AnalysisResult resultDetailsPage, final IssuesTableRowType type) {
headers = element.findElements(By.xpath(".//thead/tr/th"))
public IssuesTable(final WebElement issuesTab, final AnalysisResult resultDetailsPage, final IssuesTableRowType type) {
this.issuesTab = issuesTab;
this.resultDetailsPage = resultDetailsPage;
this.type = type;

tableElement = issuesTab.findElement(By.id("issues"));
headers = tableElement.findElements(By.xpath(".//thead/tr/th"))
.stream()
.map(WebElement::getText)
.collect(
Collectors.toList());
this.type = type;
this.tableElement = element;
updateTableRows();
this.resultDetailsPage = resultDetailsPage;
}

/**
Expand All @@ -54,10 +57,16 @@ public IssuesTable(final WebElement element, final AnalysisResult resultDetailsP
*
* @return the PageObject representing the target page
*/
public <T extends PageObject> T clickLinkOnSite(WebElement link, Class<T> targetPageClass) {
public <T extends PageObject> T clickLinkOnSite(final WebElement link, final Class<T> targetPageClass) {
return resultDetailsPage.openLinkOnSite(link, targetPageClass);
}

public int getTotal() {
String tableInfo = issuesTab.findElement(By.id("issues_info")).getText();
String total = StringUtils.substringAfter(tableInfo, "of ");
return Integer.parseInt(StringUtils.substringBefore(total, " "));
}

/**
* Updates the table rows. E.g. if they are changed by toggling a details-row.
*/
Expand Down Expand Up @@ -136,7 +145,7 @@ public List<String> getHeaders() {
*
* @return the row
*/
public <T extends AbstractIssuesTableRow> T getRowAs(int row, Class<T> expectedClass) {
public <T extends AbstractIssuesTableRow> T getRowAs(final int row, final Class<T> expectedClass) {
return getTableRows().get(row).getAs(expectedClass);
}

Expand All @@ -149,8 +158,8 @@ public <T extends AbstractIssuesTableRow> T getRowAs(int row, Class<T> expectedC
* @return the filtered AnalysisResult
*/
public AnalysisResult clickFilterLinkOnSite(final WebElement element) {
return this.resultDetailsPage.openFilterLinkOnSite(element);
return resultDetailsPage.openFilterLinkOnSite(element);
}

public enum IssuesTableRowType {DEFAULT, DRY}
}
}
183 changes: 104 additions & 79 deletions src/test/java/plugins/WarningsNextGenerationPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,34 +156,76 @@ public void should_show_build_summary_and_link_to_details() {

Build build = buildJob(job);

verifyCheckStyle(build);
verifyPmd(build);
verifyFindBugs(build);
verifyCpd(build);
}

private void verifyCpd(final Build build) {
build.open();
AnalysisSummary checkstyle = new AnalysisSummary(build, CHECKSTYLE_ID);
assertThat(checkstyle).isDisplayed();
assertThat(checkstyle).hasTitleText("CheckStyle: 3 warnings");
assertThat(checkstyle).hasNewSize(3);
assertThat(checkstyle).hasFixedSize(1);
assertThat(checkstyle).hasReferenceBuild(1);
assertThat(checkstyle).hasInfoType(InfoType.ERROR);
AnalysisSummary cpd = new AnalysisSummary(build, CPD_ID);
assertThat(cpd).isDisplayed();
assertThat(cpd).hasTitleText("CPD: 20 warnings");
assertThat(cpd).hasNewSize(20);
assertThat(cpd).hasFixedSize(0);
assertThat(cpd).hasReferenceBuild(1);
assertThat(cpd).hasInfoType(InfoType.INFO);

AnalysisResult checkstyleDetails = checkstyle.openOverallResult();
assertThat(checkstyleDetails).hasActiveTab(Tab.CATEGORIES);
assertThat(checkstyleDetails).hasTotal(3);
assertThat(checkstyleDetails).hasOnlyAvailableTabs(Tab.CATEGORIES, Tab.TYPES, Tab.ISSUES);
AnalysisResult cpdDetails = cpd.openOverallResult();
assertThat(cpdDetails).hasActiveTab(Tab.ISSUES);
assertThat(cpdDetails).hasOnlyAvailableTabs(Tab.ISSUES);

IssuesTable issuesTable = cpdDetails.openIssuesTable();
assertThat(issuesTable).hasSize(10);
assertThat(issuesTable).hasTotal(20);

DryIssuesTableRow firstRow = issuesTable.getRowAs(0, DryIssuesTableRow.class);
DryIssuesTableRow secondRow = issuesTable.getRowAs(1, DryIssuesTableRow.class);

firstRow.toggleDetailsRow();
assertThat(issuesTable).hasSize(11);

DetailsTableRow detailsRow = issuesTable.getRowAs(1, DetailsTableRow.class);
assertThat(detailsRow).hasDetails("Found duplicated code.\nfunctionOne();");

assertThat(issuesTable.getRowAs(2, DryIssuesTableRow.class)).isEqualTo(secondRow);

firstRow.toggleDetailsRow();
assertThat(issuesTable).hasSize(10);
assertThat(issuesTable.getRowAs(1, DryIssuesTableRow.class)).isEqualTo(secondRow);

SourceView sourceView = firstRow.openSourceCode();
assertThat(sourceView).hasFileName(CPD_SOURCE_NAME);

String expectedSourceCode = toString(WARNINGS_PLUGIN_PREFIX + CPD_SOURCE_PATH);
assertThat(sourceView.getSourceCode()).isEqualToIgnoringWhitespace(expectedSourceCode);

cpdDetails.open();
issuesTable = cpdDetails.openIssuesTable();
firstRow = issuesTable.getRowAs(0, DryIssuesTableRow.class);

AnalysisResult lowSeverity = firstRow.clickOnSeverityLink();
IssuesTable lowSeverityTable = lowSeverity.openIssuesTable();
assertThat(lowSeverityTable).hasSize(6);
assertThat(lowSeverityTable).hasTotal(6);

for (int i = 0; i < 6; i++) {
DryIssuesTableRow row = lowSeverityTable.getRowAs(i, DryIssuesTableRow.class);
assertThat(row).hasSeverity("Low");
}

build.open();
AnalysisSummary pmd = new AnalysisSummary(build, PMD_ID);
assertThat(pmd).isDisplayed();
assertThat(pmd).hasTitleText("PMD: 2 warnings");
assertThat(pmd).hasNewSize(0);
assertThat(pmd).hasFixedSize(1);
assertThat(pmd).hasReferenceBuild(1);
assertThat(pmd).hasInfoType(InfoType.ERROR);
assertThat(openInfoView(build, CPD_ID))
.hasNoErrorMessages()
.hasInfoMessages("-> found 1 file",
"-> found 20 issues (skipped 0 duplicates)",
"-> 1 copied, 0 not in workspace, 0 not-found, 0 with I/O error",
"Issues delta (vs. reference build): outstanding: 0, new: 20, fixed: 0");

AnalysisResult pmdDetails = pmd.openOverallResult();
assertThat(pmdDetails).hasActiveTab(Tab.CATEGORIES);
assertThat(pmdDetails).hasTotal(2);
assertThat(pmdDetails).hasOnlyAvailableTabs(Tab.CATEGORIES, Tab.TYPES, Tab.ISSUES);
}

private void verifyFindBugs(final Build build) {
build.open();
AnalysisSummary findbugs = new AnalysisSummary(build, FINDBUGS_ID);
assertThat(findbugs).isDisplayed();
Expand All @@ -195,21 +237,27 @@ public void should_show_build_summary_and_link_to_details() {
assertThat(findbugs).hasDetails("No warnings for 2 builds, i.e. since build 1");

build.open();
AnalysisSummary cpd = new AnalysisSummary(build, CPD_ID);
assertThat(cpd).isDisplayed();
assertThat(cpd).hasTitleText("CPD: 20 warnings");
assertThat(cpd).hasNewSize(20);
assertThat(cpd).hasFixedSize(0);
assertThat(cpd).hasReferenceBuild(1);
assertThat(cpd).hasInfoType(InfoType.INFO);
assertThat(openInfoView(build, FINDBUGS_ID))
.hasNoErrorMessages()
.hasInfoMessages("-> found 1 file",
"-> found 0 issues (skipped 0 duplicates)",
"Issues delta (vs. reference build): outstanding: 0, new: 0, fixed: 0");
}

private void verifyPmd(final Build build) {
build.open();
assertThat(openInfoView(build, CHECKSTYLE_ID))
.hasInfoMessages("-> found 1 file",
"-> found 3 issues (skipped 0 duplicates)",
"Issues delta (vs. reference build): outstanding: 0, new: 3, fixed: 1")
.hasErrorMessages("Can't resolve absolute paths for some files:",
"Can't create fingerprints for some files:");
AnalysisSummary pmd = new AnalysisSummary(build, PMD_ID);
assertThat(pmd).isDisplayed();
assertThat(pmd).hasTitleText("PMD: 2 warnings");
assertThat(pmd).hasNewSize(0);
assertThat(pmd).hasFixedSize(1);
assertThat(pmd).hasReferenceBuild(1);
assertThat(pmd).hasInfoType(InfoType.ERROR);

AnalysisResult pmdDetails = pmd.openOverallResult();
assertThat(pmdDetails).hasActiveTab(Tab.CATEGORIES);
assertThat(pmdDetails).hasTotal(2);
assertThat(pmdDetails).hasOnlyAvailableTabs(Tab.CATEGORIES, Tab.TYPES, Tab.ISSUES);

build.open();
assertThat(openInfoView(build, PMD_ID))
Expand All @@ -218,21 +266,30 @@ public void should_show_build_summary_and_link_to_details() {
"Issues delta (vs. reference build): outstanding: 2, new: 0, fixed: 1")
.hasErrorMessages("Can't resolve absolute paths for some files:",
"Can't create fingerprints for some files:");
}

private void verifyCheckStyle(final Build build) {
build.open();
assertThat(openInfoView(build, FINDBUGS_ID))
.hasNoErrorMessages()
.hasInfoMessages("-> found 1 file",
"-> found 0 issues (skipped 0 duplicates)",
"Issues delta (vs. reference build): outstanding: 0, new: 0, fixed: 0");
AnalysisSummary checkstyle = new AnalysisSummary(build, CHECKSTYLE_ID);
assertThat(checkstyle).isDisplayed();
assertThat(checkstyle).hasTitleText("CheckStyle: 3 warnings");
assertThat(checkstyle).hasNewSize(3);
assertThat(checkstyle).hasFixedSize(1);
assertThat(checkstyle).hasReferenceBuild(1);
assertThat(checkstyle).hasInfoType(InfoType.ERROR);

AnalysisResult checkstyleDetails = checkstyle.openOverallResult();
assertThat(checkstyleDetails).hasActiveTab(Tab.CATEGORIES);
assertThat(checkstyleDetails).hasTotal(3);
assertThat(checkstyleDetails).hasOnlyAvailableTabs(Tab.CATEGORIES, Tab.TYPES, Tab.ISSUES);

build.open();
assertThat(openInfoView(build, CPD_ID))
.hasNoErrorMessages()
assertThat(openInfoView(build, CHECKSTYLE_ID))
.hasInfoMessages("-> found 1 file",
"-> found 20 issues (skipped 0 duplicates)",
"-> 1 copied, 0 not in workspace, 0 not-found, 0 with I/O error",
"Issues delta (vs. reference build): outstanding: 0, new: 20, fixed: 0");
"-> found 3 issues (skipped 0 duplicates)",
"Issues delta (vs. reference build): outstanding: 0, new: 3, fixed: 1")
.hasErrorMessages("Can't resolve absolute paths for some files:",
"Can't create fingerprints for some files:");
}

private InfoView openInfoView(final Build build, final String toolId) {
Expand Down Expand Up @@ -290,39 +347,6 @@ public void should_aggregate_tools_into_single_result() {
Tab.TOOLS, Tab.PACKAGES, Tab.FILES, Tab.CATEGORIES, Tab.TYPES, Tab.ISSUES);
}

/**
* Verifies that clicking on the (+) icon within the details column of the issues table will show and hide the
* details child row.
*/
@Test
public void should_open_and_hide_details_row() {
Build build = createAndBuildFreeStyleJob("CPD",
cpd -> cpd.setHighThreshold(2).setNormalThreshold(1),
CPD_REPORT, CPD_SOURCE_PATH);

AnalysisResult result = openAnalysisResult(build, CPD_ID);
IssuesTable issuesTable = result.openIssuesTable();
assertThat(issuesTable).hasSize(10);

DryIssuesTableRow firstRow = issuesTable.getRowAs(0, DryIssuesTableRow.class);
DryIssuesTableRow secondRow = issuesTable.getRowAs(1, DryIssuesTableRow.class);

firstRow.toggleDetailsRow();
assertThat(issuesTable).hasSize(11);

DetailsTableRow detailsRow = issuesTable.getRowAs(1, DetailsTableRow.class);
assertThat(detailsRow).hasDetails(
"Found duplicated code.\npublic static void functionOne()\n"
+ " {\n"
+ " System.out.println(\"testfile for redundancy\");");

assertThat(issuesTable.getRowAs(2, DryIssuesTableRow.class)).isEqualTo(secondRow);

firstRow.toggleDetailsRow();
assertThat(issuesTable).hasSize(10);
assertThat(issuesTable.getRowAs(1, DryIssuesTableRow.class)).isEqualTo(secondRow);
}

/**
* Verifies that the links to the source code view are working.
*/
Expand Down Expand Up @@ -425,7 +449,8 @@ private IssuesRecorder addRecorderWith3Tools(final FreeStyleJob job) {
recorder.setTool("CheckStyle");
recorder.addTool("FindBugs");
recorder.addTool("PMD");
recorder.addTool("CPD");
recorder.addTool("CPD",
cpd -> cpd.setHighThreshold(8).setNormalThreshold(3));
recorder.setEnabledForFailure(true);
});
}
Expand Down

0 comments on commit 412405b

Please sign in to comment.