Search in sources :

Example 1 with CheckStyleAction

use of org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction in project acceptance-test-harness by jenkinsci.

the class CheckStylePluginTest method should_show_warnings_per_user.

/**
 * Verifies that blaming of warnings works on agents: creates a new project in a Git repository in a docker
 * container. Registers the same docker container as slave agent to build the project. Uses the recorded build
 * results in checkstyle-result.xml (no actual maven goal is invoked). Verifies that the blame information is
 * correctly assigned for each of the warnings. Also checks, that the age is increased for yet another build.
 */
@Test
@WithPlugins({ "git", "dashboard-view", "analysis-core@1.88-SNAPSHOT", "ssh-slaves" })
@WithDocker
@Issue("JENKINS-6748")
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { CREDENTIALS_ID, CREDENTIALS_KEY })
public void should_show_warnings_per_user() {
    // avoid JENKINS-49026
    jenkins.restart();
    DumbSlave agent = createDockerAgent();
    String gitRepositoryUrl = createGitRepositoryInDockerContainer();
    FreeStyleJob job = createFreeStyleJob(jenkins, null, settings -> settings.pattern.set("**/checkstyle-result.xml"));
    job.configure(() -> {
        job.useScm(GitScm.class).url(gitRepositoryUrl).credentials(CREDENTIALS_ID);
        job.setLabelExpression(agent.getName());
    });
    buildSuccessfulJob(job);
    CheckStyleAction action = new CheckStyleAction(job);
    action.open();
    SortedMap<String, Integer> expectedPeople = new TreeMap<>();
    expectedPeople.put("Unknown authors", 1);
    expectedPeople.put("Jenkins-ATH <jenkins-ath@example.org>", 11);
    assertThat(action.getPeopleTabContents(), is(expectedPeople));
    action.find(By.partialLinkText("Jenkins-ATH")).click();
    assertThat(driver, hasContent("Checkstyle Warnings - Jenkins-ATH"));
    action.open();
    SortedMap<String, String> expectedOrigin = new TreeMap<>();
    expectedOrigin.put("Main.java:0", "-");
    expectedOrigin.put("Main.java:2", "Jenkins-ATH");
    expectedOrigin.put("Main.java:4", "Jenkins-ATH");
    expectedOrigin.put("Main.java:6", "Jenkins-ATH");
    expectedOrigin.put("Main.java:9", "Jenkins-ATH");
    expectedOrigin.put("Main.java:13", "Jenkins-ATH");
    expectedOrigin.put("Main.java:18", "Jenkins-ATH");
    expectedOrigin.put("Main.java:23", "Jenkins-ATH");
    expectedOrigin.put("Main.java:24", "Jenkins-ATH");
    expectedOrigin.put("Main.java:27", "Jenkins-ATH");
    assertThat(action.getOriginTabContentsAsStrings(AUTHOR), is(expectedOrigin));
    assertThatAgeIsAt(action, expectedOrigin, 1);
    buildSuccessfulJob(job);
    assertThatAgeIsAt(action, expectedOrigin, 2);
    GraphConfigurationView view = action.configureTrendGraphForUser();
    view.open();
    view.setUserGraph();
    view.save();
    WebElement graph = find(getUsersTrendGraphXpath());
    assertThat(graph.isDisplayed(), is(true));
    verifyNoAuthors(action, true);
    WebElement nothing = getElement(getUsersTrendGraphXpath());
    assertThat(nothing, nullValue());
    verifyNoAuthors(action, false);
}
Also used : CheckStyleAction(org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction) GraphConfigurationView(org.jenkinsci.test.acceptance.plugins.analysis_core.GraphConfigurationView) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) TreeMap(java.util.TreeMap) WebElement(org.openqa.selenium.WebElement) Issue(org.jvnet.hudson.test.Issue) WithCredentials(org.jenkinsci.test.acceptance.junit.WithCredentials) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins) WithDocker(org.jenkinsci.test.acceptance.junit.WithDocker)

Example 2 with CheckStyleAction

use of org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction in project acceptance-test-harness by jenkinsci.

the class CheckStylePluginTest method should_retrieve_results_from_maven_job.

/**
 * Builds a maven project and checks if new warning are displayed.
 */
@Test
public void should_retrieve_results_from_maven_job() {
    MavenModuleSet job = createMavenJob();
    Build build = buildSuccessfulJob(job);
    assertThatCheckStyleResultExists(job, build);
    build.open();
    CheckStyleAction checkstyle = new CheckStyleAction(build);
    checkstyle.open();
    assertThat(checkstyle.getNumberOfNewWarnings(), is(12));
}
Also used : CheckStyleAction(org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction) Build(org.jenkinsci.test.acceptance.po.Build) MavenModuleSet(org.jenkinsci.test.acceptance.plugins.maven.MavenModuleSet) Test(org.junit.Test)

Example 3 with CheckStyleAction

use of org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction in project acceptance-test-harness by jenkinsci.

the class CheckStylePluginTest method should_link_to_source_code_in_real_project.

/**
 * Builds an existing freestyle project using actual maven commands and checks if new warning are displayed. Also
 * verifies that the warnings have links to the actual source code and the source code view shows the affected
 * line.
 */
