// SONAR-4602 @Test public void no_issues_mode_cache_after_issue_change() 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) SonarRunner runner = configureRunner("shared/xoo-sample"); orchestrator.executeBuild(runner); // First issues mode runner = configureRunnerIssues("shared/xoo-sample"); 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"); // Second issues mode runner = configureRunnerIssues("shared/xoo-sample"); result = orchestrator.executeBuild(runner); // False positive is not returned assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(16); }
// SONAR-4602 @Test public void no_issues_mode_cache_after_profile_change() throws Exception { restoreProfile("one-issue-per-line-empty.xml"); orchestrator.getServer().provisionProject("sample", "xoo-sample"); orchestrator .getServer() .associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); // First run (publish mode) SonarRunner runner = configureRunner("shared/xoo-sample"); orchestrator.executeBuild(runner); // First issues mode runner = configureRunnerIssues("shared/xoo-sample"); BuildResult result = orchestrator.executeBuild(runner); // No new issues assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(0); // Modification of QP should invalidate cache restoreProfile("/one-issue-per-line.xml"); // Second issues mode runner = configureRunnerIssues("shared/xoo-sample", "sonar.report.export.path", "sonar-report.json"); result = orchestrator.executeBuild(runner); // As many new issue as lines assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); }
@Test public void non_associated_mode() throws IOException { restoreProfile("one-issue-per-line.xml"); setDefaultQualityProfile("xoo", "one-issue-per-line"); SonarRunner runner = configureRunnerIssues("shared/xoo-sample-non-associated"); BuildResult result = orchestrator.executeBuild(runner); assertThat(result.getLogs()).contains("Local analysis"); assertThat(result.getLogs()).contains("Cache not found, synchronizing data"); assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); result = orchestrator.executeBuild(runner); assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); assertThat(result.getLogs()).contains("Found cache"); }
@Before public void setUpProject() throws IOException { orchestrator.resetData(); orchestrator .getServer() .restoreProfile(FileLocation.ofClasspath("/duplication/xoo-duplication-profile.xml")); FileUtils.copyDirectory(ItUtils.projectDir(PROJECT_DIR), temp.getRoot()); projectDir = temp.getRoot(); }
@Test public void issues_analysis_on_new_project() throws IOException { restoreProfile("one-issue-per-line.xml"); orchestrator.getServer().provisionProject("sample", "xoo-sample"); orchestrator .getServer() .associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); SonarRunner runner = configureRunnerIssues("shared/xoo-sample", "sonar.verbose", "true"); BuildResult result = orchestrator.executeBuild(runner); assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); }
// 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) SonarRunner 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"); 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"); }
private SonarRunner configureRunner(String projectDir, String... props) throws IOException { SonarRunner runner = SonarRunner.create( ItUtils.projectDir(projectDir), "sonar.working.directory", temp.newFolder().getAbsolutePath(), "sonar.report.export.path", "sonar-report.json", "sonar.userHome", temp.newFolder().getAbsolutePath()); runner.setProperties(props); return runner; }
/** SONAR-926 SONAR-5069 */ @Test public void test_sonar_runner_inspection() { orchestrator .getServer() .restoreProfile( FileLocation.ofClasspath("/analysis/MultiLanguageTest/one-issue-per-line.xml")); orchestrator .getServer() .restoreProfile( FileLocation.ofClasspath("/analysis/MultiLanguageTest/one-issue-per-line-xoo2.xml")); orchestrator.getServer().provisionProject("multi-language-sample", "multi-language-sample"); orchestrator .getServer() .associateProjectToQualityProfile("multi-language-sample", "xoo", "one-issue-per-line"); orchestrator .getServer() .associateProjectToQualityProfile( "multi-language-sample", "xoo2", "one-issue-per-line-xoo2"); SonarRunner build = SonarRunner.create().setProjectDir(ItUtils.projectDir("analysis/xoo-multi-languages")); BuildResult result = orchestrator.executeBuild(build); assertThat(result.getLogs()).contains("2 files indexed"); assertThat(result.getLogs()).contains("Quality profile for xoo: one-issue-per-line"); assertThat(result.getLogs()).contains("Quality profile for xoo2: one-issue-per-line-xoo2"); // modules Resource project = getResource("multi-language-sample", "files", "violations"); assertThat(project.getMeasureIntValue("files")).isEqualTo(2); assertThat(project.getMeasureIntValue("violations")).isEqualTo(26); Resource xooFile = getResource("multi-language-sample:src/sample/Sample.xoo", "violations"); assertThat(xooFile.getMeasureIntValue("violations")).isEqualTo(13); Resource xoo2File = getResource("multi-language-sample:src/sample/Sample.xoo2", "violations"); assertThat(xoo2File.getMeasureIntValue("violations")).isEqualTo(13); }
@After public void resetPeriods() throws Exception { ItUtils.resetPeriods(orchestrator); }
private void scan(String... properties) { SonarRunner build = SonarRunner.create(ItUtils.projectDir("exclusions/exclusions")).setProperties(properties); orchestrator.executeBuild(build); }