import com.sonar.orchestrator.build.SonarScannerInstaller;
import com.sonar.orchestrator.config.FileSystem;
import com.sonar.orchestrator.version.Version;
-import org.sonarqube.tests.Category3Suite;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.lang.ObjectUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
-import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.wsclient.issue.IssueQuery;
import org.sonar.wsclient.issue.Issues;
import org.sonar.wsclient.user.UserParameters;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.tests.Category3Suite;
+import org.sonarqube.ws.client.PostRequest;
import util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- @Before
- public void deleteData() throws IOException {
- orchestrator.resetData();
- }
+ @Rule
+ public Tester tester = new Tester(orchestrator).disableOrganizations();
@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");
- SonarScanner runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.verbose", "true");
+ SonarScanner runner = configureScannerIssues("shared/xoo-sample", null, "sonar.verbose", "true");
BuildResult result = orchestrator.executeBuild(runner);
assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17);
}
restoreProfile("one-issue-per-line.xml");
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
- SonarScanner runner = configureRunner("shared/xoo-sample");
- runner.setProperty("sonar.analysis.mode", "incremental");
+ SonarScanner scanner = configureScanner("shared/xoo-sample");
+ scanner.setProperty("sonar.analysis.mode", "incremental");
thrown.expect(BuildFailureException.class);
- BuildResult res = orchestrator.executeBuild(runner);
+ BuildResult res = orchestrator.executeBuild(scanner);
assertThat(res.getLogs()).contains("Invalid analysis mode: incremental. This mode was removed in SonarQube 5.2");
}
restoreProfile("one-issue-per-line.xml");
setDefaultQualityProfile("xoo", "one-issue-per-line");
- SonarScanner runner = configureRunner("shared/xoo-sample");
- runner.setProjectKey("sample/project");
- runner.setProperty("sonar.analysis.mode", "issues");
- BuildResult result = orchestrator.executeBuild(runner);
+ SonarScanner scanner = configureScanner("shared/xoo-sample");
+ scanner.setProjectKey("sample/project");
+ scanner.setProperty("sonar.analysis.mode", "issues");
+ BuildResult result = orchestrator.executeBuild(scanner);
assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17);
}
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
- SonarScanner runner = configureRunner("shared/xoo-sample", "sonar.verbose", "true");
+ SonarScanner runner = configureScanner("shared/xoo-sample", "sonar.verbose", "true");
BuildResult result = orchestrator.executeBuild(runner);
List<Issue> serverIssues = ItUtils.getAllServerIssues(orchestrator);
for (Issue i : serverIssues) {
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules");
// do it again, scanning nothing (all files should be unchanged)
- runner = configureRunnerIssues("shared/xoo-sample", null,
+ runner = configureScannerIssues("shared/xoo-sample", null,
"sonar.verbose", "true");
result = orchestrator.executeBuild(runner);
assertThat(result.getLogs()).contains("Scanning only changed files");
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
- SonarScanner runner = configureRunner("shared/xoo-sample", "sonar.verbose", "true");
+ SonarScanner runner = configureScanner("shared/xoo-sample", "sonar.verbose", "true");
BuildResult result = orchestrator.executeBuild(runner);
List<Issue> serverIssues = ItUtils.getAllServerIssues(orchestrator);
for (Issue i : serverIssues) {
issueClient.doTransition(serverIssues.get(1).key(), "wontfix");
// do it again, scanning nothing (all files should be unchanged)
- runner = configureRunnerIssues("shared/xoo-sample", null,
+ runner = configureScannerIssues("shared/xoo-sample", null,
"sonar.verbose", "true");
result = orchestrator.executeBuild(runner);
assertThat(result.getLogs()).contains("Scanning only changed files");
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
- SonarScanner runner = configureRunner("shared/xoo-sample", "sonar.verbose", "true");
- BuildResult result = orchestrator.executeBuild(runner);
+ SonarScanner scanner = configureScanner("shared/xoo-sample", "sonar.verbose", "true");
+ BuildResult result = orchestrator.executeBuild(scanner);
// change QP
restoreProfile("with-many-rules.xml");
FileUtils.write(srcFile, "\n", StandardCharsets.UTF_8, true);
// scan again, with different QP
- runner = SonarScanner.create(tmpProjectDir,
+ scanner = SonarScanner.create(tmpProjectDir,
"sonar.working.directory", temp.newFolder().getAbsolutePath(),
"sonar.analysis.mode", "issues",
"sonar.report.export.path", "sonar-report.json",
"sonar.userHome", temp.newFolder().getAbsolutePath(),
"sonar.verbose", "true",
"sonar.scanChangedFilesOnly", "true");
- result = orchestrator.executeBuild(runner);
+ result = orchestrator.executeBuild(scanner);
assertThat(result.getLogs()).contains("Scanning only changed files");
assertThat(result.getLogs()).doesNotContain("'One Issue Per Line' skipped because there is no related file in current project");
ItUtils.assertIssuesInJsonReport(result, 3, 0, 17);
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "empty");
- SonarScanner runner = configureRunner("shared/xoo-sample",
+ SonarScanner runner = configureScanner("shared/xoo-sample",
"sonar.verbose", "true",
"sonar.analysis.mode", "issues",
"sonar.profile", "one-issue-per-line");
orchestrator.getServer().provisionProject("sample", "xoo-sample-with-spaces");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules");
- SonarScanner runner = configureRunner("analysis/xoo-sample-with-spaces/v2");
+ SonarScanner runner = configureScanner("analysis/xoo-sample-with-spaces/v2");
orchestrator.executeBuild(runner);
assertThat(getComponent(orchestrator, "sample:my sources/main/xoo/sample/My Sample.xoo")).isNotNull();
- runner = configureRunnerIssues("analysis/xoo-sample-with-spaces/v2", null);
+ runner = configureScannerIssues("analysis/xoo-sample-with-spaces/v2", null);
BuildResult result = orchestrator.executeBuild(runner);
// Analysis is not persisted in database
assertThat(getComponent(orchestrator, "com.sonarsource.it.samples:simple-sample")).isNull();
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules");
// First real scan with source
- SonarScanner runner = configureRunner("shared/xoo-history-v2");
+ SonarScanner runner = configureScanner("shared/xoo-history-v2");
orchestrator.executeBuild(runner);
assertThat(getComponent(orchestrator, "sample:src/main/xoo/sample/ClassAdded.xoo")).isNotNull();
// Second scan should remove ClassAdded.xoo
- runner = configureRunner("shared/xoo-history-v1");
+ runner = configureScanner("shared/xoo-history-v1");
orchestrator.executeBuild(runner);
assertThat(getComponent(orchestrator, "sample:src/main/xoo/sample/ClassAdded.xoo")).isNull();
// Re-add ClassAdded.xoo in local workspace
- runner = configureRunnerIssues("shared/xoo-history-v2", null);
+ runner = configureScannerIssues("shared/xoo-history-v2", null);
BuildResult result = orchestrator.executeBuild(runner);
assertThat(getComponent(orchestrator, "sample:src/main/xoo/sample/ClassAdded.xoo")).isNull();
@Test
public void should_fail_if_plugin_access_secured_properties() throws IOException {
// Test access from task (ie BatchSettings)
- SonarScanner runner = configureRunnerIssues("shared/xoo-sample", null,
+ SonarScanner runner = configureScannerIssues("shared/xoo-sample", null,
"accessSecuredFromTask", "true");
BuildResult result = orchestrator.executeBuildQuietly(runner);
+ "The SonarQube plugin which requires this property must be deactivated in issues mode.");
// Test access from sensor (ie ModuleSettings)
- runner = configureRunnerIssues("shared/xoo-sample", null,
+ runner = configureScannerIssues("shared/xoo-sample", null,
"accessSecuredFromSensor", "true");
result = orchestrator.executeBuildQuietly(runner);
File homeDir = runFirstAnalysisAndFlagIssueAsWontFix();
// Second issues mode using same cache dir but cache disabled by default
- SonarScanner runner = configureRunnerIssues("shared/xoo-sample", homeDir);
+ SonarScanner runner = configureScannerIssues("shared/xoo-sample", homeDir);
BuildResult result = orchestrator.executeBuild(runner);
// False positive is not returned
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
// First run (publish mode)
- SonarScanner runner = configureRunner("shared/xoo-sample");
+ SonarScanner runner = configureScanner("shared/xoo-sample");
orchestrator.executeBuild(runner);
// First issues mode
File homeDir = temp.newFolder();
- runner = configureRunnerIssues("shared/xoo-sample", homeDir);
+ runner = configureScannerIssues("shared/xoo-sample", homeDir);
BuildResult result = orchestrator.executeBuild(runner);
// 17 issues
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
// First run (publish mode)
- SonarScanner runner = configureRunner("shared/xoo-sample");
+ SonarScanner runner = configureScanner("shared/xoo-sample");
orchestrator.executeBuild(runner);
SonarClient client = orchestrator.getServer().adminWsClient();
client.issueClient().assign(issue.key(), "julien");
// Issues
- runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.login", "julien", "sonar.password", "password");
+ runner = configureScannerIssues("shared/xoo-sample", null, "sonar.login", "julien", "sonar.password", "password");
BuildResult result = orchestrator.executeBuild(runner);
JSONObject obj = ItUtils.getJSONReport(result);
// use same working dir, because lock file is in it
String workDirPath = temp.newFolder().getAbsolutePath();
- SonarScanner runner = configureRunner("shared/xoo-sample",
+ SonarScanner runner = configureScanner("shared/xoo-sample",
"sonar.working.directory", workDirPath);
orchestrator.executeBuild(runner);
List<Callable<BuildResult>> tasks = new ArrayList<>();
final File homeDir = temp.newFolder();
for (int i = 0; i < nThreads; i++) {
- tasks.add(new Callable<BuildResult>() {
-
- public BuildResult call() throws Exception {
- SonarScanner runner = configureRunnerIssues("shared/xoo-sample", homeDir,
- "sonar.it.enableWaitingSensor", "true",
- "sonar.working.directory", workDirPath);
- return orchestrator.executeBuild(runner);
- }
+ tasks.add(() -> {
+ SonarScanner scanner = configureScannerIssues("shared/xoo-sample", homeDir,
+ "sonar.it.enableWaitingSensor", "true",
+ "sonar.working.directory", workDirPath);
+ return orchestrator.executeBuild(scanner);
});
}
ItUtils.restoreProfile(orchestrator, getClass().getResource("/analysis/IssuesModeTest/" + fileName));
}
- private SonarScanner configureRunnerIssues(String projectDir, @Nullable File homeDir, String... props) throws IOException {
+ private SonarScanner configureScannerIssues(String projectDir, @Nullable File homeDir, String... props) throws IOException {
SonarScanner scanner = SonarScanner.create(ItUtils.projectDir(projectDir),
"sonar.working.directory", temp.newFolder().getAbsolutePath(),
"sonar.analysis.mode", "issues",
return scanner;
}
- private SonarScanner configureRunner(String projectDir, String... props) throws IOException {
- SonarScanner runner = SonarScanner.create(ItUtils.projectDir(projectDir),
+ private SonarScanner configureScanner(String projectDir, String... props) throws IOException {
+ SonarScanner scanner = SonarScanner.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;
+ scanner.setProperties(props);
+ return scanner;
}
private void setDefaultQualityProfile(String languageKey, String profileName) {
- orchestrator.getServer().adminWsClient().post("api/qualityprofiles/set_default",
- "language", languageKey,
- "profileName", profileName);
+ tester.wsClient().wsConnector().call(new PostRequest("api/qualityprofiles/set_default")
+ .setParam("language", languageKey)
+ .setParam("profileName", profileName));
}
}
import java.io.IOException;
import java.util.Map;
import org.apache.commons.io.FileUtils;
-import org.junit.Assume;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.tests.Category3Suite;
import org.sonarqube.ws.client.component.SearchWsRequest;
import util.ItUtils;
import static util.ItUtils.getComponentNavigation;
import static util.ItUtils.getMeasureAsDouble;
import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
-import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.resetSettings;
-import static util.ItUtils.setServerProperty;
public class ScannerTest {
public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR;
@Rule
- public ExpectedException thrown = ExpectedException.none();
+ public TemporaryFolder temp = new TemporaryFolder();
@Rule
- public TemporaryFolder temp = new TemporaryFolder();
+ public Tester tester = new Tester(orchestrator).disableOrganizations();
@Before
- public void deleteData() {
- orchestrator.resetData();
+ public void setUp() {
ItUtils.restoreProfile(orchestrator, getClass().getResource("/analysis/BatchTest/one-issue-per-line.xml"));
}
scan("shared/xoo-multi-modules-sample");
scan("shared/xoo-multi-modules-sample", "sonar.branch", "branch/0.x");
- assertThat(newAdminWsClient(orchestrator).components().search(new SearchWsRequest().setQualifiers(singletonList("TRK"))).getComponentsList()).hasSize(2);
+ assertThat(tester.wsClient().components().search(new SearchWsRequest().setQualifiers(singletonList("TRK"))).getComponentsList()).hasSize(2);
assertThat(getComponent(orchestrator, "com.sonarsource.it.samples:multi-modules-sample").getName()).isEqualTo("Sonar :: Integration Tests :: Multi-modules Sample");
assertThat(getComponent(orchestrator, "com.sonarsource.it.samples:multi-modules-sample:branch/0.x").getName())
.isEqualTo("Sonar :: Integration Tests :: Multi-modules Sample branch/0.x");
assertThat(result.getLogs()).doesNotContain(moduleBKey + ":" + propKey);
// Set property only on root project
- setServerProperty(orchestrator, rootModuleKey, propKey, "project");
+ tester.settings().setProjectSetting(rootModuleKey, propKey, "project");
result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", propKey);
assertThat(result.getLogs()).contains(moduleBKey + ":" + propKey + " = project");
// Override property on moduleB
- setServerProperty(orchestrator, moduleBKey, propKey, "moduleB");
+ tester.settings().setProjectSetting(moduleBKey, propKey, "moduleB");
result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", propKey);
String moduleBKey = rootModuleKey + ":module_b";
// Set property on provisioned project
- setServerProperty(orchestrator, rootModuleKey, propKey, "project");
+ tester.settings().setProjectSetting(rootModuleKey, propKey, "project");
BuildResult result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", propKey);
File cache = new File(userHome, "cache");
assertThat(cache).exists().isDirectory();
- int cachedFiles = FileUtils.listFiles(cache, new String[] {"jar"}, true).size();
+ int cachedFiles = FileUtils.listFiles(cache, new String[]{"jar"}, true).size();
assertThat(cachedFiles).isGreaterThan(5);
assertThat(result.getLogs()).contains("User cache: " + cache.getAbsolutePath());
assertThat(result.getLogs()).contains("Download sonar-xoo-plugin-");
public void should_display_project_url_after_analysis() throws IOException {
orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "Sonar :: Integration Tests :: Multi-modules Sample");
orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "one-issue-per-line");
- Assume.assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("3.6"));
BuildResult result = scan("shared/xoo-multi-modules-sample");
assertThat(result.getLogs()).contains("/dashboard/index/com.sonarsource.it.samples:multi-modules-sample:mybranch");
- try {
- setServerProperty(orchestrator, null, "sonar.core.serverBaseURL", "http://foo:123/sonar");
- result = scan("shared/xoo-multi-modules-sample");
- assertThat(result.getLogs()).contains("http://foo:123/sonar/dashboard/index/com.sonarsource.it.samples:multi-modules-sample");
- } finally {
- resetSettings(orchestrator, null, "sonar.core.serverBaseURL");
- }
+ tester.settings().setGlobalSettings("sonar.core.serverBaseURL", "http://foo:123/sonar");
+ result = scan("shared/xoo-multi-modules-sample");
+ assertThat(result.getLogs()).contains("http://foo:123/sonar/dashboard/index/com.sonarsource.it.samples:multi-modules-sample");
}
/**
}
private SonarScanner configureScanner(String projectPath, String... props) {
- SonarScanner scanner = SonarScanner.create(ItUtils.projectDir(projectPath))
+ return SonarScanner.create(ItUtils.projectDir(projectPath))
.setProperties(props);
- return scanner;
}
}