Search in sources :

Example 1 with Issue

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

the class CustomRulesTest method analyzeProjectWithCustomRules.

@Test
public void analyzeProjectWithCustomRules() throws Exception {
    ORCHESTRATOR.getServer().adminWsClient().post("api/rules/create", "template_key", "xoo:TemplateRule", "custom_key", "MyCustomRule", "markdown_description", "My description", "name", "My custom rule", "severity", "BLOCKER", "params", "line=2");
    xooSampleAnalysis.run();
    List<Issue> issues = searchIssues();
    assertThat(issues).hasSize(1);
    Issue issue = issues.get(0);
    assertThat(issue.ruleKey()).isEqualTo("xoo:MyCustomRule");
    assertThat(issue.line()).isEqualTo(2);
    // Overriden in quality profile
    assertThat(issue.severity()).isEqualTo("CRITICAL");
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Test(org.junit.Test)

Example 2 with Issue

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

the class IssuePermissionTest method need_administer_issue_permission_on_project_to_flag_as_false_positive.

/**
   * SONAR-2447
   */
@Test
public void need_administer_issue_permission_on_project_to_flag_as_false_positive() {
    SonarClient client = orchestrator.getServer().adminWsClient();
    Issue issueOnSample = client.issueClient().find(IssueQuery.create().componentRoots("sample")).list().get(0);
    Issue issueOnSample2 = client.issueClient().find(IssueQuery.create().componentRoots("sample2")).list().get(0);
    String user = "user";
    try {
        client.userClient().create(UserParameters.create().login(user).name(user).password("password").passwordConfirmation("password"));
        addUserPermission(user, "sample", "issueadmin");
        // Without issue admin permission, a user cannot flag an issue as false positive
        try {
            orchestrator.getServer().wsClient(user, "password").issueClient().doTransition(issueOnSample2.key(), "falsepositive");
            fail();
        } catch (Exception e) {
            assertThat(e).isInstanceOf(HttpException.class).describedAs("404");
        }
        // With issue admin permission, a user can flag an issue as false positive
        assertThat(orchestrator.getServer().wsClient(user, "password").issueClient().doTransition(issueOnSample.key(), "falsepositive").status()).isEqualTo("RESOLVED");
    } finally {
        client.userClient().deactivate(user);
    }
}
Also used : Issue(org.sonar.wsclient.issue.Issue) SonarClient(org.sonar.wsclient.SonarClient) HttpException(org.sonar.wsclient.base.HttpException) Test(org.junit.Test)

Example 3 with Issue

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

the class IssueFilterExtensionTest method should_filter_files.

@Test
public void should_filter_files() throws Exception {
    analysis.withProperties("sonar.exclusions", "**/HelloA1.xoo").run();
    List<Issue> issues = searchIssues();
    assertThat(issues).isNotEmpty();
    for (Issue issue : issues) {
        // verify exclusion to avoid false positive
        assertThat(issue.componentKey()).doesNotContain("HelloA1");
    }
    assertThat(getMeasureAsDouble(ORCHESTRATOR, xooMultiModuleProjectKey, "violations").intValue()).isEqualTo(issues.size());
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Test(org.junit.Test)

Example 4 with Issue

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

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

Aggregations

Test (org.junit.Test)30 Issue (org.sonar.wsclient.issue.Issue)30 IssueClient (org.sonar.wsclient.issue.IssueClient)7 Issues (org.sonar.wsclient.issue.Issues)7 SonarClient (org.sonar.wsclient.SonarClient)5 BuildResult (com.sonar.orchestrator.build.BuildResult)3 MavenBuild (com.sonar.orchestrator.build.MavenBuild)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 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