@Test
public void should_link_to_source_code_in_real_project() {
    FreeStyleJob job = createJob(jenkins, CHECKSTYLE_PLUGIN_ROOT + SAMPLE_CHECKSTYLE_PROJECT, FreeStyleJob.class, CheckStyleFreestyleSettings.class, settings -> settings.pattern.set("target/checkstyle-result.xml"));
    setMavenGoal(job, "clean package checkstyle:checkstyle");
    Build build = buildSuccessfulJob(job);
    assertThatCheckStyleResultExists(job, build);
    build.open();
    CheckStyleAction checkstyle = new CheckStyleAction(build);
    checkstyle.open();
    assertThat(checkstyle.getNumberOfNewWarnings(), is(12));
    SortedMap<String, String> expectedContent = new TreeMap<>();
    expectedContent.put("Main.java:0", "JavadocPackageCheck");
    expectedContent.put("Main.java:2", "HideUtilityClassConstructorCheck");
    expectedContent.put("Main.java:4", "JavadocVariableCheck");
    expectedContent.put("Main.java:6", "FinalParametersCheck");
    expectedContent.put("Main.java:9", "WhitespaceAroundCheck");
    expectedContent.put("Main.java:13", "WhitespaceAroundCheck");
    expectedContent.put("Main.java:18", "WhitespaceAroundCheck");
    expectedContent.put("Main.java:23", "JavadocMethodCheck");
    expectedContent.put("Main.java:24", "MagicNumberCheck");
    expectedContent.put("Main.java:27", "JavadocMethodCheck");
    assertThat(checkstyle.getWarningsTabContents(), is(expectedContent));
    verifySourceLine(checkstyle, "Main.java", 27, "27     public static int return8() {", "Checks the Javadoc of a method or constructor.");
}
Also used : CheckStyleAction(org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 4 with CheckStyleAction

use of org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction in project acceptance-test-harness by jenkinsci.

the class CheckStylePluginTest method should_resolve_environment_variables.

/**
 * Verifies that environment variables are expanded in the file name pattern.
 */
@Test
@Issue("JENKINS-30735")
@WithPlugins({ "envinject", "analysis-core@1.77", "checkstyle@3.46" })
public void should_resolve_environment_variables() {
    FreeStyleJob job = createFreeStyleJob(settings -> settings.pattern.set("checkstyle${ENV_DASH}result.xml"));
    job.configure(() -> new EnvInjectConfig.Environment(job).properties.sendKeys("ENV_DASH=-"));
    Build build = buildSuccessfulJob(job);
    assertThatCheckStyleResultExists(job, build);
    CheckStyleAction action = new CheckStyleAction(job);
    assertThatWarningsCountInSummaryIs(action, TOTAL_NUMBER_OF_WARNINGS);
    assertThatNewWarningsCountInSummaryIs(action, TOTAL_NUMBER_OF_WARNINGS);
    assertThat(build.getConsole(), containsRegexp("\\[CHECKSTYLE\\] Searching for all files in .* that match the pattern checkstyle-result.xml\n"));
}
Also used : CheckStyleAction(org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction) EnvInjectConfig(org.jenkinsci.test.acceptance.plugins.envinject.EnvInjectConfig) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 5 with CheckStyleAction

use of org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction in project acceptance-test-harness by jenkinsci.

the class CheckStylePluginTest method verifyWarningCounts.

private void verifyWarningCounts(final Build build) {
    CheckStyleAction action = new CheckStyleAction(build);
    assertThatWarningsCountInSummaryIs(action, 679);
    assertThatNewWarningsCountInSummaryIs(action, 2);
    assertThatFixedWarningsCountInSummaryIs(action, 99);
    action.open();
    assertThat(action.getNumberOfWarnings(), is(679));
    assertThat(action.getNumberOfNewWarnings(), is(2));
    assertThat(action.getNumberOfFixedWarnings(), is(99));
    assertThat(action.getNumberOfWarningsWithHighPriority(), is(679));
    assertThat(action.getNumberOfWarningsWithNormalPriority(), is(0));
    assertThat(action.getNumberOfWarningsWithLowPriority(), is(0));
    action.openNew();
    assertThat(action.getNumberOfWarningsWithHighPriority(), is(2));
    assertThat(action.getNumberOfWarningsWithNormalPriority(), is(0));
    assertThat(action.getNumberOfWarningsWithLowPriority(), is(0));
    action.openFixed();
    assertThat(action.getNumberOfRowsInFixedWarningsTable(), is(99));
}
Also used : CheckStyleAction(org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction)

Aggregations

CheckStyleAction (org.jenkinsci.test.acceptance.plugins.checkstyle.CheckStyleAction)7 Build (org.jenkinsci.test.acceptance.po.Build)5 Test (org.junit.Test)5 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)3 TreeMap (java.util.TreeMap)2 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)2 MavenModuleSet (org.jenkinsci.test.acceptance.plugins.maven.MavenModuleSet)2 Issue (org.jvnet.hudson.test.Issue)2 WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)1 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)1 GraphConfigurationView (org.jenkinsci.test.acceptance.plugins.analysis_core.GraphConfigurationView)1 EnvInjectConfig (org.jenkinsci.test.acceptance.plugins.envinject.EnvInjectConfig)1 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)1 Node (org.jenkinsci.test.acceptance.po.Node)1 WebElement (org.openqa.selenium.WebElement)1