Search in sources :

Example 56 with WithPlugins

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

the class JobDslPluginTest method should_approve_administrator_script_automatically.

/**
 * Verifies that if script security for Job DSL scripts is enabled,
 * scripts saved by non administrators that not run in a Groovy sandbox
 * wont be executed.
 * If a administrator saves the seed job, any DSL scripts it contains
 * will be automatically approved. Afterwards the script
 * can be executed.
 */
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_approve_administrator_script_automatically() {
    setUpSecurity();
    jenkins.login().doLogin(USER);
    FreeStyleJob seedJob = createSeedJob();
    JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
    jobDsl.setScript("job('New_Job')");
    jobDsl.setUseSandbox(false);
    seedJob.save();
    // Build should fail because script is saved from non administrator an not yet approved
    Build build = seedJob.scheduleBuild().shouldFail();
    assertThat(build.getConsole(), containsString("script not yet approved for use"));
    jenkins.logout();
    jenkins.login().doLogin(ADMIN);
    // Build should fail because script is saved from non administrator an not yet approved
    Build build2 = seedJob.scheduleBuild().shouldFail();
    assertThat(build2.getConsole(), containsString("script not yet approved for use"));
    seedJob.configure();
    seedJob.save();
    jenkins.logout();
    jenkins.login().doLogin(USER);
    // Build should succeed because job was saved from administrator
    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) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 57 with WithPlugins

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

the class JobDslPluginTest method should_look_on_filesystem.

/**
 * Verifies that a list of newline separated DSL scripts, located in the workspace,
 * is read an executed in the same order as specified.
 * Therefore the first script creates an folder. The second script creates a job
 * in this folder. If the order is changed, the build will fail because the
 * folder was not created yet.
 */
@Test
@WithPlugins("cloudbees-folder")
public void should_look_on_filesystem() {
    FreeStyleJob seedJob = createSeedJob();
    seedJob.copyResource(resource("/job_dsl_plugin/CreateFolder.groovy"));
    seedJob.copyResource(resource("/job_dsl_plugin/CreateJobInFolder.groovy"));
    JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
    jobDsl.setScriptTargetsOnFilesystem("CreateFolder.groovy", "CreateJobInFolder.groovy");
    seedJob.save();
    Build build = seedJob.scheduleBuild().shouldSucceed();
    Pattern expected = Pattern.compile("Processing DSL script CreateFolder.groovy(\\s*)" + "Processing DSL script CreateJobInFolder.groovy");
    assertThat(build.getConsole(), containsRegexp(expected));
}
Also used : Pattern(java.util.regex.Pattern) JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) Build(org.jenkinsci.test.acceptance.po.Build) 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 58 with WithPlugins

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

the class JobDslPluginTest method should_lookup_at_jenkins_root.

/**
 * Verifies that relative job names are interpreted relative to the Jenkins root.
 * Even if the seed job is located in a folder, a new generated job is relative
 * to the Jenkins root.
 */
@Test
@WithPlugins("cloudbees-folder")
public void should_lookup_at_jenkins_root() {
    Folder folder = runSeedJobInFolder("New_Job", JobDslLookupStrategy.JENKINS_ROOT);
    FreeStyleJob newJob = getJob("New_Job");
    assertThat(newJob, pageObjectExists());
    newJob = folder.getJobs().get(FreeStyleJob.class, "New_Job");
    assertThat(newJob, pageObjectDoesNotExist());
}
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)

Example 59 with WithPlugins

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

the class JobDslPluginTest method job_filters_most_recent_3_jobs.

/**
 * This test creates 5 jobs and builds them immediately. A list view is created with its job filter set to show the
 * 3 jobs which were most recently built.
 */
@Test
@WithPlugins("view-job-filters")
public void job_filters_most_recent_3_jobs() {
    List<Job> jobs = createAmountOfJobs(5, true);
    String jobDslScript = "listView('" + LIST_VIEW_NAME + "') {\n" + "  columns {\n" + "    name()\n" + "  }\n" + "  jobs{\n" + "    names('" + jobs.get(0).name + "','" + jobs.get(1).name + "','" + jobs.get(2).name + "','" + jobs.get(3).name + "','" + jobs.get(4).name + "')\n" + "  }\n" + "  jobFilters {\n" + "    mostRecent {\n" + "      maxToInclude(3)\n" + "    }\n" + "  }\n" + "}";
    View view = openNewlyCreatedListView(jobDslScript, LIST_VIEW_NAME);
    assertThat(view, not(containsJob(jobs.get(0))));
    assertThat(view, not(containsJob(jobs.get(1))));
    assertThat(view, containsJob(jobs.get(2)));
    assertThat(view, containsJob(jobs.get(3)));
    assertThat(view, containsJob(jobs.get(4)));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Job(org.jenkinsci.test.acceptance.po.Job) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) ListView(org.jenkinsci.test.acceptance.po.ListView) View(org.jenkinsci.test.acceptance.po.View) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 60 with WithPlugins

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

the class JobDslPluginTest method job_filters_regex_name_exclude_matched.

/**
 * This test creates a listView and 4 jobs. The job filters are checking the name with a regex and
 * jobs matching the regex are excluded in the listView.
 */
@Test
@WithPlugins("view-job-filters")
public void job_filters_regex_name_exclude_matched() {
    Job job1 = createJobWithName(EXAMPLE_DISABLED_NAME);
    Job job2 = createJobWithName(EXAMPLE_ENABLED_NAME);
    List<Job> jobs = createAmountOfJobs(2, false);
    String jobDslScript = "listView('" + LIST_VIEW_NAME + "') {\n" + "  columns {\n" + "    name()\n" + "  }\n" + "  jobs{\n" + "    names('" + job1.name + "','" + job2.name + "','" + jobs.get(0).name + "','" + jobs.get(1).name + "')\n" + "  }\n" + "  jobFilters {\n" + "        regex {\n" + "            matchType(MatchType.EXCLUDE_MATCHED)\n" + "            matchValue(RegexMatchValue.NAME)\n" + "            regex('" + LIST_VIEW_REGEX + "')\n" + "        }\n" + "  }\n" + "}";
    View view = openNewlyCreatedListView(jobDslScript, LIST_VIEW_NAME);
    assertThat(view, not(containsJob(job1)));
    assertThat(view, not(containsJob(job2)));
    assertThat(view, containsJob(jobs.get(0)));
    assertThat(view, containsJob(jobs.get(1)));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Job(org.jenkinsci.test.acceptance.po.Job) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) ListView(org.jenkinsci.test.acceptance.po.ListView) View(org.jenkinsci.test.acceptance.po.View) 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