use of jenkins.scm.api.trait.SCMSourceTrait in project blueocean-plugin by jenkinsci.
the class GithubPipelineCreateRequestTest method createPipeline.
@Test
public void createPipeline() throws UnirestException {
PowerMockito.mockStatic(GitHubWebHook.class);
GitHubWebHook gitHubWebHookMock = Mockito.spy(GitHubWebHook.class);
PowerMockito.when(GitHubWebHook.get()).thenReturn(gitHubWebHookMock);
PowerMockito.when(GitHubWebHook.getJenkinsInstance()).thenReturn(this.j.jenkins);
String credentialId = createGithubCredential(user);
Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).crumb(this.crumb).post("/organizations/jenkins/pipelines/").data(MapsHelper.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_github_pipeline.GithubPipelineCreateRequest", "scmConfig", MapsHelper.of("id", GithubScm.ID, "uri", githubApiUrl, "credentialId", credentialId, "config", MapsHelper.of("repoOwner", "cloudbeers", "repository", "PR-demo")))).build(Map.class);
assertNotNull(r);
assertEquals("pipeline1", r.get("name"));
MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
GitHubSCMSource source = (GitHubSCMSource) mbp.getSCMSources().get(0);
List<SCMSourceTrait> traits = source.getTraits();
Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
BranchDiscoveryTrait branchDiscoveryTrait = SCMTrait.find(traits, BranchDiscoveryTrait.class);
Assert.assertNotNull(branchDiscoveryTrait);
Assert.assertTrue(branchDiscoveryTrait.isBuildBranch());
Assert.assertTrue(branchDiscoveryTrait.isBuildBranchesWithPR());
ForkPullRequestDiscoveryTrait forkPullRequestDiscoveryTrait = SCMTrait.find(traits, ForkPullRequestDiscoveryTrait.class);
Assert.assertNotNull(forkPullRequestDiscoveryTrait);
Assert.assertTrue(forkPullRequestDiscoveryTrait.getTrust() instanceof ForkPullRequestDiscoveryTrait.TrustPermission);
Assert.assertEquals(1, forkPullRequestDiscoveryTrait.getStrategies().size());
Assert.assertTrue(forkPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
OriginPullRequestDiscoveryTrait originPullRequestDiscoveryTrait = SCMTrait.find(traits, OriginPullRequestDiscoveryTrait.class);
Assert.assertNotNull(originPullRequestDiscoveryTrait);
Assert.assertEquals(1, originPullRequestDiscoveryTrait.getStrategies().size());
Assert.assertTrue(originPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
Mockito.verify(gitHubWebHookMock, Mockito.times(1)).registerHookFor(mbp);
}
use of jenkins.scm.api.trait.SCMSourceTrait in project blueocean-plugin by jenkinsci.
the class GitPipelineCreateRequest method createSource.
@Override
protected SCMSource createSource(@Nonnull MultiBranchProject project, @Nonnull BlueScmConfig scmConfig) {
GitSCMSource gitSource = new GitSCMSource(StringUtils.defaultString(scmConfig.getUri()));
gitSource.setCredentialsId(computeCredentialId(scmConfig));
List<SCMSourceTrait> traits = gitSource.getTraits();
traits.add(new BranchDiscoveryTrait());
traits.add(new CleanBeforeCheckoutTrait());
traits.add(new CleanAfterCheckoutTrait());
traits.add(new LocalBranchTrait());
return gitSource;
}
use of jenkins.scm.api.trait.SCMSourceTrait in project blueocean-plugin by jenkinsci.
the class GitPipelineCreateRequestTest method createPipeline.
@Test
public void createPipeline() throws UnirestException, IOException {
User user = login("vivek", "Vivek Pandey", "vivek.pandey@gmail.com");
Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).crumb(crumb).post("/organizations/jenkins/pipelines/").data(MapsHelper.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", MapsHelper.of("id", GitScm.ID, "uri", sampleRepo.toString()))).build(Map.class);
assertNotNull(r);
assertEquals("pipeline1", r.get("name"));
MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
GitSCMSource source = (GitSCMSource) mbp.getSCMSources().get(0);
List<SCMSourceTrait> traits = source.getTraits();
Assert.assertNotNull(SCMTrait.find(traits, BranchDiscoveryTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
}
use of jenkins.scm.api.trait.SCMSourceTrait in project blueocean-plugin by jenkinsci.
the class BitbucketPipelineCreateRequestTest method createdWithTraits.
@Test
public void createdWithTraits() throws Exception {
String credentialId = createCredential(BitbucketServerScm.ID);
Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, authenticatedUser.getId(), authenticatedUser.getId())).crumb(crumb).post("/organizations/jenkins/pipelines/").data(MapsHelper.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketPipelineCreateRequest", "scmConfig", MapsHelper.of("id", BitbucketServerScm.ID, "credentialId", credentialId, "uri", apiUrl, "config", MapsHelper.of("repoOwner", "TESTP", "repository", "pipeline-demo-test")))).build(Map.class);
assertNotNull(r);
assertEquals("pipeline1", r.get("name"));
MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
BitbucketSCMSource source = (BitbucketSCMSource) mbp.getSCMSources().get(0);
List<SCMSourceTrait> traits = source.getTraits();
Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
BranchDiscoveryTrait branchDiscoveryTrait = SCMTrait.find(traits, BranchDiscoveryTrait.class);
Assert.assertNotNull(branchDiscoveryTrait);
Assert.assertTrue(branchDiscoveryTrait.isBuildBranch());
Assert.assertTrue(branchDiscoveryTrait.isBuildBranchesWithPR());
ForkPullRequestDiscoveryTrait forkPullRequestDiscoveryTrait = SCMTrait.find(traits, ForkPullRequestDiscoveryTrait.class);
Assert.assertNotNull(forkPullRequestDiscoveryTrait);
Assert.assertTrue(forkPullRequestDiscoveryTrait.getTrust() instanceof ForkPullRequestDiscoveryTrait.TrustTeamForks);
Assert.assertEquals(1, forkPullRequestDiscoveryTrait.getStrategies().size());
Assert.assertTrue(forkPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
OriginPullRequestDiscoveryTrait originPullRequestDiscoveryTrait = SCMTrait.find(traits, OriginPullRequestDiscoveryTrait.class);
Assert.assertNotNull(originPullRequestDiscoveryTrait);
Assert.assertEquals(1, originPullRequestDiscoveryTrait.getStrategies().size());
Assert.assertTrue(originPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
}
Aggregations