Search in sources :

Example 1 with BlueIssue

use of io.jenkins.blueocean.rest.model.BlueIssue in project blueocean-plugin by jenkinsci.

the class GithubIssueTest method changeSetEntryIsNotGithub.

@Test
public void changeSetEntryIsNotGithub() throws Exception {
    MultiBranchProject project = mock(MultiBranchProject.class);
    Job job = mock(Job.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);
    when(entry.getMsg()).thenReturn("Closed #123 #124");
    when(project.getSCMSources()).thenReturn(Lists.newArrayList(new GitSCMSource("http://example.com/repo.git")));
    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(0, resolved.size());
}
Also used : ChangeLogSet(hudson.scm.ChangeLogSet) DescribableList(hudson.util.DescribableList) MultiBranchProject(jenkins.branch.MultiBranchProject) Run(hudson.model.Run) GitSCMSource(jenkins.plugins.git.GitSCMSource) Job(hudson.model.Job) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Test(org.junit.Test)

Example 2 with BlueIssue

use of io.jenkins.blueocean.rest.model.BlueIssue in project blueocean-plugin by jenkinsci.

the class BlueJiraIssueTest method issuesForChangeSetItem.

@Test
public void issuesForChangeSetItem() throws Exception {
    Job job = mock(Job.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    mockStatic(JiraSite.class);
    JiraSite site = mock(JiraSite.class);
    when(site.getIssuePattern()).thenReturn(JiraSite.DEFAULT_ISSUE_PATTERN);
    when(JiraSite.get(job)).thenReturn(site);
    when(entry.getMsg()).thenReturn("TEST-123");
    // Should resolve no issues because there is no JiraJobAction
    Assert.assertTrue(BlueIssueFactory.resolve(entry).isEmpty());
    // Setup a job with a JiraJobAction
    JiraIssue jiraIssue1 = new JiraIssue("FOO-123", "A cool issue");
    JiraIssue jiraIssue2 = new JiraIssue("FOO-124", "A cool issue");
    when(site.getUrl(jiraIssue1)).thenReturn(new URL("http://jira.example.com/browse/FOO-123"));
    when(site.getUrl(jiraIssue2)).thenReturn(new URL("http://jira.example.com/browse/FOO-124"));
    JiraBuildAction action = new JiraBuildAction(run, Sets.newLinkedHashSet(ImmutableSet.of(jiraIssue1, jiraIssue2)));
    when(run.getAction(JiraBuildAction.class)).thenReturn(action);
    // Expect two issues
    when(entry.getMsg()).thenReturn("something FOO-123 vivek FOO-124 #ace");
    List<BlueIssue> issues = Lists.newLinkedList(BlueIssueFactory.resolve(entry));
    Assert.assertEquals(2, issues.size());
    BlueIssue issue1 = issues.get(0);
    Assert.assertEquals("FOO-123", issue1.getId());
    Assert.assertEquals("http://jira.example.com/browse/FOO-123", issue1.getURL());
    BlueIssue issue2 = issues.get(1);
    Assert.assertEquals("FOO-124", issue2.getId());
    Assert.assertEquals("http://jira.example.com/browse/FOO-124", issue2.getURL());
}
Also used : JiraIssue(hudson.plugins.jira.model.JiraIssue) JiraBuildAction(hudson.plugins.jira.JiraBuildAction) ChangeLogSet(hudson.scm.ChangeLogSet) Run(hudson.model.Run) Job(hudson.model.Job) JiraSite(hudson.plugins.jira.JiraSite) URL(java.net.URL) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with BlueIssue

use of io.jenkins.blueocean.rest.model.BlueIssue in project blueocean-plugin by jenkinsci.

the class GithubIssueTest method jobNotImplemented.

@Test
public void jobNotImplemented() throws Exception {
    Job job = mock(Job.class);
    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(job);
    Assert.assertTrue(resolved.isEmpty());
}
Also used : Job(hudson.model.Job) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Test(org.junit.Test)

Example 4 with BlueIssue

use of io.jenkins.blueocean.rest.model.BlueIssue in project blueocean-plugin by jenkinsci.

the class GithubIssueTest method changeSetJobParentNotMultibranch.

@Test
public void changeSetJobParentNotMultibranch() throws Exception {
    AbstractFolder project = mock(AbstractFolder.class);
    Job job = mock(Job.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);
    when(entry.getMsg()).thenReturn("Closed #123 #124");
    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(0, resolved.size());
}
Also used : AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) ChangeLogSet(hudson.scm.ChangeLogSet) DescribableList(hudson.util.DescribableList) Run(hudson.model.Run) Job(hudson.model.Job) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Test(org.junit.Test)

Example 5 with BlueIssue

use of io.jenkins.blueocean.rest.model.BlueIssue 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(Job.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(Lists.newArrayList(source));
    when(entry.getMsg()).thenReturn("Closed #123 #124");
    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(2, resolved.size());
    Map<String, BlueIssue> issueMap = Maps.uniqueIndex(resolved, new Function<BlueIssue, String>() {

        @Override
        public String apply(BlueIssue input) {
            return input.getId();
        }
    });
    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 : ChangeLogSet(hudson.scm.ChangeLogSet) DescribableList(hudson.util.DescribableList) Run(hudson.model.Run) GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) MultiBranchProject(jenkins.branch.MultiBranchProject) Job(hudson.model.Job) Test(org.junit.Test)

Aggregations

Job (hudson.model.Job)6 BlueIssue (io.jenkins.blueocean.rest.model.BlueIssue)6 Test (org.junit.Test)6 Run (hudson.model.Run)4 ChangeLogSet (hudson.scm.ChangeLogSet)4 DescribableList (hudson.util.DescribableList)3 JiraSite (hudson.plugins.jira.JiraSite)2 JiraIssue (hudson.plugins.jira.model.JiraIssue)2 URL (java.net.URL)2 MultiBranchProject (jenkins.branch.MultiBranchProject)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)1 JiraBuildAction (hudson.plugins.jira.JiraBuildAction)1 JiraJobAction (hudson.plugins.jira.JiraJobAction)1 GitSCMSource (jenkins.plugins.git.GitSCMSource)1 GitHubSCMSource (org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)1