Search in sources :

Example 21 with Issue

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

the class IssueSearchTest method components_contain_sub_project_id_and_project_id_informations.

@Test
public void components_contain_sub_project_id_and_project_id_informations() {
    String fileKey = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1:src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo";
    Issues issues = issueClient().find(IssueQuery.create().components(fileKey));
    assertThat(issues.list()).isNotEmpty();
    Collection<Component> components = issues.components();
    Component project = findComponent(components, "com.sonarsource.it.samples:multi-modules-sample");
    assertThat(project.subProjectId()).isNull();
    assertThat(project.projectId()).isNull();
    Component subModuleA1 = findComponent(components, "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1");
    assertThat(subModuleA1.subProjectId()).isEqualTo(project.id());
    assertThat(subModuleA1.projectId()).isEqualTo(project.id());
    Component file = findComponent(components, fileKey);
    assertThat(file.subProjectId()).isNotNull();
    assertThat(file.projectId()).isNotNull();
    Issue issue = issues.list().get(0);
    assertThat(issues.component(issue)).isNotNull();
    assertThat(issues.component(issue).subProjectId()).isEqualTo(subModuleA1.id());
    assertThat(issues.component(issue).projectId()).isEqualTo(project.id());
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Issues(org.sonar.wsclient.issue.Issues) Component(org.sonar.wsclient.component.Component) Test(org.junit.Test)

Example 22 with Issue

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

the class IssuesModeTest method load_user_name_in_json_report.

// SONAR-6522
@Test
public void load_user_name_in_json_report() throws Exception {
    restoreProfile("one-issue-per-line.xml");
    orchestrator.getServer().provisionProject("sample", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
    // First run (publish mode)
    SonarScanner runner = configureRunner("shared/xoo-sample");
    orchestrator.executeBuild(runner);
    SonarClient client = orchestrator.getServer().adminWsClient();
    Issues issues = client.issueClient().find(IssueQuery.create());
    Issue issue = issues.list().get(0);
    UserParameters creationParameters = UserParameters.create().login("julien").name("Julien H").password("password").passwordConfirmation("password");
    client.userClient().create(creationParameters);
    // Assign issue
    client.issueClient().assign(issue.key(), "julien");
    // Issues
    runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.login", "julien", "sonar.password", "password");
    BuildResult result = orchestrator.executeBuild(runner);
    JSONObject obj = ItUtils.getJSONReport(result);
    Map<String, String> userNameByLogin = Maps.newHashMap();
    final JSONArray users = (JSONArray) obj.get("users");
    if (users != null) {
        for (Object user : users) {
            String login = ObjectUtils.toString(((JSONObject) user).get("login"));
            String name = ObjectUtils.toString(((JSONObject) user).get("name"));
            userNameByLogin.put(login, name);
        }
    }
    assertThat(userNameByLogin.get("julien")).isEqualTo("Julien H");
    for (Object issueJson : (JSONArray) obj.get("issues")) {
        JSONObject jsonObject = (JSONObject) issueJson;
        if (issue.key().equals(jsonObject.get("key"))) {
            assertThat(jsonObject.get("assignee")).isEqualTo("julien");
            return;
        }
    }
    fail("Issue not found");
}
Also used : UserParameters(org.sonar.wsclient.user.UserParameters) BuildResult(com.sonar.orchestrator.build.BuildResult) Issue(org.sonar.wsclient.issue.Issue) JSONObject(org.json.simple.JSONObject) Issues(org.sonar.wsclient.issue.Issues) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) SonarClient(org.sonar.wsclient.SonarClient) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 23 with Issue

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

the class IssueChangelogTest method update_changelog_when_reopening_unresolved_issue_by_scan.

@Test
public void update_changelog_when_reopening_unresolved_issue_by_scan() throws Exception {
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");
    Issue issue = searchRandomIssue();
    assertIssueHasNoChange(issue.key());
    // re analyse the project after resolving an issue in order to reopen it
    adminIssueClient().doTransition(issue.key(), "resolve");
    runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");
    List<Changelog> changes = changelog(issue.key()).getChangelogList();
    assertThat(changes).hasSize(2);
    // Change done by the user (first change is be the oldest one)
    Changelog change1 = changes.get(0);
    assertThat(change1.getUser()).isEqualTo("admin");
    assertThat(change1.getCreationDate()).isNotNull();
    assertThat(change1.getDiffsList()).extracting(Changelog.Diff::getKey, Changelog.Diff::getOldValue, Changelog.Diff::getNewValue).containsOnly(tuple("resolution", "", "FIXED"), tuple("status", "OPEN", "RESOLVED"));
    // Change done by scan
    Changelog change2 = changes.get(1);
    assertThat(change2.hasUser()).isFalse();
    assertThat(change2.getCreationDate()).isNotNull();
    assertThat(change2.getDiffsList()).extracting(Changelog.Diff::getKey, Changelog.Diff::getOldValue, Changelog.Diff::getNewValue).containsOnly(tuple("resolution", "", ""), tuple("status", "RESOLVED", "REOPENED"));
}
Also used : Issue(org.sonar.wsclient.issue.Issue) Changelog(org.sonarqube.ws.Issues.ChangelogWsResponse.Changelog) Test(org.junit.Test)

Example 24 with Issue

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

the class IssuePermissionTest method need_user_permission_on_project_to_see_issue_changelog.

/**
   * SONAR-4839
   */
@Test
public void need_user_permission_on_project_to_see_issue_changelog() {
    SonarClient client = orchestrator.getServer().adminWsClient();
    Issue issue = client.issueClient().find(IssueQuery.create().componentRoots("sample")).list().get(0);
    client.issueClient().assign(issue.key(), "admin");
    String withBrowsePermission = "with-browse-permission";
    String withoutBrowsePermission = "without-browse-permission";
    try {
        client.userClient().create(UserParameters.create().login(withBrowsePermission).name(withBrowsePermission).password("password").passwordConfirmation("password"));
        addUserPermission(withBrowsePermission, "sample", "user");
        client.userClient().create(UserParameters.create().login(withoutBrowsePermission).name(withoutBrowsePermission).password("password").passwordConfirmation("password"));
        // By default, it's the group anyone that have the permission user, it would be better to remove all groups on this permission
        removeGroupPermission("anyone", "sample", "user");
        // Without user permission, a user cannot see issue changelog on the project
        try {
            changelog(issue.key(), withoutBrowsePermission, "password");
            fail();
        } catch (Exception e) {
            assertThat(e).isInstanceOf(org.sonarqube.ws.client.HttpException.class).describedAs("403");
        }
        // Without user permission, a user cannot see issues on the project
        assertThat(changelog(issue.key(), withBrowsePermission, "password").getChangelogList()).isNotEmpty();
    } finally {
        client.userClient().deactivate(withBrowsePermission);
        client.userClient().deactivate(withoutBrowsePermission);
    }
}
Also used : Issue(org.sonar.wsclient.issue.Issue) SonarClient(org.sonar.wsclient.SonarClient) HttpException(org.sonar.wsclient.base.HttpException) Test(org.junit.Test)

Example 25 with Issue

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

the class AutoAssignTest method update_author_and_assignee_when_scm_is_activated.

/**
   * SONAR-7098
   *
   * Given two versions of same project:
   * v1: issue, but no SCM data
   * v2: old issue and SCM data
   * Expected: all issues should be associated with authors
   */
@Test
public void update_author_and_assignee_when_scm_is_activated() {
    createUser(SIMON_USER, SIMON_USER);
    // Run a first analysis without SCM
    projectAnalysis.withProperties("sonar.scm.disabled", "true").run();
    List<Issue> issues = searchIssues();
    assertThat(issues).isNotEmpty();
    // No author and assignee are set
    for (Issue issue : issues) {
        assertThat(issue.author()).isEmpty();
    }
    assertThat(search(IssueQuery.create().assigned(true)).list()).isEmpty();
    // Run a second analysis with SCM
    projectAnalysis.run();
    issues = searchIssues();
    assertThat(issues).isNotEmpty();
    // Authors and assignees are set
    for (Issue issue : issues) {
        assertThat(issue.author()).isNotEmpty();
    }
    assertThat(search(IssueQuery.create().assignees(SIMON_USER)).list()).hasSize(3);
}
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