Search in sources :

Example 1 with MockJobTemplateFactory

use of com.palantir.stash.stashbot.mocks.MockJobTemplateFactory in project stashbot by palantir.

the class BuildSuccessReportingServletTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Throwable {
    MockitoAnnotations.initMocks(this);
    Mockito.when(cpm.getJenkinsServerConfiguration(Mockito.anyString())).thenReturn(jsc);
    Mockito.when(cpm.getRepositoryConfigurationForRepository(Mockito.any(Repository.class))).thenReturn(rc);
    Mockito.when(jsc.getUrl()).thenReturn(ABSOLUTE_URL);
    Mockito.when(cpm.getPullRequestMetadata(pr)).thenReturn(prm);
    Mockito.when(repositoryService.getById(REPO_ID)).thenReturn(repo);
    Mockito.when(prs.getById(REPO_ID, PULL_REQUEST_ID)).thenReturn(pr);
    Mockito.when(pr.getId()).thenReturn(PULL_REQUEST_ID);
    Mockito.when(pr.getToRef()).thenReturn(toRef);
    Mockito.when(toRef.getRepository()).thenReturn(repo);
    Mockito.when(repo.getId()).thenReturn(REPO_ID);
    Mockito.when(repo.getSlug()).thenReturn("slug");
    Mockito.when(repo.getProject()).thenReturn(proj);
    Mockito.when(proj.getKey()).thenReturn("projectKey");
    Mockito.when(ub.getJenkinsTriggerUrl(Mockito.any(Repository.class), Mockito.any(JobType.class), Mockito.anyString(), Mockito.any(PullRequest.class))).thenReturn(ABSOLUTE_URL);
    Mockito.when(ss.impersonating(Mockito.any(StashUser.class), Mockito.anyString())).thenReturn(esc);
    Mockito.when(ss.withPermission(Mockito.any(Permission.class), Mockito.anyString())).thenReturn(esc);
    jtf = new MockJobTemplateFactory(jtm);
    jtf.generateDefaultsForRepo(repo, rc);
    // Let's use the actual operation classes here for test coverage
    Answer<Void> frobber = new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Operation<Void, Exception> op = (Operation<Void, Exception>) invocation.getArguments()[0];
            op.perform();
            return null;
        }
    };
    Mockito.when(esc.call(Mockito.<Operation<Void, Exception>>any())).thenAnswer(frobber);
    mockWriter = new StringWriter();
    Mockito.when(res.getWriter()).thenReturn(new PrintWriter(mockWriter));
    bsrs = new BuildSuccessReportingServlet(cpm, repositoryService, bss, prs, ub, jtm, ss, us, lf);
}
Also used : BuildSuccessReportingServlet(com.palantir.stash.stashbot.servlet.BuildSuccessReportingServlet) PullRequest(com.atlassian.stash.pull.PullRequest) Operation(com.atlassian.stash.util.Operation) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Answer(org.mockito.stubbing.Answer) Repository(com.atlassian.stash.repository.Repository) MockJobTemplateFactory(com.palantir.stash.stashbot.mocks.MockJobTemplateFactory) JobType(com.palantir.stash.stashbot.jobtemplate.JobType) StashUser(com.atlassian.stash.user.StashUser) StringWriter(java.io.StringWriter) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Permission(com.atlassian.stash.user.Permission) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 2 with MockJobTemplateFactory

use of com.palantir.stash.stashbot.mocks.MockJobTemplateFactory in project stashbot by palantir.

the class BuildTriggerServletTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    verifyCommitType = JobType.VERIFY_COMMIT;
    verifyPRType = JobType.VERIFY_PR;
    publishType = JobType.PUBLISH;
    Mockito.when(repositoryService.getById(REPO_ID)).thenReturn(repo);
    Mockito.when(prs.getById(REPO_ID, PULL_REQUEST_ID)).thenReturn(pr);
    Mockito.when(pr.getId()).thenReturn(PULL_REQUEST_ID);
    Mockito.when(repo.getId()).thenReturn(REPO_ID);
    Mockito.when(cpm.getRepositoryConfigurationForRepository(repo)).thenReturn(rc);
    Mockito.when(jt1.getJobType()).thenReturn(verifyCommitType);
    Mockito.when(jt2.getJobType()).thenReturn(verifyPRType);
    Mockito.when(jt3.getJobType()).thenReturn(publishType);
    Mockito.when(jtm.getJenkinsJobsForRepository(rc)).thenReturn(ImmutableList.of(jt1, jt2, jt3));
    Mockito.when(jtm.fromString(rc, verifyCommitType.toString())).thenReturn(jt1);
    Mockito.when(jtm.fromString(rc, verifyPRType.toString())).thenReturn(jt2);
    Mockito.when(jtm.fromString(rc, publishType.toString())).thenReturn(jt3);
    mockWriter = new StringWriter();
    Mockito.when(res.getWriter()).thenReturn(new PrintWriter(mockWriter));
    jtf = new MockJobTemplateFactory(jtm);
    jtf.generateDefaultsForRepo(repo, rc);
    bsrs = new BuildTriggerServlet(repositoryService, prs, jtm, cpm, jenkinsManager, lf);
}
Also used : MockJobTemplateFactory(com.palantir.stash.stashbot.mocks.MockJobTemplateFactory) StringWriter(java.io.StringWriter) BuildTriggerServlet(com.palantir.stash.stashbot.servlet.BuildTriggerServlet) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 3 with MockJobTemplateFactory

