use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class BitbucketCloudScmContentProviderTest method checkScmProperties.
@Test
public void checkScmProperties() throws Exception {
// ensure cloud provider works with cloud multibranch pipeline
String credentialId = createCredential(BitbucketCloudScm.ID, authenticatedUser);
MultiBranchProject mbp = mockMbp(credentialId);
ScmContentProvider provider = new BitbucketCloudScmContentProvider();
// unfortunately overriding the apiUrl for WireMock returns a "localhost" URL here, so we mock the call
when(((BitbucketSCMSource) mbp.getSCMSources().get(0)).getServerUrl()).thenReturn(BitbucketCloudScm.API_URL);
assertTrue(provider.support(mbp));
assertEquals(provider.getScmId(), BitbucketCloudScm.ID);
assertEquals(provider.getApiUrl(mbp), BitbucketCloudScm.API_URL);
// ensure server provider doesn't work with cloud multibranch pipeline
provider = new BitbucketServerScmContentProvider();
assertFalse(provider.support(mbp));
}
use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class BitbucketCloudScmContentProviderTest method mockMbp.
private MultiBranchProject mockMbp(String credentialId, User user) {
MultiBranchProject mbp = mock(MultiBranchProject.class);
when(mbp.getName()).thenReturn("pipeline1");
when(mbp.getParent()).thenReturn(j.jenkins);
BitbucketSCMSource scmSource = mock(BitbucketSCMSource.class);
when(scmSource.getServerUrl()).thenReturn(apiUrl);
when(scmSource.getCredentialsId()).thenReturn(credentialId);
when(scmSource.getRepoOwner()).thenReturn(USER_UUID);
when(scmSource.getRepository()).thenReturn("demo1");
when(mbp.getSCMSources()).thenReturn(Collections.singletonList(scmSource));
// mock blueocean credential provider stuff
BlueOceanCredentialsProvider.FolderPropertyImpl folderProperty = mock(BlueOceanCredentialsProvider.FolderPropertyImpl.class);
DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties = new DescribableList<>(mbp);
properties.add(new BlueOceanCredentialsProvider.FolderPropertyImpl(user.getId(), credentialId, BlueOceanCredentialsProvider.createDomain(apiUrl)));
Domain domain = mock(Domain.class);
when(domain.getName()).thenReturn(BitbucketCloudScm.DOMAIN_NAME);
when(folderProperty.getDomain()).thenReturn(domain);
when(mbp.getProperties()).thenReturn(properties);
return mbp;
}
use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class BitbucketCloudScmContentProviderTest method getContent.
@Test
public void getContent() throws UnirestException, IOException {
String credentialId = createCredential(BitbucketCloudScm.ID);
StaplerRequest staplerRequest = mockStapler();
MultiBranchProject mbp = mockMbp(credentialId);
ScmFile<GitContent> content = (ScmFile<GitContent>) new BitbucketCloudScmContentProvider().getContent(staplerRequest, mbp);
assertEquals("Jenkinsfile", content.getContent().getName());
assertEquals("04553981a05754d4bffef56a59d9d996d500301c", content.getContent().getCommitId());
assertEquals("demo1", content.getContent().getRepo());
assertEquals(BbCloudWireMock.USER_UUID, content.getContent().getOwner());
}
use of jenkins.branch.MultiBranchProject 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));
}
use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class GithubIssueTest method changeSetEntry.
@Test
public void changeSetEntry() throws Exception {
MultiBranchProject project = mock(MultiBranchProject.class);
Job job = mock(MockJob.class);
Run run = mock(Run.class);
ChangeLogSet logSet = mock(ChangeLogSet.class);
ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
when(project.getProperties()).thenReturn(new DescribableList(project));
when(entry.getParent()).thenReturn(logSet);
when(logSet.getRun()).thenReturn(run);
when(run.getParent()).thenReturn(job);
when(job.getParent()).thenReturn(project);
GitHubSCMSource source = new GitHubSCMSource("foo", null, null, null, "example", "repo");
when(project.getSCMSources()).thenReturn(Collections.singletonList(source));
when(entry.getMsg()).thenReturn("Closed #123 #124");
Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
Assert.assertEquals(2, resolved.size());
Map<String, BlueIssue> issueMap = resolved.stream().collect(Collectors.toMap(BlueIssue::getId, blueIssue -> blueIssue));
BlueIssue issue123 = issueMap.get("#123");
Assert.assertEquals("https://github.com/example/repo/issues/123", issue123.getURL());
BlueIssue issue124 = issueMap.get("#124");
Assert.assertEquals("https://github.com/example/repo/issues/124", issue124.getURL());
}
Aggregations