Search in sources :

Example 96 with JSONArray

use of org.json.simple.JSONArray in project sonarqube by SonarSource.

the class IssueJsonReportTest method precise_issue_location.

@Test
public void precise_issue_location() throws IOException {
    orchestrator.getServer().restoreProfile(getResource("multiline.xml"));
    orchestrator.getServer().provisionProject("sample-multiline", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample-multiline", "xoo", "multiline");
    File projectDir = ItUtils.projectDir("shared/xoo-precise-issues");
    SonarScanner runner = SonarScanner.create(projectDir, "sonar.analysis.mode", "issues", "sonar.verbose", "true", "sonar.report.export.path", "sonar-report.json");
    BuildResult result = orchestrator.executeBuild(runner);
    assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(2);
    JSONObject obj = ItUtils.getJSONReport(result);
    JSONArray issues = (JSONArray) obj.get("issues");
    JSONObject issue1 = (JSONObject) issues.get(0);
    JSONObject issue2 = (JSONObject) issues.get(1);
    assertThat(issue1.get("startLine")).isIn(6L);
    assertThat(issue1.get("line")).isIn(6L);
    assertThat(issue1.get("endLine")).isIn(6L);
    assertThat(issue1.get("startOffset")).isIn(27L);
    assertThat(issue1.get("endOffset")).isIn(32L);
    assertThat(issue2.get("startLine")).isIn(9L);
    assertThat(issue2.get("line")).isIn(9L);
    assertThat(issue2.get("endLine")).isIn(15L);
    assertThat(issue2.get("startOffset")).isIn(20L);
    assertThat(issue2.get("endOffset")).isIn(2L);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 97 with JSONArray

use of org.json.simple.JSONArray in project sonarqube by SonarSource.

the class IssueJsonReportTest method issue_line.

@Test
public void issue_line() throws IOException {
    orchestrator.getServer().restoreProfile(getResource("one-issue-per-line.xml"));
    orchestrator.getServer().provisionProject("sample", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
    File projectDir = ItUtils.projectDir("shared/xoo-sample");
    SonarScanner runner = SonarScanner.create(projectDir, "sonar.analysis.mode", "issues", "sonar.verbose", "true", "sonar.report.export.path", "sonar-report.json");
    BuildResult result = orchestrator.executeBuild(runner);
    assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17);
    JSONObject obj = ItUtils.getJSONReport(result);
    JSONArray issues = (JSONArray) obj.get("issues");
    for (Object issue : issues) {
        JSONObject jsonIssue = (JSONObject) issue;
        assertThat(jsonIssue.get("startLine")).isNotNull();
        assertThat(jsonIssue.get("line")).isEqualTo(jsonIssue.get("startLine"));
        assertThat(jsonIssue.get("endLine")).isEqualTo(jsonIssue.get("startLine"));
        assertThat(jsonIssue.get("endOffset")).isNotNull();
        assertThat(jsonIssue.get("startOffset")).isNotNull();
    }
    List<Long> lineNumbers = new ArrayList<>(16);
    for (long i = 1L; i < 18; i++) {
        lineNumbers.add(i);
    }
    assertThat(issues).extracting("startLine").containsAll(lineNumbers);
    assertThat(issues).extracting("endLine").containsAll(lineNumbers);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 98 with JSONArray

use of org.json.simple.JSONArray in project sonarqube by SonarSource.

the class IssuesModeTest method runFirstAnalysisAndFlagIssueAsWontFix.

private File runFirstAnalysisAndFlagIssueAsWontFix() throws IOException {
    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);
    // First issues mode
    File homeDir = temp.newFolder();
    runner = configureRunnerIssues("shared/xoo-sample", homeDir);
    BuildResult result = orchestrator.executeBuild(runner);
    // 17 issues
    assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(17);
    // Flag one issue as false positive
    JSONObject obj = ItUtils.getJSONReport(result);
    String key = ((JSONObject) ((JSONArray) obj.get("issues")).get(0)).get("key").toString();
    orchestrator.getServer().adminWsClient().issueClient().doTransition(key, "falsepositive");
    return homeDir;
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner)

Example 99 with JSONArray

use of org.json.simple.JSONArray 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 100 with JSONArray

use of org.json.simple.JSONArray in project sonarqube by SonarSource.

the class ItUtils method assertIssuesInJsonReport.

public static void assertIssuesInJsonReport(BuildResult result, int newIssues, int resolvedIssues, int existingIssues) {
    JSONObject obj = getJSONReport(result);
    JSONArray issues = (JSONArray) obj.get("issues");
    int countNew = 0;
    int countResolved = 0;
    int countExisting = 0;
    for (Object issue : issues) {
        JSONObject jsonIssue = (JSONObject) issue;
        if ((Boolean) jsonIssue.get("isNew")) {
            countNew++;
        } else if (jsonIssue.get("resolution") != null) {
            countResolved++;
        } else {
            countExisting++;
        }
    }
    assertThat(countNew).isEqualTo(newIssues);
    assertThat(countResolved).isEqualTo(resolvedIssues);
    assertThat(countExisting).isEqualTo(existingIssues);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject)

Aggregations

JSONArray (org.json.simple.JSONArray)148 JSONObject (org.json.simple.JSONObject)129 JSONParser (org.json.simple.parser.JSONParser)61 HttpClient (org.apache.commons.httpclient.HttpClient)21 ParseException (org.json.simple.parser.ParseException)21 GetMethod (org.apache.commons.httpclient.methods.GetMethod)17 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 File (java.io.File)11 IOException (java.io.IOException)11 MapLayer (au.org.emii.portal.menu.MapLayer)8 FileReader (java.io.FileReader)6 HashMap (java.util.HashMap)6 List (java.util.List)6 LegendObject (au.org.ala.legend.LegendObject)5 Point (com.vividsolutions.jts.geom.Point)5 PrintStream (java.io.PrintStream)5 Event (org.zkoss.zk.ui.event.Event)5 BuildResult (com.sonar.orchestrator.build.BuildResult)4 SonarScanner (com.sonar.orchestrator.build.SonarScanner)4