use of com.palantir.stash.stashbot.mocks.MockJobTemplateFactory in project stashbot by palantir.

the class JenkinsManagerTest method setUp.

@Before
public void setUp() throws Throwable {
    MockitoAnnotations.initMocks(this);
    Mockito.when(jenkinsClientManager.getJenkinsServer(Mockito.any(JenkinsServerConfiguration.class), Mockito.any(RepositoryConfiguration.class))).thenReturn(jenkinsServer);
    jtf = new MockJobTemplateFactory(jtm);
    jtf.generateDefaultsForRepo(repo, rc);
    Mockito.when(xmlFormatter.generateJobXml(Mockito.any(JobTemplate.class), Mockito.eq(repo))).thenReturn(XML_STRING);
    Mockito.when(cpm.getJenkinsServerConfiguration(Mockito.anyString())).thenReturn(jsc);
    Mockito.when(cpm.getRepositoryConfigurationForRepository(repo)).thenReturn(rc);
    Mockito.when(jsc.getStashUsername()).thenReturn("stash_username");
    Mockito.when(jsc.getStashPassword()).thenReturn("stash_password");
    Mockito.when(jsc.getPassword()).thenReturn("jenkins_password");
    Mockito.when(repo.getName()).thenReturn("somename");
    Mockito.when(repo.getSlug()).thenReturn("slug");
    Mockito.when(repo.getProject()).thenReturn(proj);
    Mockito.when(proj.getKey()).thenReturn("project_key");
    Mockito.when(um.getRemoteUser()).thenReturn(up);
    Mockito.when(up.getUsername()).thenReturn("someuser");
    Mockito.when(us.getUserByName(Mockito.anyString())).thenReturn(su);
    mssb = new MockSecurityServiceBuilder();
    ss = mssb.getSecurityService();
    jenkinsManager = new JenkinsManager(repositoryService, cpm, jtm, xmlFormatter, jenkinsClientManager, sub, lf, ss, us, um);
}
Also used : MockJobTemplateFactory(com.palantir.stash.stashbot.mocks.MockJobTemplateFactory) MockSecurityServiceBuilder(com.palantir.stash.stashbot.mocks.MockSecurityServiceBuilder) JenkinsServerConfiguration(com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration) RepositoryConfiguration(com.palantir.stash.stashbot.persistence.RepositoryConfiguration) JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate) Before(org.junit.Before)

Aggregations

MockJobTemplateFactory (com.palantir.stash.stashbot.mocks.MockJobTemplateFactory)3 Before (org.junit.Before)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 PullRequest (com.atlassian.stash.pull.PullRequest)1 Repository (com.atlassian.stash.repository.Repository)1 Permission (com.atlassian.stash.user.Permission)1 StashUser (com.atlassian.stash.user.StashUser)1 Operation (com.atlassian.stash.util.Operation)1 JobType (com.palantir.stash.stashbot.jobtemplate.JobType)1 MockSecurityServiceBuilder (com.palantir.stash.stashbot.mocks.MockSecurityServiceBuilder)1 JenkinsServerConfiguration (com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration)1 JobTemplate (com.palantir.stash.stashbot.persistence.JobTemplate)1 RepositoryConfiguration (com.palantir.stash.stashbot.persistence.RepositoryConfiguration)1 BuildSuccessReportingServlet (com.palantir.stash.stashbot.servlet.BuildSuccessReportingServlet)1 BuildTriggerServlet (com.palantir.stash.stashbot.servlet.BuildTriggerServlet)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1