use of com.palantir.stash.stashbot.persistence.JobTemplate in project stashbot by palantir.
the class JenkinsManagerTest method testPreserveJenkinsJobConfigEnabled.
@Test
public void testPreserveJenkinsJobConfigEnabled() throws IOException {
JobTemplate jt = jtm.getDefaultVerifyJob();
HashMap<String, Job> jobs = Maps.newHashMap();
// update job logic requires the job be there already
jobs.put(jt.getBuildNameFor(repo), new Job());
Mockito.when(rc.getPreserveJenkinsJobConfig()).thenReturn(true);
Mockito.when(jenkinsServer.getJobs()).thenReturn(jobs);
jenkinsManager.updateJob(repo, jt);
Mockito.verify(jenkinsServer, Mockito.never()).updateJob(Mockito.anyString(), Mockito.anyString());
}
use of com.palantir.stash.stashbot.persistence.JobTemplate in project stashbot by palantir.
the class JenkinsManagerTest method testTriggerBuildShort.
@Test
public void testTriggerBuildShort() throws Exception {
String HASH = "38356e8abe0e96538dd1007278ecc02c3bf3d2cb";
String REF = "refs/heads/master";
JobTemplate jt = jtm.getDefaultVerifyJob();
String jobName = jt.getBuildNameFor(repo);
Job existingJob = Mockito.mock(Job.class);
Mockito.when(existingJob.getName()).thenReturn(jobName);
Map<String, Job> jobMap = new HashMap<String, Job>();
jobMap.put(jobName, existingJob);
Mockito.when(jenkinsServer.getJobs()).thenReturn(jobMap);
Mockito.when(jtm.getJobTemplate(JobType.VERIFY_COMMIT, rc)).thenReturn(jt);
jenkinsManager.triggerBuild(repo, JobType.VERIFY_COMMIT, HASH, REF);
jenkinsManager.destroy();
@SuppressWarnings({ "unchecked", "rawtypes" }) Class<Map<String, String>> forClass = (Class) Map.class;
ArgumentCaptor<Map<String, String>> paramCaptor = ArgumentCaptor.forClass(forClass);
Mockito.verify(existingJob).build(paramCaptor.capture());
Map<String, String> paramMap = paramCaptor.getValue();
Assert.assertTrue(paramMap.containsKey("buildHead"));
Assert.assertTrue(paramMap.containsKey("buildRef"));
Assert.assertTrue(paramMap.containsKey("repoId"));
Assert.assertFalse(paramMap.containsKey("pullRequestId"));
Assert.assertFalse(paramMap.containsKey("mergeHead"));
}
use of com.palantir.stash.stashbot.persistence.JobTemplate in project stashbot by palantir.
the class JenkinsManagerTest method testCreateJob.
@Test
public void testCreateJob() throws Exception {
JobTemplate jt = jtm.getDefaultVerifyJob();
jenkinsManager.createJob(repo, jt);
ArgumentCaptor<String> xmlCaptor = ArgumentCaptor.forClass(String.class);
Mockito.verify(xmlFormatter).generateJobXml(jt, repo);
Mockito.verify(jenkinsServer).createJob(Mockito.anyString(), xmlCaptor.capture());
Assert.assertEquals(XML_STRING, xmlCaptor.getValue());
}
use of com.palantir.stash.stashbot.persistence.JobTemplate in project stashbot by palantir.
the class JenkinsManagerTest method testUpdateRepoCIEnabled.
@Test
public void testUpdateRepoCIEnabled() throws IOException {
Mockito.when(rc.getCiEnabled()).thenReturn(true);
jenkinsManager.updateRepo(repo);
List<JobTemplate> templates = jtf.getMockTemplates();
for (JobTemplate t : templates) {
Mockito.verify(jenkinsServer).createJob(Mockito.eq(t.getBuildNameFor(repo)), Mockito.anyString());
}
}
use of com.palantir.stash.stashbot.persistence.JobTemplate in project stashbot by palantir.
the class MockJobTemplateFactory method getJobTemplate.
public JobTemplate getJobTemplate(Repository repo, RepositoryConfiguration rc, JobType jt) throws Exception {
JobTemplate template = Mockito.mock(JobTemplate.class);
Mockito.when(template.getJobType()).thenReturn(jt);
Mockito.when(template.getName()).thenReturn(jt.toString());
Mockito.when(template.getBuildNameFor(repo)).thenReturn("somename_" + jt.toString());
Mockito.when(template.getTemplateFile()).thenReturn("src/test/resources/test-template.vm");
JobMapping jm = Mockito.mock(JobMapping.class);
Mockito.when(jm.getRepositoryConfiguration()).thenReturn(rc);
Mockito.when(jm.getJobTemplate()).thenReturn(template);
Mockito.when(jm.isVisible()).thenReturn(true);
Mockito.when(jm.isEnabled()).thenReturn(true);
Mockito.when(jtm.getJenkinsJobsForRepository(rc)).thenReturn(ImmutableList.copyOf(templates));
Mockito.when(jtm.fromString(rc, jt.toString())).thenReturn(template);
templates.add(template);
mappings.add(jm);
return template;
}
Aggregations