Search in sources :

Example 11 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)

Example 12 with Issue

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

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

the class IssueSearchTest method search_by_exact_creation_date.

/**
   * SONAR-4563
   */
@Test
public void search_by_exact_creation_date() {
    final Issue issue = search(IssueQuery.create()).list().get(0);
    assertThat(issue.creationDate()).isNotNull();
    // search the issue key with the same date
    assertThat(search(IssueQuery.create().issues().issues(issue.key()).createdAt(issue.creationDate())).list()).hasSize(1);
    // search issue key with 1 second more and less should return nothing
    assertThat(search(IssueQuery.create().issues().issues(issue.key()).createdAt(DateUtils.addSeconds(issue.creationDate(), 1))).size()).isEqualTo(0);
    assertThat(search(IssueQuery.create().issues().issues(issue.key()).createdAt(DateUtils.addSeconds(issue.creationDate(), -1))).size()).isEqualTo(0);
    // search with future and past dates that do not match any issues
    assertThat(search(IssueQuery.create().createdAt(toDate("2020-01-01"))).size()).isEqualTo(0);
    assertThat(search(IssueQuery.create().createdAt(toDate("2010-01-01"))).size()).isEqualTo(0);
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Test(org.junit.Test)

Example 14 with Issue

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

the class IssueChangelogTest method update_changelog_when_assigning_issue_by_user.

@Test
public void update_changelog_when_assigning_issue_by_user() throws Exception {
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");
    Issue issue = searchRandomIssue();
    assertIssueHasNoChange(issue.key());
    adminIssueClient().assign(issue.key(), "admin");
    List<Changelog> changes = changelog(issue.key()).getChangelogList();
    assertThat(changes).hasSize(1);
    Changelog change = changes.get(0);
    assertThat(change.getUser()).isEqualTo("admin");
    assertThat(change.getCreationDate()).isNotNull();
    assertThat(change.getDiffsList()).extracting(Changelog.Diff::getKey, Changelog.Diff::hasOldValue, Changelog.Diff::getNewValue).containsOnly(tuple("assignee", false, "Administrator"));
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Changelog(org.sonarqube.ws.Issues.ChangelogWsResponse.Changelog) Test(org.junit.Test)

Example 15 with Issue

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

the class IssueChangelogTest method display_file_name_in_changelog_during_file_move.

@Test
public void display_file_name_in_changelog_during_file_move() {
    // version 1
    runProjectAnalysis(ORCHESTRATOR, "issue/xoo-tracking-v1");
    // version 2
    runProjectAnalysis(ORCHESTRATOR, "issue/xoo-tracking-v3");
    Issue issue = searchRandomIssue();
    List<Changelog> changes = changelog(issue.key()).getChangelogList();
    assertThat(changes).hasSize(1);
    Changelog change = changes.get(0);
    assertThat(change.hasUser()).isFalse();
    assertThat(change.getCreationDate()).isNotNull();
    assertThat(change.getDiffsList()).extracting(Changelog.Diff::getKey, Changelog.Diff::getOldValue, Changelog.Diff::getNewValue).containsOnly(tuple("file", "src/main/xoo/sample/Sample.xoo", "src/main/xoo/sample/Sample2.xoo"));
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Changelog(org.sonarqube.ws.Issues.ChangelogWsResponse.Changelog) 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