Search in sources :

Example 16 with JobTemplate

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());
}
Also used : JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate) Job(com.offbytwo.jenkins.model.Job) Test(org.junit.Test)

Example 17 with JobTemplate

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"));
}
Also used : HashMap(java.util.HashMap) JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate) Job(com.offbytwo.jenkins.model.Job) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 18 with JobTemplate

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());
}
Also used : JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate) Test(org.junit.Test)

Example 19 with JobTemplate

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());
    }
}
Also used : JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate) Test(org.junit.Test)

Example 20 with JobTemplate

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;
}
Also used : JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate) JobMapping(com.palantir.stash.stashbot.persistence.JobMapping)

Aggregations

JobTemplate (com.palantir.stash.stashbot.persistence.JobTemplate)21 Test (org.junit.Test)9 Job (com.offbytwo.jenkins.model.Job)6 RepositoryConfiguration (com.palantir.stash.stashbot.persistence.RepositoryConfiguration)5 JenkinsServerConfiguration (com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration)4 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 DBParam (net.java.ao.DBParam)4 PullRequest (com.atlassian.stash.pull.PullRequest)2 Repository (com.atlassian.stash.repository.Repository)2 JenkinsServer (com.offbytwo.jenkins.JenkinsServer)2 JobMapping (com.palantir.stash.stashbot.persistence.JobMapping)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ServletException (javax.servlet.ServletException)2 HttpResponseException (org.apache.http.client.HttpResponseException)2 BuildStatus (com.atlassian.stash.build.BuildStatus)1 State (com.atlassian.stash.build.BuildStatus.State)1 InternalBuildStatus (com.atlassian.stash.internal.build.InternalBuildStatus)1