}
private void runSampleProjectAnalysis(String projectVersion, String... properties) {
- ItUtils.runProjectAnalysis(
- NewDebtRatioMeasureTest.orchestrator,
- "measure/xoo-new-debt-ratio-" + projectVersion,
- ItUtils.concat(properties,
- // disable standard scm support so that it does not interfere with Xoo Scm sensor
- "sonar.scm.disabled", "false")
- );
+ ItUtils.runVerboseProjectAnalysis(
+ NewDebtRatioMeasureTest.orchestrator,
+ "measure/xoo-new-debt-ratio-" + projectVersion,
+ ItUtils.concat(properties,
+ // disable standard scm support so that it does not interfere with Xoo Scm sensor
+ "sonar.scm.disabled", "false")
+ );
}
private Resource getFileResourceWithVariations(String metricKey) {
}
private void runSampleProjectAnalysis(String... properties) {
- ItUtils.runProjectAnalysis(TechnicalDebtMeasureVariationTest.orchestrator, "shared/xoo-sample", properties);
+ ItUtils.runVerboseProjectAnalysis(TechnicalDebtMeasureVariationTest.orchestrator, "shared/xoo-sample", properties);
}
private Resource getSampleProjectResourceWithVariations(String metricKey) {
package issue.suite;
import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.locator.FileLocation;
import java.util.List;
import org.junit.BeforeClass;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueQuery;
+import static issue.suite.IssueTestSuite.searchIssues;
import static org.assertj.core.api.Assertions.assertThat;
-import static util.ItUtils.projectDir;
+import static util.ItUtils.runProjectAnalysis;
public class CommonRulesTest {
orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/issue/suite/CommonRulesTest/xoo-common-rules-profile.xml"));
orchestrator.getServer().provisionProject("common-rules-project", "Sample");
orchestrator.getServer().associateProjectToQualityProfile("common-rules-project", "xoo", "xoo-common-rules");
- SonarRunner analysis = SonarRunner.create(projectDir("issue/common-rules"),
+ runProjectAnalysis(orchestrator, "issue/common-rules",
"sonar.cpd.xoo.minimumTokens", "2",
"sonar.cpd.xoo.minimumLines", "2");
- orchestrator.executeBuild(analysis);
}
@Test
}
private List<Issue> findIssues(String componentKey, String ruleKey) {
- return orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create().components(componentKey).rules(ruleKey)).list();
+ return searchIssues(IssueQuery.create().components(componentKey).rules(ruleKey));
}
}
package issue.suite;
import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.locator.FileLocation;
import java.util.List;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.issue.Issue;
-import org.sonar.wsclient.issue.IssueQuery;
-import util.ItUtils;
+import static issue.suite.IssueTestSuite.searchIssues;
import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.runProjectAnalysis;
public class CustomRulesTest {
orchestrator.getServer().provisionProject("sample", "Sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "Custom");
- orchestrator.executeBuild(SonarRunner.create().setProjectDir(ItUtils.projectDir("shared/xoo-sample")));
+ runProjectAnalysis(orchestrator, "shared/xoo-sample");
- List<Issue> issues = orchestrator.getServer().adminWsClient().issueClient().find(IssueQuery.create()).list();
+ List<Issue> issues = searchIssues();
assertThat(issues).hasSize(1);
Issue issue = issues.get(0);
import java.util.List;
import org.junit.Before;
import org.junit.ClassRule;
-import org.junit.Ignore;
import org.junit.Test;
import org.sonar.wsclient.base.HttpException;
import org.sonar.wsclient.issue.ActionPlan;
import static issue.suite.IssueTestSuite.ORCHESTRATOR;
import static issue.suite.IssueTestSuite.adminIssueClient;
-import static issue.suite.IssueTestSuite.issueClient;
import static issue.suite.IssueTestSuite.search;
import static issue.suite.IssueTestSuite.searchIssueByKey;
import static issue.suite.IssueTestSuite.searchIssues;
import static issue.suite.IssueTestSuite.searchRandomIssue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
-import static util.ItUtils.projectDir;
+import static util.ItUtils.runProjectAnalysis;
import static util.ItUtils.toDate;
import static util.ItUtils.verifyHttpException;
orchestrator.getServer().provisionProject("sample", "Sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "xoo-one-issue-per-line-profile");
- scan = SonarRunner.create(projectDir("shared/xoo-sample"));
- orchestrator.executeBuild(scan);
+ scan = runProjectAnalysis(orchestrator, "shared/xoo-sample");
issue = searchRandomIssue();
}
assertThat(comment.createdAt()).isNotNull();
// reload issue
- Issue reloaded = searchIssueByKey(issue.key());
+ Issue reloaded = searchIssues(issue.key(), true).iterator().next();
assertThat(reloaded.comments()).hasSize(1);
assertThat(reloaded.comments().get(0).key()).isEqualTo(comment.key());
assertThat(issues.users()).isEmpty();
adminIssueClient().assign(issue.key(), "admin");
- assertThat(search(IssueQuery.create().assignees("admin")).list()).hasSize(1);
+ assertThat(searchIssues(IssueQuery.create().assignees("admin"))).hasSize(1);
orchestrator.executeBuild(scan);
Issue reloaded = searchIssueByKey(issue.key());
adminIssueClient().assign(issue.key(), null);
reloaded = searchIssueByKey(issue.key());
assertThat(reloaded.assignee()).isNull();
- assertThat(issueClient().find(IssueQuery.create().assignees("admin")).list()).isEmpty();
+ assertThat(searchIssues(IssueQuery.create().assignees("admin"))).isEmpty();
}
/**
adminIssueClient().doAction(issue.key(), "fake");
// reload issue
- Issue reloaded = searchIssueByKey(issue.key());
+ Issue reloaded = searchIssues(issue.key(), true).iterator().next();
assertThat(reloaded.comments()).hasSize(1);
assertThat(reloaded.comments().get(0).htmlText()).isEqualTo("New Comment from fake action");
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.locator.FileLocation;
import java.util.List;
import org.junit.Before;
import org.sonar.wsclient.issue.BulkChange;
import org.sonar.wsclient.issue.BulkChangeQuery;
import org.sonar.wsclient.issue.Issue;
-import org.sonar.wsclient.issue.IssueClient;
-import org.sonar.wsclient.issue.IssueQuery;
import org.sonar.wsclient.issue.NewActionPlan;
import util.ItUtils;
import static issue.suite.IssueTestSuite.ORCHESTRATOR;
+import static issue.suite.IssueTestSuite.adminIssueClient;
+import static issue.suite.IssueTestSuite.issueClient;
import static org.assertj.core.api.Assertions.assertThat;
-import static util.ItUtils.projectDir;
+import static util.ItUtils.runProjectAnalysis;
/**
* SONAR-4421
BulkChange bulkChange = buldChangeAssigneeOfIssues(issueKeys, "admin");
assertThat(bulkChange.totalIssuesChanged()).isEqualTo(BULK_EDITED_ISSUE_COUNT);
- for (Issue issue : searchIssues(issueKeys)) {
+ for (Issue issue : IssueTestSuite.searchIssues(issueKeys)) {
assertThat(issue.assignee()).isEqualTo("admin");
}
}
);
assertThat(bulkChange.totalIssuesChanged()).isEqualTo(BULK_EDITED_ISSUE_COUNT);
- for (Issue issue : searchIssues(issueKeys)) {
+ for (Issue issue : IssueTestSuite.searchIssues(issueKeys)) {
assertThat(issue.actionPlan()).isEqualTo(newActionPlan.key());
}
}
);
assertThat(bulkChange.totalIssuesChanged()).isEqualTo(BULK_EDITED_ISSUE_COUNT);
- for (Issue issue : searchIssues(issueKeys, true)) {
+ for (Issue issue : IssueTestSuite.searchIssues(issueKeys, true)) {
assertThat(issue.comments()).hasSize(1);
assertThat(issue.comments().get(0).htmlText()).isEqualTo(COMMENT_AS_HTML);
}
);
assertThat(bulkChange.totalIssuesChanged()).isEqualTo(BULK_EDITED_ISSUE_COUNT);
- for (Issue issue : searchIssues(issueKeys, true)) {
+ for (Issue issue : IssueTestSuite.searchIssues(issueKeys, true)) {
assertThat(issue.status()).isEqualTo("CONFIRMED");
assertThat(issue.assignee()).isEqualTo("admin");
assertThat(issue.severity()).isEqualTo(newSeverity);
String[] issueKeys = searchIssueKeys(nbIssues);
// Confirm an issue
- adminIssueClient().doTransition(searchIssues().iterator().next().key(), "confirm");
+ adminIssueClient().doTransition(IssueTestSuite.searchIssues().iterator().next().key(), "confirm");
// Apply a bulk change on unconfirm transition
BulkChangeQuery query = (BulkChangeQuery.create()
assertThat(bulkChange.totalIssuesChanged()).isEqualTo(1);
int nbIssuesWithComment = 0;
- for (Issue issue : searchIssues(issueKeys, true)) {
+ for (Issue issue : IssueTestSuite.searchIssues(issueKeys, true)) {
if (!issue.comments().isEmpty()) {
nbIssuesWithComment++;
}
orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/issue/suite/IssueBulkChangeTest/one-issue-per-line-profile.xml"));
orchestrator.getServer().provisionProject("sample", "Sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
- orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample")));
+ runProjectAnalysis(orchestrator, "shared/xoo-sample");
}
private static void assertIssueSeverity(String[] issueKeys, String expectedSeverity) {
- for (Issue issue : searchIssues(issueKeys)) {
+ for (Issue issue : IssueTestSuite.searchIssues(issueKeys)) {
assertThat(issue.severity()).isEqualTo(expectedSeverity);
}
}
private static void assertIssueStatus(String[] issueKeys, String expectedStatus) {
- for (Issue issue : searchIssues(issueKeys)) {
+ for (Issue issue : IssueTestSuite.searchIssues(issueKeys)) {
assertThat(issue.status()).isEqualTo(expectedStatus);
}
}
.toArray(String.class);
}
- private static List<Issue> searchIssues(String... issueKeys) {
- return searchIssues(issueKeys, false);
- }
-
- private static List<Issue> searchIssues(String[] issueKeys, boolean withComments) {
- IssueQuery query = IssueQuery.create().issues(issueKeys);
- if (withComments) {
- query.urlParams().put("additionalFields", "comments");
- }
- return searchIssues(query);
- }
-
- private static List<Issue> searchIssues() {
- return searchIssues(IssueQuery.create());
- }
-
private static String[] searchIssueKeys(int limit) {
- return getIssueKeys(searchIssues(), limit);
- }
-
- private static List<Issue> searchIssues(IssueQuery issueQuery) {
- return issueClient().find(issueQuery).list();
- }
-
- private static IssueClient issueClient() {
- return orchestrator.getServer().wsClient().issueClient();
- }
-
- private static IssueClient adminIssueClient() {
- return orchestrator.getServer().adminWsClient().issueClient();
+ return getIssueKeys(IssueTestSuite.searchIssues(), limit);
}
private static ActionPlanClient adminActionPlanClient() {
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueChange;
import org.sonar.wsclient.issue.IssueChangeDiff;
-import org.sonar.wsclient.issue.IssueClient;
import org.sonar.wsclient.issue.IssueQuery;
import static issue.suite.IssueTestSuite.ORCHESTRATOR;
+import static issue.suite.IssueTestSuite.adminIssueClient;
+import static issue.suite.IssueTestSuite.issueClient;
import static org.assertj.core.api.Assertions.assertThat;
-import static util.ItUtils.projectDir;
+import static util.ItUtils.runProjectAnalysis;
public class IssueChangelogTest {
orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/issue/suite/IssueChangelogTest/one-issue-per-line-profile.xml"));
orchestrator.getServer().provisionProject("sample", "Sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
- scan = SonarRunner.create(projectDir("shared/xoo-sample"));
- orchestrator.executeBuild(scan);
+ scan = runProjectAnalysis(orchestrator, "shared/xoo-sample");
issue = searchRandomIssue();
}
return issueClient().changes(issueKey);
}
- private static IssueClient issueClient() {
- return orchestrator.getServer().wsClient().issueClient();
- }
-
- private static IssueClient adminIssueClient() {
- return orchestrator.getServer().adminWsClient().issueClient();
- }
}
return issueClient().find(issueQuery);
}
- static List<Issue> searchIssues(IssueQuery issueQuery) {
- return search(issueQuery).list();
- }
-
static Issue searchIssueByKey(String issueKey) {
List<Issue> issues = searchIssues(IssueQuery.create().issues(issueKey));
assertThat(issues).hasSize(1);
return issues.get(0);
}
+ static List<Issue> searchIssues(String... issueKeys) {
+ return searchIssues(issueKeys, false);
+ }
+
+ static List<Issue> searchIssues(String issueKey, boolean withComments) {
+ return searchIssues(new String[] { issueKey }, withComments);
+ }
+
+ static List<Issue> searchIssues(String[] issueKeys, boolean withComments) {
+ IssueQuery query = IssueQuery.create().issues(issueKeys);
+ if (withComments) {
+ query.urlParams().put("additionalFields", "comments");
+ }
+ return searchIssues(query);
+ }
+
+ static List<Issue> searchIssues() {
+ return searchIssues(IssueQuery.create());
+ }
+
+ static List<Issue> searchIssues(IssueQuery issueQuery) {
+ return issueClient().find(issueQuery).list();
+ }
}
* mailto:contact AT sonarsource DOT com
*/
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarRunner;
+import com.sonar.orchestrator.locator.FileLocation;
+import java.io.File;
+import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-import com.sonar.orchestrator.locator.FileLocation;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import org.sonar.wsclient.base.HttpException;
+import org.sonar.wsclient.services.PropertyDeleteQuery;
+import org.sonar.wsclient.services.PropertyUpdateQuery;
import static com.google.common.collect.FluentIterable.from;
import static java.util.Arrays.asList;
-import static org.assertj.core.api.Assertions.fail;
-
import static org.assertj.core.api.Assertions.assertThat;
-import org.apache.commons.io.FileUtils;
-import org.sonar.wsclient.base.HttpException;
+import static org.assertj.core.api.Assertions.fail;
public class ItUtils {
/**
* Locate the pom file of a sample project
*
- * @param relativePath project path related to the directory it/it-projects, for example "qualitygate/xoo-sample"
+ * @param projectName project path related to the directory it/it-projects, for example "qualitygate/xoo-sample"
*/
public static File projectPom(String projectName) {
File pom = new File(projectDir(projectName), "pom.xml");
return count;
}
- public static void runProjectAnalysis(Orchestrator orchestrator, String projectRelativePath, String... properties) {
+ public static SonarRunner runVerboseProjectAnalysis(Orchestrator orchestrator, String projectRelativePath, String... properties) {
+ return runProjectAnalysis(orchestrator, projectRelativePath, true, properties);
+ }
+
+ public static SonarRunner runProjectAnalysis(Orchestrator orchestrator, String projectRelativePath, String... properties) {
+ return runProjectAnalysis(orchestrator, projectRelativePath, false, properties);
+ }
+
+ private static SonarRunner runProjectAnalysis(Orchestrator orchestrator, String projectRelativePath, boolean enableDebugLogs, String... properties) {
SonarRunner sonarRunner = SonarRunner.create(projectDir(projectRelativePath));
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
- for (int i = 0; i < properties.length; i+=2) {
- builder.put(properties[i], properties[i+1]);
+ for (int i = 0; i < properties.length; i += 2) {
+ builder.put(properties[i], properties[i + 1]);
+ }
+ SonarRunner scan = sonarRunner.setDebugLogs(enableDebugLogs).setProperties(builder.build());
+ orchestrator.executeBuild(scan);
+ return scan;
+ }
+
+ public static void setServerProperty(Orchestrator orchestrator, String key, @Nullable String value) {
+ if (value == null) {
+ orchestrator.getServer().getAdminWsClient().delete(new PropertyDeleteQuery(key));
+ } else {
+ orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery().setKey(key).setValue(value));
}
- orchestrator.executeBuild(sonarRunner.setDebugLogs(true).setProperties(builder.build()));
}
/**
* Concatenates a vararg to a String array.
*
- * Useful when using {@link #runProjectAnalysis(Orchestrator, String, String...)}, eg.:
+ * Useful when using {@link #runVerboseProjectAnalysis(Orchestrator, String, String...)}, eg.:
* <pre>
* ItUtils.runProjectAnalysis(orchestrator, "project_name",
* ItUtils.concat(properties, "sonar.scm.disabled", "false")