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)));
}
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));
}
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();
}
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']")));
}
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());
}
Aggregations