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);
}
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);
}
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;
}
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");
}
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);
}
Aggregations