Search in sources :

Example 6 with JiraSite

use of hudson.plugins.jira.JiraSite in project blueocean-plugin by jenkinsci.

the class BlueJiraIssueTest method issuesForJob.

@Test
public void issuesForJob() throws Exception {
    Job job = mock(Job.class);
    mockStatic(JiraSite.class);
    JiraSite site = mock(JiraSite.class);
    when(JiraSite.get(job)).thenReturn(site);
    // Should resolve no issues because there is no JiraJobAction
    Assert.assertTrue(BlueIssueFactory.resolve(job).isEmpty());
    // Setup a job with a JiraJobAction
    JiraIssue jiraIssue = new JiraIssue("FOO-123", "A cool issue");
    when(site.getUrl(jiraIssue)).thenReturn(new URL("http://jira.example.com/browse/FOO-123"));
    JiraJobAction action = new JiraJobAction(job, jiraIssue);
    when(job.getAction(JiraJobAction.class)).thenReturn(action);
    // Expect a single issue
    Collection<BlueIssue> issues = BlueIssueFactory.resolve(job);
    Assert.assertEquals(1, issues.size());
    BlueIssue issue = issues.iterator().next();
    Assert.assertEquals("FOO-123", issue.getId());
    Assert.assertEquals("http://jira.example.com/browse/FOO-123", issue.getURL());
}
Also used : JiraIssue(hudson.plugins.jira.model.JiraIssue) Job(hudson.model.Job) JiraJobAction(hudson.plugins.jira.JiraJobAction) 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 7 with JiraSite

use of hudson.plugins.jira.JiraSite in project blueocean-plugin by jenkinsci.

the class BlueJiraIssueTest method issuesForJobNoAction.

@Test
public void issuesForJobNoAction() throws Exception {
    Job job = mock(Job.class);
    mockStatic(JiraSite.class);
    JiraSite site = mock(JiraSite.class);
    when(JiraSite.get(job)).thenReturn(site);
    when(job.getAction(JiraJobAction.class)).thenReturn(null);
    // Should resolve no issues because there is no JiraJobAction
    Assert.assertTrue(BlueIssueFactory.resolve(job).isEmpty());
}
Also used : Job(hudson.model.Job) JiraSite(hudson.plugins.jira.JiraSite) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with JiraSite

use of hudson.plugins.jira.JiraSite in project blueocean-plugin by jenkinsci.

the class JiraSCMListenerTest method onChangeLogParsedCreatesAction.

@Test
public void onChangeLogParsedCreatesAction() throws Exception {
    JiraSCMListener listener = new JiraSCMListener();
    Job job = mock(Job.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    final ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(entry.getMsg()).thenReturn("TEST-123");
    ChangeLogSet<ChangeLogSet.Entry> set = new ChangeLogSet<ChangeLogSet.Entry>(run, null) {

        @Override
        public boolean isEmptySet() {
            return false;
        }

        @Override
        public Iterator<Entry> iterator() {
            return ImmutableSet.of(entry).iterator();
        }
    };
    // Setup JIRA site
    mockStatic(JiraSite.class);
    JiraSite site = mock(JiraSite.class);
    JiraSession session = mock(JiraSession.class);
    when(site.getIssuePattern()).thenReturn(JiraSite.DEFAULT_ISSUE_PATTERN);
    when(site.getSession()).thenReturn(session);
    when(JiraSite.get(job)).thenReturn(site);
    Issue rawIssue = mock(Issue.class);
    when(rawIssue.getKey()).thenReturn("TEST-123");
    when(rawIssue.getSummary()).thenReturn("Foo");
    when(session.getIssuesFromJqlSearch("key in ('TEST-123')")).thenReturn(Lists.newArrayList(rawIssue));
    when(run.getAction(JiraBuildAction.class)).thenReturn(null);
    ArgumentCaptor<JiraBuildAction> actionArgumentCaptor = ArgumentCaptor.forClass(JiraBuildAction.class);
    listener.onChangeLogParsed(run, null, null, set);
    verify(run).addAction(actionArgumentCaptor.capture());
    JiraBuildAction action = actionArgumentCaptor.getValue();
    Assert.assertFalse(action.getIssues().isEmpty());
    JiraIssue issue = action.getIssue("TEST-123");
    Assert.assertNotNull(issue);
    Assert.assertEquals("TEST-123", issue.getKey());
}
Also used : JiraIssue(hudson.plugins.jira.model.JiraIssue) ChangeLogSet(hudson.scm.ChangeLogSet) Issue(com.atlassian.jira.rest.client.api.domain.Issue) JiraIssue(hudson.plugins.jira.model.JiraIssue) JiraSession(hudson.plugins.jira.JiraSession) Run(hudson.model.Run) JiraBuildAction(hudson.plugins.jira.JiraBuildAction) Job(hudson.model.Job) JiraSite(hudson.plugins.jira.JiraSite) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

JiraSite (hudson.plugins.jira.JiraSite)8 Job (hudson.model.Job)7 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 JiraBuildAction (hudson.plugins.jira.JiraBuildAction)5 JiraIssue (hudson.plugins.jira.model.JiraIssue)5 ChangeLogSet (hudson.scm.ChangeLogSet)5 Run (hudson.model.Run)4 Issue (com.atlassian.jira.rest.client.api.domain.Issue)3 JiraSession (hudson.plugins.jira.JiraSession)3 JiraJobAction (hudson.plugins.jira.JiraJobAction)2 BlueIssue (io.jenkins.blueocean.rest.model.BlueIssue)2 URL (java.net.URL)2 Function (com.google.common.base.Function)1