Skip to content
Permalink
Browse files

[JENKINS-39950] Added verification of all portlet links.

  • Loading branch information...
uhafner committed May 28, 2017
1 parent 562d274 commit 512817eef59b08b07c23e974f4853ec9a275b158
@@ -16,6 +16,10 @@ public ViewsMixIn(ContainerPageObject context) {
super(context);
}

public <T extends View> T create(final Class<T> type) {
return create(type, createRandomName());
}

public <T extends View> T create(final Class<T> type, String name) {

final Finder<WebElement> finder = new Finder<WebElement>() {
@@ -7,6 +7,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@@ -41,7 +42,6 @@
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.Job;
import org.jenkinsci.test.acceptance.po.ListView;
import org.jenkinsci.test.acceptance.po.TopLevelItem;
import org.jenkinsci.test.acceptance.po.WorkflowJob;
import org.jenkinsci.test.acceptance.po.WorkflowMultiBranchJob;
import org.junit.Test;
@@ -56,7 +56,6 @@
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.jenkinsci.test.acceptance.Matchers.*;
import static org.jenkinsci.test.acceptance.plugins.analysis_collector.AnalysisPlugin.*;
import static org.jenkinsci.test.acceptance.plugins.dashboard_view.DashboardView.*;
@@ -93,6 +92,7 @@
private static final int WARNINGS_LOW = 0;
private static final int LOW_COUNT = CHECKSTYLE_LOW + FINDBUGS_LOW + PMD_LOW + TASKS_LOW + WARNINGS_LOW;
private static final int NORMAL_COUNT = TOTAL - LOW_COUNT - HIGH_COUNT;
private static final List<AnalysisPlugin> ANALYSIS_PLUGINS = Arrays.asList(CHECKSTYLE, PMD, FINDBUGS, TASKS, WARNINGS);

@Inject
DockerContainerHolder<GitContainer> gitForMultiBranch;
@@ -308,20 +308,21 @@ public void should_set_warnings_count_in_list_view_column() {
* Each branch contains a Jenkinsfile and several warnings results files.
* Builds the jobs and verifies that the portlet is correctly filled and that all links open the correct page.
*/
@Test @Issue("JENKINS-39950") @WithPlugins({"dashboard-view", "nested-view"})
@Test @Issue({"JENKINS-39950"}) @WithPlugins({"dashboard-view", "nested-view", "git", "workflow-job", "workflow-cps", "workflow-basic-steps", "workflow-durable-task-step", "workflow-multibranch"})
@WithDocker @WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = {"warnings", "/org/jenkinsci/test/acceptance/docker/fixtures/GitContainer/unsafe"})
public void should_show_correct_links() throws InterruptedException, SftpException, JSchException, IOException {
NestedView nested = jenkins.getViews().create(NestedView.class, "Nested");
public void should_open_links_in_folder_dashboard_and_nested_views() {
// Given
NestedView nested = jenkins.getViews().create(NestedView.class);

DashboardView dashboard = nested.getViews().create(DashboardView.class, "Dashboard");
dashboard.configure();
dashboard.matchAllJobs();
dashboard.checkRecurseIntoFolders();
DashboardView dashboard = nested.getViews().create(DashboardView.class);
dashboard.configure( () -> {
dashboard.matchAllJobs();
dashboard.checkRecurseIntoFolders();

addWarningsPortlet(dashboard);
dashboard.save();
addWarningsPortlet(dashboard);
});

Folder folder = dashboard.jobs.create(Folder.class, "Folder");
Folder folder = dashboard.jobs.create(Folder.class);
folder.save();
folder.open();

@@ -335,20 +336,32 @@ public void should_show_correct_links() throws InterruptedException, SftpExcepti
job.save();
job.waitForBranchIndexingFinished(20);

WorkflowJob master = job.getJob("master");
master.build(1).waitUntilFinished().shouldSucceed();
WorkflowJob branch = job.getJob("branch");
branch.build(1).waitUntilFinished().shouldSucceed();
// When
List<String> jobs = Arrays.asList("master", "branch");
for (String name : jobs) {
buildBranch(job, name);
}

// Then
dashboard.open();

verifyWarningsCountInPortlet(master, dashboard);
verifyWarningsCountInPortlet(branch, dashboard);
for (String name : jobs) {
verifyWarningsCountInPortlet(name, dashboard);
}

// FIXME: check that the links are broken
List<WebElement> links = all(By.linkText(String.valueOf(CHECKSTYLE_ALL)));
assertThat(links, hasSize(2));
for (AnalysisPlugin plugin : ANALYSIS_PLUGINS) {
for (String name : jobs) {
dashboard.open();
findPortletLink(dashboard, name, plugin.getId()).click();
assertThat(driver, hasContent(plugin.getName()));
}
}
}

private WorkflowJob buildBranch(WorkflowMultiBranchJob job, String branchName) {
WorkflowJob master = job.getJob(branchName);
master.build(1).waitUntilFinished().shouldSucceed();
return master;
}

private String createGitRepositoryInDockerContainer() {
@@ -400,21 +413,24 @@ public void should_aggregate_warnings_in_dashboard_portlet() {
dashboard.save();

dashboard.open();
verifyWarningsCountInPortlet(job, dashboard);
verifyWarningsCountInPortlet(job.name, dashboard);

// uncheck Open Tasks
dashboard.configure(() -> portlet.checkCollectedPlugin(TASKS, false));
dashboard.open();

assertThat(dashboard, not(hasWarningsFor(job, TASKS, TASKS_ALL)));
assertThat(dashboard, not(hasWarnings(job.name, TASKS.getId(), TASKS_ALL)));
}

private void verifyWarningsCountInPortlet(TopLevelItem job, DashboardView dashboard) {
assertThat(dashboard, hasWarningsFor(job, CHECKSTYLE, CHECKSTYLE_ALL));
assertThat(dashboard, hasWarningsFor(job, PMD, PMD_ALL));
assertThat(dashboard, hasWarningsFor(job, FINDBUGS, FINDBUGS_ALL));
assertThat(dashboard, hasWarningsFor(job, TASKS, TASKS_ALL));
assertThat(dashboard, hasWarningsFor(job, WARNINGS, WARNINGS_ALL));
private void verifyWarningsCountInPortlet(String name, DashboardView dashboard) {
for (AnalysisPlugin plugin : ANALYSIS_PLUGINS) {
assertThat(dashboard, hasWarnings(name, CHECKSTYLE.getId(), CHECKSTYLE_ALL));

}
assertThat(dashboard, hasWarnings(name, PMD.getId(), PMD_ALL));
assertThat(dashboard, hasWarnings(name, FINDBUGS.getId(), FINDBUGS_ALL));
assertThat(dashboard, hasWarnings(name, TASKS.getId(), TASKS_ALL));
assertThat(dashboard, hasWarnings(name, WARNINGS.getId(), WARNINGS_ALL));
}

@Test @WithPlugins("workflow-aggregator")
@@ -564,13 +580,13 @@ private void addAndConfigureTasksPublisher(final FreeStyleJob job) {
configurator.accept(taskScannerSettings);
}

public static Matcher<DashboardView> hasWarningsFor(final TopLevelItem job, final AnalysisPlugin plugin, final int warningsCount) {
return new Matcher<DashboardView>(" shows %s warnings for plugin %s and job %s", warningsCount, plugin.getId(), job.name) {
public static Matcher<DashboardView> hasWarnings(final String jobName, final String pluginId, final int warningsCount) {
return new Matcher<DashboardView>(" shows %s warnings for plugin %s and job %s", warningsCount, pluginId, jobName) {
@Override
public boolean matchesSafely(final DashboardView view) {
view.open();
try {
WebElement warningsLink = view.find(by.css("a[href='job/" + job.name + "/" + plugin.getId() + "']"));
WebElement warningsLink = findPortletLink(view, jobName, pluginId);
String linkText = warningsLink.getText();
return Integer.parseInt(linkText) == warningsCount;
} catch (NoSuchElementException | NumberFormatException e) {
@@ -580,8 +596,12 @@ public boolean matchesSafely(final DashboardView view) {

@Override
public void describeMismatchSafely(final DashboardView view, final Description desc) {
desc.appendText("Portlet does not show expected warnings for plugin " + plugin.getId());
desc.appendText("Portlet does not show expected warnings for plugin " + pluginId);
}
};
}

private static WebElement findPortletLink(DashboardView view, String jobName, String pluginId) {
return view.find(by.css("a[href*='%s'][href$='%s']", jobName, pluginId));
}
}

0 comments on commit 512817e

Please sign in to comment.
You can’t perform that action at this time.