Search in sources :

Example 1 with Issues

use of org.sonar.wsclient.issue.Issues in project sonarqube by SonarSource.

the class IssueNotificationsTest method notifications_for_bulk_change_ws.

/**
   * SONAR-4606
   */
@Test
public void notifications_for_bulk_change_ws() throws Exception {
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample", "sonar.projectDate", "2015-12-15");
    Issues issues = issueClient.find(IssueQuery.create().componentRoots(PROJECT_KEY));
    Issue issue = issues.list().get(0);
    // bulk change without notification by default
    issuesService.bulkChange(BulkChangeRequest.builder().setIssues(singletonList(issue.key())).setAssign(USER_LOGIN).setSetSeverity("MINOR").build());
    // bulk change with notification
    issuesService.bulkChange(BulkChangeRequest.builder().setIssues(singletonList(issue.key())).setSetSeverity("BLOCKER").setSendNotifications(true).build());
    waitUntilAllNotificationsAreDelivered(2);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    emails.next();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat((String) message.getContent()).contains("sample/Sample.xoo");
    assertThat((String) message.getContent()).contains("Severity: BLOCKER (was MINOR)");
    assertThat((String) message.getContent()).contains("See it in SonarQube: http://localhost:9000/issues/search#issues=" + issue.key());
    assertThat(emails.hasNext()).isFalse();
}
Also used : Issue(org.sonar.wsclient.issue.Issue) MimeMessage(javax.mail.internet.MimeMessage) Issues(org.sonar.wsclient.issue.Issues) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test)

Example 2 with Issues

use of org.sonar.wsclient.issue.Issues in project sonarqube by SonarSource.

the class IssuePurgeTest method purge_old_closed_issues.

/**
   * SONAR-4308
   */
