Search in sources :

Example 1 with DumbSlave

use of org.jenkinsci.test.acceptance.po.DumbSlave 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 DumbSlave

use of org.jenkinsci.test.acceptance.po.DumbSlave in project acceptance-test-harness by jenkinsci.

the class WarningsPluginTest method should_parse_codenarc_on_agent.

@Test
@Issue("JENKINS-17787")
@WithPlugins({ "violations", "ssh-slaves" })
@WithDocker
@Ignore("Reproduces JENKINS-17787")
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { CREDENTIALS_ID, CREDENTIALS_KEY })
public void should_parse_codenarc_on_agent() {
    DumbSlave dockerSlave = createDockerAgent();
    FreeStyleJob job = prepareDockerSlave(dockerSlave);
    assertThatCodeNarcActionExists(job);
}
Also used : FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) Ignore(org.junit.Ignore) 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 3 with DumbSlave

use of org.jenkinsci.test.acceptance.po.DumbSlave in project acceptance-test-harness by jenkinsci.

the class WarningsPluginTest method should_scan_console_log_of_slave_build.

@Test
@WithDocker
@WithCredentials(credentialType = WithCredentials.SSH_USERNAME_PRIVATE_KEY, values = { CREDENTIALS_ID, CREDENTIALS_KEY })
@WithPlugins("ssh-slaves")
public void should_scan_console_log_of_slave_build() throws ExecutionException, InterruptedException {
    DumbSlave dockerSlave = createDockerAgent();
    FreeStyleJob job = prepareDockerSlave(dockerSlave);
    job.configure();
    job.copyResource(resource(RESOURCE_WARNING_MAIN_JAVA_PATH));
    ShellBuildStep shellBuildStep = job.addBuildStep(ShellBuildStep.class);
    shellBuildStep.command(CMD_WARNING_MAIN_JAVA_CONSOLE);
    WarningsPublisher warningsPublisher = job.addPublisher(WarningsPublisher.class);
    warningsPublisher.addConsoleScanner(JAVA_ID);
    job.save();
    Build build = job.startBuild().shouldSucceed();
    assertThatActionExists(job, build, "Java Warnings");
    WarningsAction action = createJavaResultAction(build);
    assertThatWarningsCountInSummaryIs(action, 3);
    String codeLine = action.getLinkedSourceFileText(AnalysisAction.Tab.DETAILS, "WarningMain.java", 10);
    String[] codeLineArr = codeLine.trim().split("\\s+", 2);
    assertThat("Warning should be at line", codeLineArr[0], is("10"));
    assertThat("Assert failed comparing code line is", codeLineArr[1], is("text =  (TextClass) text2;"));
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) WarningsPublisher(org.jenkinsci.test.acceptance.plugins.warnings.WarningsPublisher) ShellBuildStep(org.jenkinsci.test.acceptance.po.ShellBuildStep) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) WarningsAction(org.jenkinsci.test.acceptance.plugins.warnings.WarningsAction) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) 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 4 with DumbSlave

use of org.jenkinsci.test.acceptance.po.DumbSlave in project acceptance-test-harness by jenkinsci.

the class SshSlaveController method create.

private Slave create(String host, Jenkins j) {
    // Just to make sure the dumb slave is set up properly, we should seed it
    // with a FS root and executors
    final DumbSlave s = j.slaves.create(DumbSlave.class);
    s.find(by.input("_.host")).sendKeys(host);
    elasticSleep(25);
    final Select cId = new Select(s.find(by.input("_.credentialsId")));
    final String credentialName = String.format("%s (%s)", machine.getUser(), fingerprint);
    waitFor().until(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            List<WebElement> options = cId.getOptions();
            for (WebElement e : options) {
                if (credentialName.equals(e.getText()))
                    return true;
            }
            return false;
        }
    });
    cId.selectByVisibleText(credentialName);
    s.setExecutors(1);
    s.save();
    return s;
}
Also used : Select(org.openqa.selenium.support.ui.Select) List(java.util.List) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) WebElement(org.openqa.selenium.WebElement) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GeneralSecurityException(java.security.GeneralSecurityException)

Example 5 with DumbSlave

use of org.jenkinsci.test.acceptance.po.DumbSlave in project acceptance-test-harness by jenkinsci.

the class TSRCreateSlaveTest method newSlave.

@Test
@Since("1.560")
public void newSlave() {
    // this test requires a newer version of credentials plugin that has inline "Add" button
    // I'm not sure exactly which version it is, but 1.532 LTS doesn't have it, and 1.555 has it,
    // so it's somewhere in between
    // TODO: this should be converted to "@WithPlugin("ssh-credentials") with specific version tag,
    // not the core version
    // Just to make sure the dumb slave is set up properly, we should seed it
    // with a FS root and executors
    final DumbSlave s = jenkins.slaves.create(DumbSlave.class);
    {
        SshSlaveLauncher l = s.setLauncher(SshSlaveLauncher.class);
        String username = "user1";
        String privateKey = "1212122112";
        String description = "Ssh key";
        l.host.set("127.0.0.1");
        // make sure this exists
        l.credentialsId.resolve();
        try {
            l.credentialsId.select(String.format("%s (%s)", username, description));
            fail();
        } catch (NoSuchElementException e) {
        // ignore
        }
        SshCredentialDialog f = l.addCredential();
        {
            SshPrivateKeyCredential sc = f.select(SshPrivateKeyCredential.class);
            sc.description.set(description);
            sc.username.set(username);
            sc.selectEnterDirectly().privateKey.set(privateKey);
        }
        f.add();
        l.credentialsId.select(String.format("%s (%s)", username, description));
    }
    s.save();
}
Also used : SshSlaveLauncher(org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher) SshPrivateKeyCredential(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential) SshCredentialDialog(org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshCredentialDialog) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) NoSuchElementException(org.openqa.selenium.NoSuchElementException) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) Since(org.jenkinsci.test.acceptance.junit.Since)

Aggregations

DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)17 Test (org.junit.Test)12 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)8 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)8 SshSlaveLauncher (org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher)7 Matchers.containsString (org.hamcrest.Matchers.containsString)6 WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)5 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)5 Build (org.jenkinsci.test.acceptance.po.Build)5 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)5 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)4 SshPrivateKeyCredential (org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshPrivateKeyCredential)4 WarningsPublisher (org.jenkinsci.test.acceptance.plugins.warnings.WarningsPublisher)3 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)3 Issue (org.jvnet.hudson.test.Issue)3 IOException (java.io.IOException)2 Since (org.jenkinsci.test.acceptance.junit.Since)2 CredentialsPage (org.jenkinsci.test.acceptance.plugins.credentials.CredentialsPage)2 ManagedCredentials (org.jenkinsci.test.acceptance.plugins.credentials.ManagedCredentials)2 SshCredentialDialog (org.jenkinsci.test.acceptance.plugins.ssh_credentials.SshCredentialDialog)2