Search in sources :

Example 21 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_create_job_with_sidebar_link.

/**
 * Tests whether a sidebar link is set to a job created by JobDsl when a link url and link label
 * are set to this job and the seed job is build.
 */
@Test
@WithPlugins("sidebar-link")
public void should_create_job_with_sidebar_link() {
    // Arrange
    String jobName = "MyJob";
    String linkUrl = "https://jenkins.io";
    String linkLabel = "jenkins.io";
    String jobDslScript = String.format("job('%s') { properties { sidebarLinks { link('%s', '%s') } } }", jobName, linkUrl, linkLabel);
    Job seed = createSeedJobWithJobDsl(jobDslScript);
    // Act
    seed.startBuild().waitUntilFinished();
    Job job = jenkins.jobs.get(Job.class, jobName);
    // Assert
    job.open();
    assertThat(driver, hasElement(by.href(linkUrl)));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Job(org.jenkinsci.test.acceptance.po.Job) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 22 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_save_configurations.

/**
 * Verifies that all configurations, done on the job configuration page,
 * are saved correctly.
 */
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_save_configurations() {
    FreeStyleJob seedJob = createSeedJob();
    JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
    jobDsl.setScriptTargetsOnFilesystem("JobTest.groovy", "AnotherJobTest.groovy");
    jobDsl.setIgnoreMissingFiles(true);
    jobDsl.setIgnoreExisting(true);
    jobDsl.setRemovedJobAction(JobDslRemovedJobAction.DELETE);
    jobDsl.setRemovedViewAction(JobDslRemovedViewAction.DELETE);
    jobDsl.setRemovedConfigFilesAction(JobDslRemovedConfigFilesAction.DELETE);
    jobDsl.setLookupStrategy(JobDslLookupStrategy.SEED_JOB);
    jobDsl.setAdditionalClasspath("path1", "path2");
    jobDsl.setFailOnMissingPlugin(true);
    jobDsl.setUnstableOnDeprecation(true);
    seedJob.save();
    seedJob.configure();
    assertThat(jobDsl.isLookOnFilesystem(), is(true));
    assertThat(jobDsl.getScriptTargetsOnFilesystem(), equalTo(new String[] { "JobTest.groovy", "AnotherJobTest.groovy" }));
    assertThat(jobDsl.isIgnoreMissingFiles(), is(true));
    assertThat(jobDsl.isIgnoreExisting(), is(true));
    assertThat(jobDsl.getRemovedJobAction(), equalTo(JobDslRemovedJobAction.DELETE));
    assertThat(jobDsl.getRemovedViewAction(), equalTo(JobDslRemovedViewAction.DELETE));
    assertThat(jobDsl.getRemovedConfigFilesAction(), equalTo(JobDslRemovedConfigFilesAction.DELETE));
    assertThat(jobDsl.getLookupStrategy(), equalTo(JobDslLookupStrategy.SEED_JOB));
    assertThat(jobDsl.getAdditionalClasspath(), equalTo(new String[] { "path1", "path2" }));
    assertThat(jobDsl.isFailOnMissingPlugin(), is(true));
    assertThat(jobDsl.isUnstableOnDeprecation(), is(true));
    String script = "job('JobDSL-Test') {\n" + "    description('This is a description.')\n" + "}";
    jobDsl.setScript(script);
    seedJob.save();
    seedJob.configure();
    assertThat(jobDsl.isUseScriptText(), is(true));
    assertThat(jobDsl.getScript(), equalTo(script));
    setUpSecurity();
    jenkins.login().doLogin(ADMIN);
    seedJob.configure(() -> jobDsl.setUseSandbox(true));
    seedJob.configure();
    assertThat(jobDsl.isUseSandbox(), is(true));
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 23 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_run_grooy_sandbox_as_particular_user.

/**
 * Verifies that Groovy sandbox can only used if 'Access Control for Builds'
 * is configured. The DSL job needs to run as a particular user.
 */
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm", "authorize-project" })
public void should_run_grooy_sandbox_as_particular_user() {
    GlobalSecurityConfig sc = setUpSecurity();
    jenkins.login().doLogin(USER);
    FreeStyleJob seedJob = createSeedJob();
    JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
    jobDsl.setScript("job('New_Job')");
    jobDsl.setUseSandbox(true);
    seedJob.save();
    // Build should fail because script runs in sandbox but no particular user is specified
    // which should run the build
    Build build = seedJob.scheduleBuild().shouldFail();
    assertThat(build.getConsole(), containsString("You must configure the DSL job to run as a specific user in order to use the Groovy sandbox"));
    runBuildAsUserWhoTriggered(sc);
    jenkins.login().doLogin(USER);
    // Build should succeed because now a particular user is specified
    seedJob.scheduleBuild().shouldSucceed();
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) GlobalSecurityConfig(org.jenkinsci.test.acceptance.po.GlobalSecurityConfig) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 24 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_ignore_removed_config_files.

/**
 * Verifies whether a previously generated config file will be ignored if it
 * is not referenced anymore.
 */
@Test
@WithPlugins("config-file-provider")
public void should_ignore_removed_config_files() {
    FreeStyleJob seedJob = executeRemovedConfigFilesAction(JobDslRemovedConfigFilesAction.IGNORE);
    Build build = seedJob.scheduleBuild().shouldSucceed();
    Pattern expected = Pattern.compile("Unreferenced config files:(\\s*)GeneratedConfigFile[{]name='Old_Config_File', id='123456789'}");
    assertThat(build.getConsole(), containsRegexp(expected));
    ConfigFileProvider configFileProvider = new ConfigFileProvider(jenkins);
    configFileProvider.open();
    assertThat(driver, hasElement(by.xpath("//a[@href='editConfig?id=123456789']")));
}
Also used : Pattern(java.util.regex.Pattern) Build(org.jenkinsci.test.acceptance.po.Build) ConfigFileProvider(org.jenkinsci.test.acceptance.plugins.config_file_provider.ConfigFileProvider) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 25 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_lookup_at_seed_job.

/**
 * Verifies that relative job names are interpreted relative to the folder in which
 * the seed job is located.
 */
@Test
@WithPlugins("cloudbees-folder")
public void should_lookup_at_seed_job() {
    Folder folder = runSeedJobInFolder("New_Job", JobDslLookupStrategy.SEED_JOB);
    FreeStyleJob newJob = getJob("New_Job");
    assertThat(newJob, pageObjectDoesNotExist());
    newJob = folder.getJobs().get(FreeStyleJob.class, "New_Job");
    assertThat(newJob, pageObjectExists());
}
Also used : FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) Folder(org.jenkinsci.test.acceptance.po.Folder) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Aggregations

WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)89 Test (org.junit.Test)89 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)71 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)53 Build (org.jenkinsci.test.acceptance.po.Build)39 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)31 Issue (org.jvnet.hudson.test.Issue)25 Job (org.jenkinsci.test.acceptance.po.Job)19 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)15 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)15 ListView (org.jenkinsci.test.acceptance.po.ListView)13 View (org.jenkinsci.test.acceptance.po.View)13 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)12 WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)11 JobDslBuildStep (org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9 GlobalSecurityConfig (org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)9 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)8 Ignore (org.junit.Ignore)8 WarningsAction (org.jenkinsci.test.acceptance.plugins.warnings.WarningsAction)5