Пример #1
0
  @Test
  public void shouldCollectIssuesByPriority() throws Exception {
    Filter filter = new Filter(null, 1l, null, null, null, null, null, null, false);
    JiraSoapService jiraSoapService = mock(JiraSoapService.class);

    JiraSoapSession soapSession = mock(JiraSoapSession.class);
    when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService);

    JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings);
    when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any()))
        .thenReturn(wrapper);

    RemoteIssue issue1 = new RemoteIssue();
    issue1.setPriority("1");
    issue1.setId("1");
    RemoteIssue issue2 = new RemoteIssue();
    issue2.setPriority("1");
    issue2.setId("2");
    RemoteIssue issue3 = new RemoteIssue();
    issue3.setPriority("2");
    issue3.setId("3");
    when(jiraSoapService.getIssuesFromFilter("token", "1"))
        .thenReturn(new RemoteIssue[] {issue1, issue2, issue3});

    Map<Long, Integer> foundIssues = sensor.collectIssuesByPriority(wrapper, "token", filter);
    assertThat(foundIssues.size()).isEqualTo(2);
    assertThat(foundIssues.get(1l)).isEqualTo(2);
    assertThat(foundIssues.get(2l)).isEqualTo(1);
  }
Пример #2
0
  @Test
  public void faillIfNoFilterFound() throws Exception {
    JiraSoapService jiraSoapService = mock(JiraSoapService.class);

    JiraSoapSession soapSession = mock(JiraSoapSession.class);
    when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService);

    JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings);
    when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any()))
        .thenReturn(wrapper);

    when(jiraSoapService.getFavouriteFilters("token")).thenReturn(new RemoteFilter[0]);

    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Unable to find filter 'myFilter' in JIRA");

    sensor.findJiraFilter(wrapper, "token");
  }
Пример #3
0
  @Test
  public void shouldCollectPriorities() throws Exception {
    JiraSoapService jiraSoapService = mock(JiraSoapService.class);
    RemotePriority priority1 = new RemotePriority();
    priority1.setId("1");
    priority1.setName("Minor");
    when(jiraSoapService.getPriorities("token")).thenReturn(new RemotePriority[] {priority1});

    JiraSoapSession soapSession = mock(JiraSoapSession.class);
    when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService);

    JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings);
    when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any()))
        .thenReturn(wrapper);

    Map<Long, String> foundPriorities = sensor.collectPriorities(wrapper, "token");
    assertThat(foundPriorities.size()).isEqualTo(1);
    assertThat(foundPriorities.get(1l)).isEqualTo("Minor");
  }
  @Test
  public void shouldCreateIssue() throws Exception {
    // Given that
    RemoteIssue issue = new RemoteIssue();
    JiraSoapService jiraSoapService = mock(JiraSoapService.class);
    when(jiraSoapService.createIssue(anyString(), any(RemoteIssue.class))).thenReturn(issue);

    JiraSoapSession soapSession = mock(JiraSoapSession.class);
    when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService);

    // Verify
    RemoteIssue returnedIssue =
        jiraIssueCreator.doCreateIssue(sonarIssue, soapSession, settings, "");

    verify(soapSession).connect("foo", "bar");
    verify(soapSession).getJiraSoapService();
    verify(soapSession).getAuthenticationToken();

    assertThat(returnedIssue).isEqualTo(issue);
  }
Пример #5
0
  @Test
  public void shouldFindFiltersWithPreviousJiraVersions() throws Exception {
    JiraSoapService jiraSoapService = mock(JiraSoapService.class);

    JiraSoapSession soapSession = mock(JiraSoapSession.class);
    when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService);

    JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings);
    when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any()))
        .thenReturn(wrapper);

    RemoteFilter myFilter = new RemoteFilter();
    myFilter.setName("myFilter");
    myFilter.setId("1");
    when(jiraSoapService.getSavedFilters("token")).thenReturn(new RemoteFilter[] {myFilter});
    when(jiraSoapService.getFavouriteFilters("token")).thenThrow(RemoteException.class);

    Filter foundFilter = sensor.findJiraFilter(wrapper, "token");
    assertThat(foundFilter.getName()).isEqualTo(myFilter.getName());
  }
 @Override
 public void doExecute(JiraSoapService jiraService, String loginToken) throws Exception {
   Log log = getLog();
   log.debug("Login Token returned: " + loginToken);
   RemoteVersion[] versions = jiraService.getVersions(loginToken, jiraProjectKey);
   String thisReleaseVersion =
       (autoDiscoverLatestRelease) ? calculateLatestReleaseVersion(versions) : releaseVersion;
   if (thisReleaseVersion != null) {
     log.info("Releasing Version " + this.releaseVersion);
     markVersionAsReleased(jiraService, loginToken, versions, thisReleaseVersion);
   }
 }
 /**
  * Release Version
  *
  * @param log
  * @param jiraService
  * @param loginToken
  * @throws RemoteException
  * @throws RemotePermissionException
  * @throws RemoteAuthenticationException
  * @throws com.atlassian.jira.rpc.soap.client.RemoteException
  */
 RemoteVersion markVersionAsReleased(
     JiraSoapService jiraService,
     String loginToken,
     RemoteVersion[] versions,
     String releaseVersion)
     throws RemoteException, RemotePermissionException, RemoteAuthenticationException,
         com.atlassian.jira.rpc.soap.client.RemoteException {
   RemoteVersion ret = null;
   if (versions != null) {
     for (RemoteVersion remoteReleasedVersion : versions) {
       if (releaseVersion.equalsIgnoreCase(remoteReleasedVersion.getName())
           && !remoteReleasedVersion.isReleased()) {
         // Mark as released
         remoteReleasedVersion.setReleased(true);
         remoteReleasedVersion.setReleaseDate(Calendar.getInstance());
         jiraService.releaseVersion(loginToken, jiraProjectKey, remoteReleasedVersion);
         getLog().info("Version " + remoteReleasedVersion.getName() + " was released in JIRA.");
         ret = remoteReleasedVersion;
         break;
       }
     }
   }
   return ret;
 }