Search in sources :

Example 16 with Issue

use of org.sonar.wsclient.issue.Issue 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 17 with Issue

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

the class IssueCreationTest method use_rule_name_if_issue_has_no_message.

/**
   * See SONAR-4785
   */
@Test
public void use_rule_name_if_issue_has_no_message() {
    ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_KEY);
    ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/IssueCreationTest/with-custom-message.xml"));
    ORCHESTRATOR.getServer().associateProjectToQualityProfile(SAMPLE_PROJECT_KEY, "xoo", "with-custom-message");
    // First analysis, the issue is generated with a message
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample", "sonar.customMessage.message", "a message");
    Issue issue = issueClient().find(IssueQuery.create()).list().get(0);
    assertThat(issue.message()).isEqualTo("a message");
    // Second analysis, the issue is generated without any message, the name of the rule is used
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");
    issue = issueClient().find(IssueQuery.create()).list().get(0);
    assertThat(issue.message()).isEqualTo("Issue With Custom Message");
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Test(org.junit.Test)

Example 18 with Issue

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

the class IssueFilterExtensionTest method should_filter_issues.

@Test
public void should_filter_issues() {
    // first analysis without issue-filter
    analysis.run();
    // Issue filter removes issues on lines < 5
    // Deprecated violation filter removes issues detected by PMD
    List<Issue> unresolvedIssues = searchResolvedIssues(xooMultiModuleProjectKey);
    int issuesBeforeLine5 = countIssuesBeforeLine5(unresolvedIssues);
    int pmdIssues = countModuleIssues(unresolvedIssues);
    assertThat(issuesBeforeLine5).isGreaterThan(0);
    assertThat(pmdIssues).isGreaterThan(0);
    // Enable issue filters
    analysis.withProperties("enableIssueFilters", "true").run();
    unresolvedIssues = searchResolvedIssues(xooMultiModuleProjectKey);
    List<Issue> resolvedIssues = searchUnresolvedIssues(xooMultiModuleProjectKey);
    assertThat(countIssuesBeforeLine5(unresolvedIssues)).isZero();
    assertThat(countModuleIssues(unresolvedIssues)).isZero();
    assertThat(countModuleIssues(resolvedIssues)).isGreaterThan(0);
    for (Issue issue : resolvedIssues) {
        // SONAR-6364 no line number on closed issues
        assertThat(issue.line()).isNull();
    }
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Test(org.junit.Test)

Example 19 with Issue

use of org.sonar.wsclient.issue.Issue 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)

Example 20 with Issue

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

the class IssuePurgeTest method resolve_issues_when_removing_module.

/**
   * SONAR-5200
   */
@Test
public void resolve_issues_when_removing_module() throws Exception {
    // Generate some issues
    xooMultiModuleAnalysis.withProperties("sonar.dynamicAnalysis", "false").run();
    // All the issues are open
    List<Issue> issues = searchIssues();
    for (Issue issue : issues) {
        assertThat(issue.resolution()).isNull();
    }
    Issue issue = issues.get(0);
    int issuesOnModuleB = searchIssues(IssueQuery.create().componentRoots("com.sonarsource.it.samples:multi-modules-sample:module_b")).size();
    assertThat(issuesOnModuleB).isEqualTo(28);
    // Second scan without module B -> issues on module B are resolved as removed and closed
    xooMultiModuleAnalysis.withProperties("sonar.dynamicAnalysis", "false", "sonar.modules", "module_a").run();
    // Resolved should should all be mark as REMOVED and affect to module b
    List<Issue> reloadedIssues = searchIssues(IssueQuery.create().resolved(true));
    assertThat(reloadedIssues).hasSize(issuesOnModuleB);
    for (Issue reloadedIssue : reloadedIssues) {
        assertThat(reloadedIssue.resolution()).isEqualTo("FIXED");
        assertThat(reloadedIssue.status()).isEqualTo("CLOSED");
        assertThat(reloadedIssue.componentKey()).contains("com.sonarsource.it.samples:multi-modules-sample:module_b");
        assertThat(reloadedIssue.updateDate().before(issue.updateDate())).isFalse();
        assertThat(reloadedIssue.closeDate()).isNotNull();
        assertThat(reloadedIssue.closeDate().before(reloadedIssue.creationDate())).isFalse();
    }
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 Issue (org.sonar.wsclient.issue.Issue)25 Issues (org.sonar.wsclient.issue.Issues)7 SonarClient (org.sonar.wsclient.SonarClient)5 BuildResult (com.sonar.orchestrator.build.BuildResult)3 SonarScanner (com.sonar.orchestrator.build.SonarScanner)3 HttpException (org.sonar.wsclient.base.HttpException)3 Changelog (org.sonarqube.ws.Issues.ChangelogWsResponse.Changelog)3 MimeMessage (javax.mail.internet.MimeMessage)2 IssueClient (org.sonar.wsclient.issue.IssueClient)2 Issues (org.sonarqube.ws.Issues)2 WiserMessage (org.subethamail.wiser.WiserMessage)2 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Component (org.sonar.wsclient.component.Component)1 UserParameters (org.sonar.wsclient.user.UserParameters)1