Search in sources :

Example 1 with IssueClient

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

the class TechnicalDebtInIssueChangelogTest method display_debt_in_issue_changelog.

@Test
public void display_debt_in_issue_changelog() throws Exception {
    orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/qualityModel/one-issue-per-file.xml"));
    orchestrator.getServer().provisionProject("sample", "sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-file");
    // Execute a first analysis to have a past snapshot
    orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
    // Second analysis, existing issues on OneIssuePerFile will have their technical debt updated with the effort to fix
    orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")).setProperties("sonar.oneIssuePerFile.effortToFix", "10"));
    IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
    Issue issue = issueClient.find(IssueQuery.create()).list().get(0);
    List<Issues.ChangelogWsResponse.Changelog> changes = changelog(issue.key()).getChangelogList();
    assertThat(changes).hasSize(1);
    assertThat(changes.get(0).getDiffsList()).extracting(Issues.ChangelogWsResponse.Changelog.Diff::getKey, Issues.ChangelogWsResponse.Changelog.Diff::getOldValue, Issues.ChangelogWsResponse.Changelog.Diff::getNewValue).containsOnly(tuple("effort", "10", "100"));
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Issues(org.sonarqube.ws.Issues) IssueClient(org.sonar.wsclient.issue.IssueClient) Test(org.junit.Test)

Example 2 with IssueClient

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

the class IssuesModeTest method only_scan_changed_files_transitions.

// SONAR-6931
@Test
public void only_scan_changed_files_transitions() throws IOException {
    restoreProfile("one-issue-per-line.xml");
    orchestrator.getServer().provisionProject("sample", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
    SonarScanner runner = configureRunner("shared/xoo-sample", "sonar.verbose", "true");
    BuildResult result = orchestrator.executeBuild(runner);
    List<Issue> serverIssues = ItUtils.getAllServerIssues(orchestrator);
    for (Issue i : serverIssues) {
        assertThat(i.status()).isEqualTo("OPEN");
    }
    assertThat(serverIssues).hasSize(17);
    // resolve 2 issues
    IssueClient issueClient = orchestrator.getServer().wsClient("admin", "admin").issueClient();
    issueClient.doTransition(serverIssues.get(0).key(), "wontfix");
    issueClient.doTransition(serverIssues.get(1).key(), "wontfix");
    // do it again, scanning nothing (all files should be unchanged)
    runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.verbose", "true");
    result = orchestrator.executeBuild(runner);
    assertThat(result.getLogs()).contains("Scanning only changed files");
    assertThat(result.getLogs()).contains("'One Issue Per Line' skipped because there is no related file in current project");
    ItUtils.assertIssuesInJsonReport(result, 0, 0, 15);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) Issue(org.sonar.wsclient.issue.Issue) IssueClient(org.sonar.wsclient.issue.IssueClient) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 3 with IssueClient

use of org.sonar.wsclient.issue.IssueClient in project sonar-java by SonarSource.

the class JavaExtensionsTest method test.

@Test
public void test() {
    MavenBuild build = MavenBuild.create(TestUtils.projectPom("java-extension")).setCleanSonarGoals().setProperty("sonar.profile", "java-extension");
    orchestrator.executeBuild(build);
    IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
    List<Issue> issues = issueClient.find(IssueQuery.create().rules("java-extension:example").componentRoots("com.sonarsource.it.projects:java-extension")).list();
    // We found issues so the extension rule was properly set.
    assertThat(issues).hasSize(4);
    issues = issueClient.find(IssueQuery.create().rules("java-extension:subscriptionexamplecheck").componentRoots("com.sonarsource.it.projects:java-extension")).list();
    assertThat(issues).hasSize(3);
    issues = issueClient.find(IssueQuery.create().rules("java-extension:subscriptionexampletestcheck").componentRoots("com.sonarsource.it.projects:java-extension")).list();
    assertThat(issues).hasSize(1);
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) Issue(org.sonar.wsclient.issue.Issue) IssueClient(org.sonar.wsclient.issue.IssueClient) Test(org.junit.Test)

Example 4 with IssueClient

use of org.sonar.wsclient.issue.IssueClient in project sonar-java by SonarSource.

the class JavaComplexityTest method complexity_sqale_computation.

@Test
public void complexity_sqale_computation() throws Exception {
    IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
    List<Issue> issues = issueClient.find(IssueQuery.create().componentRoots(PROJECT)).list();
    assertThat(issues).hasSize(3);
    Set<String> debts = Sets.newHashSet();
    for (Issue issue : issues) {
        debts.add(issue.debt());
    }
    assertThat(debts).hasSize(2).containsOnly("11min", "12min");
}
Also used : Issue(org.sonar.wsclient.issue.Issue) IssueClient(org.sonar.wsclient.issue.IssueClient) Test(org.junit.Test)

Example 5 with IssueClient

use of org.sonar.wsclient.issue.IssueClient in project sonar-java by SonarSource.

the class JavaTest method should_create_issue_pom_xml.

@Test
public void should_create_issue_pom_xml() {
    assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("6.3"));
    orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/profile-pom-xml.xml"));
    orchestrator.getServer().provisionProject("org.sonarsource.java:test-project", "Test Project");
    orchestrator.getServer().associateProjectToQualityProfile("org.sonarsource.java:test-project", "java", "java-pom-xml");
    MavenBuild build = MavenBuild.create().setPom(TestUtils.projectPom("pom-xml")).setCleanPackageSonarGoals();
    orchestrator.executeBuild(build);
    IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
    List<Issue> issues = issueClient.find(IssueQuery.create().components("org.sonarsource.java:test-project:pom.xml")).list();
    assertThat(issues).hasSize(1);
    assertThat(issues.iterator().next().ruleKey()).isEqualTo("squid:S3423");
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) Issue(org.sonar.wsclient.issue.Issue) IssueClient(org.sonar.wsclient.issue.IssueClient) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 IssueClient (org.sonar.wsclient.issue.IssueClient)8 Issue (org.sonar.wsclient.issue.Issue)7 MavenBuild (com.sonar.orchestrator.build.MavenBuild)3 BuildResult (com.sonar.orchestrator.build.BuildResult)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 Issues (org.sonarqube.ws.Issues)1