@Test
public void purge_old_closed_issues() throws Exception {
    projectAnalysisRule.setServerProperty("sonar.dbcleaner.daysBeforeDeletingClosedIssues", "5000");
    // Generate some issues
    xooSampleAnalysis.withProperties("sonar.dynamicAnalysis", "false", "sonar.projectDate", "2014-10-01").run();
    // All the issues are open
    List<Issue> issuesList = searchIssues();
    for (Issue issue : issuesList) {
        assertThat(issue.resolution()).isNull();
    }
    // Second scan with empty profile -> all issues are resolved and closed
    // -> Not deleted because less than 5000 days long
    xooSampleAnalysis.withXooEmptyProfile().withProperties("sonar.dynamicAnalysis", "false", "sonar.projectDate", "2014-10-15").run();
    issuesList = searchIssues();
    assertThat(issuesList).isNotEmpty();
    for (Issue issue : issuesList) {
        assertThat(issue.resolution()).isNotNull();
        assertThat(issue.status()).isEqualTo("CLOSED");
    }
    // Third scan -> closed issues are deleted
    projectAnalysisRule.setServerProperty("sonar.dbcleaner.daysBeforeDeletingClosedIssues", "1");
    xooSampleAnalysis.withXooEmptyProfile().withProperties("sonar.dynamicAnalysis", "false", "sonar.projectDate", "2014-10-20").run();
    Issues issues = issueClient().find(IssueQuery.create());
    assertThat(issues.list()).isEmpty();
    assertThat(issues.paging().total()).isZero();
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Issues(org.sonar.wsclient.issue.Issues) Test(org.junit.Test)

Example 3 with Issues

use of org.sonar.wsclient.issue.Issues in project sonarqube by SonarSource.

the class IssuePurgeTest method purge_old_closed_issues_when_zero_closed_issues_wanted.

/**
   * SONAR-7108
   */
@Test
public void purge_old_closed_issues_when_zero_closed_issues_wanted() throws Exception {
    projectAnalysisRule.setServerProperty("sonar.dbcleaner.daysBeforeDeletingClosedIssues", "5000");
    // Generate some issues
    xooSampleAnalysis.withProperties("sonar.dynamicAnalysis", "false", "sonar.projectDate", "2014-10-01").run();
    // All the issues are open
    List<Issue> issueList = searchIssues();
    for (Issue issue : issueList) {
        assertThat(issue.resolution()).isNull();
    }
    // Second scan with empty profile -> all issues are resolved and closed
    // -> Not deleted because less than 5000 days long
    xooSampleAnalysis.withXooEmptyProfile().withProperties("sonar.dynamicAnalysis", "false", "sonar.projectDate", "2014-10-15").run();
    issueList = searchIssues();
    assertThat(issueList).isNotEmpty();
    for (Issue issue : issueList) {
        assertThat(issue.resolution()).isNotNull();
        assertThat(issue.status()).isEqualTo("CLOSED");
    }
    // Third scan -> closed issues are deleted
    projectAnalysisRule.setServerProperty("sonar.dbcleaner.daysBeforeDeletingClosedIssues", "0");
    xooSampleAnalysis.withXooEmptyProfile().withProperties("sonar.dynamicAnalysis", "false", "sonar.projectDate", "2014-10-20").run();
    Issues issues = issueClient().find(IssueQuery.create());
    assertThat(issues.list()).isEmpty();
    assertThat(issues.paging().total()).isZero();
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Issues(org.sonar.wsclient.issue.Issues) Test(org.junit.Test)

Example 4 with Issues

use of org.sonar.wsclient.issue.Issues in project sonarqube by SonarSource.

the class IssueCreationTest method plugin_can_override_profile_severity.

@Test
public void plugin_can_override_profile_severity() throws Exception {
    ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_KEY);
    // The rule "OneBlockerIssuePerFile" is enabled with severity "INFO"
    ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/IssueCreationTest/override-profile-severity.xml"));
    ORCHESTRATOR.getServer().associateProjectToQualityProfile(SAMPLE_PROJECT_KEY, "xoo", "override-profile-severity");
    // But it's hardcoded "blocker" when plugin generates the issue
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");
    Issues issues = search(IssueQuery.create().rules("xoo:OneBlockerIssuePerFile"));
    assertThat(issues.size()).isGreaterThan(0);
    for (Issue issue : issues.list()) {
        assertThat(issue.severity()).isEqualTo("BLOCKER");
    }
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Issues(org.sonar.wsclient.issue.Issues) Test(org.junit.Test)

Example 5 with Issues

use of org.sonar.wsclient.issue.Issues in project sonarqube by SonarSource.

the class IssueNotificationsTest method notifications_for_new_issues_and_issue_changes.

@Test
public void notifications_for_new_issues_and_issue_changes() throws Exception {
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample", "sonar.projectDate", "2015-12-15");
    // change assignee
    Issues issues = issueClient.find(IssueQuery.create().componentRoots(PROJECT_KEY));
    Issue issue = issues.list().get(0);
    issueClient.assign(issue.key(), USER_LOGIN);
    waitUntilAllNotificationsAreDelivered(2);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    assertThat(emails.hasNext()).isTrue();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat((String) message.getContent()).contains("Sample");
    assertThat((String) message.getContent()).contains("17 new issues (new debt: 17min)");
    assertThat((String) message.getContent()).contains("Severity");
    assertThat((String) message.getContent()).contains("One Issue Per Line (xoo): 17");
    assertThat((String) message.getContent()).contains("See it in SonarQube: http://localhost:9000/component_issues?id=sample#createdAt=2015-12-15T00%3A00%3A00%2B");
    assertThat(emails.hasNext()).isTrue();
    message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat((String) message.getContent()).contains("sample/Sample.xoo");
    assertThat((String) message.getContent()).contains("Assignee changed to Tester");
    assertThat((String) message.getContent()).contains("See it in SonarQube: http://localhost:9000/issues/search#issues=" + issue.key());
    assertThat(emails.hasNext()).isFalse();
}
Also used : Issue(org.sonar.wsclient.issue.Issue) MimeMessage(javax.mail.internet.MimeMessage) Issues(org.sonar.wsclient.issue.Issues) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Issues (org.sonar.wsclient.issue.Issues)8 Issue (org.sonar.wsclient.issue.Issue)7 MimeMessage (javax.mail.internet.MimeMessage)2 WiserMessage (org.subethamail.wiser.WiserMessage)2 BuildResult (com.sonar.orchestrator.build.BuildResult)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 SonarClient (org.sonar.wsclient.SonarClient)1 Paging (org.sonar.wsclient.base.Paging)1 Component (org.sonar.wsclient.component.Component)1 UserParameters (org.sonar.wsclient.user.UserParameters)1