Search in sources :

Example 41 with MultiBranchProject

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));
}
Also used : BitbucketServerScmContentProvider(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.BitbucketServerScmContentProvider) ScmContentProvider(io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider) MultiBranchProject(jenkins.branch.MultiBranchProject) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) BitbucketServerScmContentProvider(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.BitbucketServerScmContentProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 42 with MultiBranchProject

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;
}
Also used : BlueOceanCredentialsProvider(io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanCredentialsProvider) DescribableList(hudson.util.DescribableList) MultiBranchProject(jenkins.branch.MultiBranchProject) AbstractFolderPropertyDescriptor(com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor) Domain(com.cloudbees.plugins.credentials.domains.Domain) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) AbstractFolderProperty(com.cloudbees.hudson.plugins.folder.AbstractFolderProperty)

Example 43 with MultiBranchProject

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());
}
Also used : StaplerRequest(org.kohsuke.stapler.StaplerRequest) MultiBranchProject(jenkins.branch.MultiBranchProject) GitContent(io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent) ScmFile(io.jenkins.blueocean.rest.impl.pipeline.scm.ScmFile) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with MultiBranchProject

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));
}
Also used : OriginPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) ForkPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) SCMSourceTrait(jenkins.scm.api.trait.SCMSourceTrait) MultiBranchProject(jenkins.branch.MultiBranchProject) Map(java.util.Map) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 45 with MultiBranchProject

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());
}
Also used : GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) Arrays(java.util.Arrays) MultiBranchProject(jenkins.branch.MultiBranchProject) ChangeLogSet(hudson.scm.ChangeLogSet) BlueIssueFactory(io.jenkins.blueocean.rest.factory.BlueIssueFactory) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) Map(java.util.Map) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Nonnull(javax.annotation.Nonnull) DescribableList(hudson.util.DescribableList) Collection(java.util.Collection) AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) ItemGroup(hudson.model.ItemGroup) Run(hudson.model.Run) Rule(org.junit.Rule) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Job(hudson.model.Job) Assert(org.junit.Assert) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Collections(java.util.Collections) GitSCMSource(jenkins.plugins.git.GitSCMSource) Mockito.mock(org.mockito.Mockito.mock) ChangeLogSet(hudson.scm.ChangeLogSet) DescribableList(hudson.util.DescribableList) MultiBranchProject(jenkins.branch.MultiBranchProject) Run(hudson.model.Run) GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) Job(hudson.model.Job) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Test(org.junit.Test)

Aggregations

MultiBranchProject (jenkins.branch.MultiBranchProject)52 Test (org.junit.Test)36 StaplerRequest (org.kohsuke.stapler.StaplerRequest)28 GitContent (io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent)18 BufferedReader (java.io.BufferedReader)16 StringReader (java.io.StringReader)16 JSONObject (net.sf.json.JSONObject)16 ServiceException (io.jenkins.blueocean.commons.ServiceException)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 User (hudson.model.User)13 Mailer (hudson.tasks.Mailer)12 BitbucketScmSaveFileRequest (io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketScmSaveFileRequest)6 Job (hudson.model.Job)5 DescribableList (hudson.util.DescribableList)5 ScmFile (io.jenkins.blueocean.rest.impl.pipeline.scm.ScmFile)5 Map (java.util.Map)5 GitSCMSource (jenkins.plugins.git.GitSCMSource)5 GitHubSCMSource (org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)5 BitbucketSCMSource (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource)4 Item (hudson.model.Item)4