Search in sources :

Example 6 with Issues

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

the class IssueSearchTest method paginate_results.

@Test
public void paginate_results() {
    Issues issues = search(IssueQuery.create().pageSize(20).pageIndex(2));
    assertThat(issues.list()).hasSize(20);
    Paging paging = issues.paging();
    assertThat(paging.pageIndex()).isEqualTo(2);
    assertThat(paging.pageSize()).isEqualTo(20);
    assertThat(paging.total()).isEqualTo(TOTAL_NB_ISSUES);
    // SONAR-3257
    // return max page size results when using negative page size value
    assertThat(search(IssueQuery.create().pageSize(0)).list()).hasSize(TOTAL_NB_ISSUES);
    assertThat(search(IssueQuery.create().pageSize(-1)).list()).hasSize(TOTAL_NB_ISSUES);
}
Also used : Issues(org.sonar.wsclient.issue.Issues) Paging(org.sonar.wsclient.base.Paging) Test(org.junit.Test)

Example 7 with Issues

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

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

Aggregations

Test (org.junit.Test)8 Issues (org.sonar.wsclient.issue.Issues)8 Issue (org.sonar.wsclient.issue.Issue)7 MimeMessage (javax.mail.internet.MimeMessage)2 WiserMessage (org.subethamail.wiser.WiserMessage)2 BuildResult (com.sonar.orchestrator.build.BuildResult)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 SonarClient (org.sonar.wsclient.SonarClient)1 Paging (org.sonar.wsclient.base.Paging)1 Component (org.sonar.wsclient.component.Component)1 UserParameters (org.sonar.wsclient.user.UserParameters)1