use of com.atlassian.stash.util.Operation 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);
}
use of com.atlassian.stash.util.Operation in project stashbot by palantir.
the class JenkinsManager method triggerBuild.
public void triggerBuild(final Repository repo, final JobType jobType, final PullRequest pr) {
final String username = um.getRemoteUser().getUsername();
final StashUser su = us.findUserByNameOrEmail(username);
es.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
// TODO: See if we can do something like StateTransferringExecutorService here instead
ss.impersonating(su, "Running as user '" + username + "' in alternate thread asynchronously").call(new Operation<Void, Exception>() {
@Override
public Void perform() throws Exception {
synchronousTriggerBuild(repo, jobType, pr);
return null;
}
});
return null;
}
;
});
}
use of com.atlassian.stash.util.Operation in project stashbot by palantir.
the class JenkinsManager method triggerBuild.
public void triggerBuild(final Repository repo, final JobType jobType, final String hashToBuild, final String buildRef) {
final String username = um.getRemoteUser().getUsername();
final StashUser su = us.findUserByNameOrEmail(username);
es.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
// TODO: See if we can do something like StateTransferringExecutorService here instead
ss.impersonating(su, "Running as user '" + username + "' in alternate thread asynchronously").call(new Operation<Void, Exception>() {
@Override
public Void perform() throws Exception {
synchronousTriggerBuild(repo, jobType, hashToBuild, buildRef);
return null;
}
});
return null;
}
;
});
}
Aggregations