case "$CATEGORY_GROUP" in
Category1)
CATEGORY=Category1 && runCategory
+ CATEGORY=measure && runCategory
CATEGORY=source && runCategory
;;
* <li>clean-up of users between tests</li>
* <li>clean-up of session when opening a browser (cookies, local storage)</li>
* <li>quick access to {@link WsClient} instances</li>
+ * <li>clean-up of defined settings. Properties that are not defined by a plugin are not reset.</li>
* <li>helpers to generate organizations and users</li>
* </ul>
- * <p>
+ *
* Recommendation is to define a {@code @Rule} instance. If not possible, then
* {@code @ClassRule} must be used through a {@link org.junit.rules.RuleChain}
* around {@link Orchestrator}.
+ *
+ * Not supported:
+ * <ul>
+ * <li>clean-up global settings</li>
+ * <li>clean-up system administrators/roots</li>
+ * <li>clean-up default organization</li>
+ * <li>clean-up the properties that are not defined (no PropertyDefinition)</li>
+ * </ul>
*/
public class Tester extends ExternalResource implements TesterSession {
return service().create(request.build()).getUser();
}
+ /**
+ * For standalone mode only
+ */
@SafeVarargs
public final User generateAdministrator(Consumer<CreateRequest.Builder>... populators) {
User user = generate(populators);
@SafeVarargs
public final User generateAdministrator(Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
+ String organizationKey = organization.getKey();
User user = generate(populators);
- session.wsClient().organizations().addMember(organization.getKey(), user.getLogin());
+ session.wsClient().organizations().addMember(organizationKey, user.getLogin());
session.wsClient().userGroups().addUser(AddUserWsRequest.builder()
- .setOrganization(organization.getKey())
+ .setOrganization(organizationKey)
.setLogin(user.getLogin())
.setName("Owners")
.build());
return user;
}
+ @SafeVarargs
+ public final User generateAdministratorOnDefaultOrganization(Consumer<CreateRequest.Builder>... populators) {
+ User user = generate(populators);
+ session.wsClient().organizations().addMember("default-organization", user.getLogin());
+ session.wsClient().userGroups().addUser(AddUserWsRequest.builder()
+ .setOrganization("default-organization")
+ .setLogin(user.getLogin())
+ .setName("sonar-administrators")
+ .build());
+ return user;
+ }
+
@SafeVarargs
public final User generateMember(Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
User user = generate(populators);
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
+import com.codeborne.selenide.WebDriverRunner;
import org.openqa.selenium.Keys;
+import org.openqa.selenium.interactions.Actions;
public class MeasuresPage {
public MeasuresPage() {
}
public MeasuresPage backShortcut() {
- Selenide.$(".layout-page-header-panel").sendKeys(Keys.LEFT);
+ SelenideElement panel = Selenide.$(".layout-page-header-panel");
+
+ // panel.sendKeys(Keys.LEFT) does not work correctly on Chrome
+ // The workaround is to use Actions
+ // https://bugs.chromium.org/p/chromedriver/issues/detail?id=35
+ Actions actions = new Actions(WebDriverRunner.getWebDriver());
+ actions.moveToElement(panel);
+ actions.click();
+ actions.sendKeys(Keys.LEFT);
+ actions.build().perform();
return this;
}
import org.sonarqube.tests.authorisation.PermissionSearchTest;
import org.sonarqube.tests.authorisation.ProvisioningPermissionTest;
import org.sonarqube.tests.authorisation.QualityProfileAdminPermissionTest;
-import org.sonarqube.tests.complexity.ComplexityMeasuresTest;
-import org.sonarqube.tests.customMeasure.CustomMeasuresTest;
-import org.sonarqube.tests.measure.DifferentialPeriodsTest;
-import org.sonarqube.tests.measure.MeasuresWsTest;
-import org.sonarqube.tests.measure.ProjectMeasuresPageTest;
-import org.sonarqube.tests.measure.SincePreviousVersionHistoryTest;
-import org.sonarqube.tests.measure.SinceXDaysHistoryTest;
-import org.sonarqube.tests.measure.TimeMachineTest;
import org.sonarqube.tests.projectAdministration.BackgroundTasksTest;
import org.sonarqube.tests.projectAdministration.ProjectAdministrationTest;
import org.sonarqube.tests.projectAdministration.ProjectBulkDeletionPageTest;
PermissionSearchTest.class,
ProvisioningPermissionTest.class,
QualityProfileAdminPermissionTest.class,
- // custom measure
- CustomMeasuresTest.class,
// measure
- ProjectMeasuresPageTest.class,
- ProjectsPageTest.class,
- MeasuresWsTest.class,
- // measure history
- DifferentialPeriodsTest.class,
- SincePreviousVersionHistoryTest.class,
- SinceXDaysHistoryTest.class,
- TimeMachineTest.class,
- // complexity
- ComplexityMeasuresTest.class
+ ProjectsPageTest.class
})
public class Category1Suite {
import org.sonarqube.tests.analysis.ScannerTest;
import org.sonarqube.tests.analysis.SettingsEncryptionTest;
import org.sonarqube.tests.analysis.TempFolderTest;
-import org.sonarqube.tests.measure.DecimalScaleMetricTest;
import org.sonarqube.tests.plugins.VersionPluginTest;
import org.sonarqube.tests.webhook.WebhooksTest;
SSLTest.class,
FavoriteTest.class,
RedirectTest.class,
- // measures
- DecimalScaleMetricTest.class,
WebhooksTest.class
})
public class Category3Suite {
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonarqube.tests.complexity;
-
-import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category1Suite;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
-import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
-import static util.ItUtils.projectDir;
-
-// TODO complete the test with other complexity metrics
-public class ComplexityMeasuresTest {
-
- private static final String PROJECT = "com.sonarsource.it.samples:multi-modules-sample";
- private static final String MODULE = "com.sonarsource.it.samples:multi-modules-sample:module_a";
- private static final String SUB_MODULE = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1";
- private static final String DIRECTORY = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1:src/main/xoo/com/sonar/it/samples/modules/a1";
- private static final String FILE = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1:src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo";
-
- private static final String COMPLEXITY_METRIC = "complexity";
- private static final String COGNITIVE_COMPLEXITY_METRIC = "cognitive_complexity";
-
- @ClassRule
- public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
-
- @BeforeClass
- public static void inspectProject() {
- orchestrator.resetData();
- orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-multi-modules-sample")));
- }
-
- @Test
- public void compute_complexity_metrics_on_file() {
- assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, FILE, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
- entry(COMPLEXITY_METRIC, 3d),
- entry(COGNITIVE_COMPLEXITY_METRIC, 4d));
- }
-
- @Test
- public void compute_complexity_metrics_on_directory() {
- assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, DIRECTORY, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
- entry(COMPLEXITY_METRIC, 3d),
- entry(COGNITIVE_COMPLEXITY_METRIC, 4d));
- }
-
- @Test
- public void compute_complexity_metrics_on_sub_module() {
- assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, SUB_MODULE, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
- entry(COMPLEXITY_METRIC, 3d),
- entry(COGNITIVE_COMPLEXITY_METRIC, 4d));
- }
-
- @Test
- public void compute_complexity_metrics_on_module() {
- assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, MODULE, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
- entry(COMPLEXITY_METRIC, 7d),
- entry(COGNITIVE_COMPLEXITY_METRIC, 9d));
- }
-
- @Test
- public void compute_complexity_metrics_on_project() {
- assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, PROJECT, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
- entry(COMPLEXITY_METRIC, 13d),
- entry(COGNITIVE_COMPLEXITY_METRIC, 17d));
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonarqube.tests.customMeasure;
-
-import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category1Suite;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import util.ItUtils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static util.ItUtils.projectDir;
-
-public class CustomMeasuresTest {
-
- private static final String PROJECT_KEY = "sample";
-
- @ClassRule
- public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
-
- @Before
- public void deleteProjects() {
- orchestrator.resetData();
- }
-
- @Test
- public void custom_measures_should_be_integrated_during_project_analysis() {
- analyzeProject();
- setBurnedBudget(1200.3);
- setTeamSize(4);
-
- assertThat(getMeasureAsDouble("team_size")).isNull();
- assertThat(getMeasureAsDouble("burned_budget")).isNull();
-
- analyzeProject();
-
- assertThat(getMeasureAsDouble("burned_budget")).isEqualTo(1200.3);
- assertThat(getMeasureAsDouble("team_size")).isEqualTo(4d);
- }
-
- @Test
- public void should_update_value() {
- analyzeProject();
- setTeamSize(4);
- analyzeProject();
- updateTeamSize(15);
- assertThat(getMeasureAsDouble("team_size")).isEqualTo(4d);
- analyzeProject();// the value is available when the project is analyzed again
- assertThat(getMeasureAsDouble("team_size")).isEqualTo(15d);
- }
-
- @Test
- public void should_delete_custom_measure() {
- analyzeProject();
- setTeamSize(4);
- analyzeProject();
- deleteCustomMeasure("team_size");
- assertThat(getMeasureAsDouble("team_size")).isEqualTo(4d);// the value is still available. It will be removed during next
- // analyzed
-
- analyzeProject();
- assertThat(getMeasureAsDouble("team_size")).isNull();
- }
-
- private void analyzeProject() {
- orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
- }
-
- private void setTeamSize(int i) {
- orchestrator.getServer().adminWsClient().post("api/custom_measures/create", "projectKey", PROJECT_KEY, "metricKey", "team_size", "value", String.valueOf(i));
- }
-
- private void updateTeamSize(int i) {
- String response = orchestrator.getServer().adminWsClient().get("api/custom_measures/search", "projectKey", PROJECT_KEY, "metricKey", "team_size");
- Matcher jsonObjectMatcher = Pattern.compile(".*?\"id\"\\s*:\\s*\"(.*?)\".*", Pattern.MULTILINE).matcher(response);
- jsonObjectMatcher.find();
- String customMeasureId = jsonObjectMatcher.group(1);
- orchestrator.getServer().adminWsClient().post("api/custom_measures/update", "id", customMeasureId, "value", String.valueOf(i));
- }
-
- private void setBurnedBudget(double d) {
- orchestrator.getServer().adminWsClient().post("api/custom_measures/create", "projectKey", PROJECT_KEY, "metricKey", "burned_budget", "value", String.valueOf(d));
- }
-
- private void deleteCustomMeasure(String metricKey) {
- String response = orchestrator.getServer().adminWsClient().get("api/custom_measures/search", "projectKey", PROJECT_KEY, "metricKey", metricKey);
- Matcher jsonObjectMatcher = Pattern.compile(".*?\"id\"\\s*:\\s*\"(.*?)\".*", Pattern.MULTILINE).matcher(response);
- jsonObjectMatcher.find();
- String customMeasureId = jsonObjectMatcher.group(1);
- orchestrator.getServer().adminWsClient().post("api/custom_measures/delete", "id", customMeasureId);
- }
-
- private Double getMeasureAsDouble(String metricKey) {
- return ItUtils.getMeasureAsDouble(orchestrator, PROJECT_KEY, metricKey);
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonarqube.tests.measure;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.sonarqube.qa.util.Tester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
+import static util.ItUtils.projectDir;
+
+// TODO complete the test with other complexity metrics
+public class ComplexityMeasuresTest {
+
+ private static final String PROJECT = "com.sonarsource.it.samples:multi-modules-sample";
+ private static final String MODULE = "com.sonarsource.it.samples:multi-modules-sample:module_a";
+ private static final String SUB_MODULE = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1";
+ private static final String DIRECTORY = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1:src/main/xoo/com/sonar/it/samples/modules/a1";
+ private static final String FILE = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1:src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo";
+ private static final String COMPLEXITY_METRIC = "complexity";
+ private static final String COGNITIVE_COMPLEXITY_METRIC = "cognitive_complexity";
+
+ @ClassRule
+ public static Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
+
+ private static Tester tester = new Tester(orchestrator);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester);
+
+ @BeforeClass
+ public static void inspectProject() {
+ orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-multi-modules-sample")));
+ }
+
+ @Test
+ public void compute_complexity_metrics_on_file() {
+ assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, FILE, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
+ entry(COMPLEXITY_METRIC, 3d),
+ entry(COGNITIVE_COMPLEXITY_METRIC, 4d));
+ }
+
+ @Test
+ public void compute_complexity_metrics_on_directory() {
+ assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, DIRECTORY, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
+ entry(COMPLEXITY_METRIC, 3d),
+ entry(COGNITIVE_COMPLEXITY_METRIC, 4d));
+ }
+
+ @Test
+ public void compute_complexity_metrics_on_sub_module() {
+ assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, SUB_MODULE, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
+ entry(COMPLEXITY_METRIC, 3d),
+ entry(COGNITIVE_COMPLEXITY_METRIC, 4d));
+ }
+
+ @Test
+ public void compute_complexity_metrics_on_module() {
+ assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, MODULE, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
+ entry(COMPLEXITY_METRIC, 7d),
+ entry(COGNITIVE_COMPLEXITY_METRIC, 9d));
+ }
+
+ @Test
+ public void compute_complexity_metrics_on_project() {
+ assertThat(getMeasuresAsDoubleByMetricKey(orchestrator, PROJECT, COMPLEXITY_METRIC, COGNITIVE_COMPLEXITY_METRIC)).containsOnly(
+ entry(COMPLEXITY_METRIC, 13d),
+ entry(COGNITIVE_COMPLEXITY_METRIC, 17d));
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonarqube.tests.measure;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
+import util.ItUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.projectDir;
+
+public class CustomMeasuresTest {
+
+ private static final String PROJECT_KEY = "sample";
+
+ @ClassRule
+ public static Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
+
+ @Rule
+ public Tester tester = new Tester(orchestrator);
+
+ @Test
+ public void custom_measures_should_be_integrated_during_project_analysis() {
+ analyzeProject();
+ setBurnedBudget(1200.3);
+ setTeamSize(4);
+
+ assertThat(getMeasureAsDouble("team_size")).isNull();
+ assertThat(getMeasureAsDouble("burned_budget")).isNull();
+
+ analyzeProject();
+
+ assertThat(getMeasureAsDouble("burned_budget")).isEqualTo(1200.3);
+ assertThat(getMeasureAsDouble("team_size")).isEqualTo(4d);
+ }
+
+ @Test
+ public void should_update_value() {
+ analyzeProject();
+ setTeamSize(4);
+ analyzeProject();
+ updateTeamSize(15);
+ assertThat(getMeasureAsDouble("team_size")).isEqualTo(4d);
+ analyzeProject();// the value is available when the project is analyzed again
+ assertThat(getMeasureAsDouble("team_size")).isEqualTo(15d);
+ }
+
+ @Test
+ public void should_delete_custom_measure() {
+ analyzeProject();
+ setTeamSize(4);
+ analyzeProject();
+ deleteCustomMeasure("team_size");
+ assertThat(getMeasureAsDouble("team_size")).isEqualTo(4d);// the value is still available. It will be removed during next
+ // analyzed
+
+ analyzeProject();
+ assertThat(getMeasureAsDouble("team_size")).isNull();
+ }
+
+ private void analyzeProject() {
+ orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
+ }
+
+ private void setTeamSize(int i) {
+ PostRequest postRequest = new PostRequest("api/custom_measures/create")
+ .setParam("projectKey", PROJECT_KEY)
+ .setParam("metricKey", "team_size")
+ .setParam("value", String.valueOf(i));
+ tester.wsClient().wsConnector().call(postRequest);
+ }
+
+ private void updateTeamSize(int i) {
+ GetRequest getRequest = new GetRequest("api/custom_measures/search")
+ .setParam("projectKey", PROJECT_KEY)
+ .setParam("metricKey", "team_size");
+ String response = tester.wsClient().wsConnector().call(getRequest).content();
+ Matcher jsonObjectMatcher = Pattern.compile(".*?\"id\"\\s*:\\s*\"(.*?)\".*", Pattern.MULTILINE).matcher(response);
+ jsonObjectMatcher.find();
+ String customMeasureId = jsonObjectMatcher.group(1);
+ PostRequest postRequest = new PostRequest("api/custom_measures/update")
+ .setParam("id", customMeasureId)
+ .setParam("value", String.valueOf(i));
+ tester.wsClient().wsConnector().call(postRequest);
+ }
+
+ private void setBurnedBudget(double d) {
+ PostRequest postRequest = new PostRequest("api/custom_measures/create")
+ .setParam("projectKey", PROJECT_KEY)
+ .setParam("metricKey", "burned_budget")
+ .setParam("value", String.valueOf(d));
+ tester.wsClient().wsConnector().call(postRequest);
+ }
+
+ private void deleteCustomMeasure(String metricKey) {
+ GetRequest getRequest = new GetRequest("api/custom_measures/search")
+ .setParam("projectKey", PROJECT_KEY)
+ .setParam("metricKey", metricKey);
+ String response = tester.wsClient().wsConnector().call(getRequest).content();
+ Matcher jsonObjectMatcher = Pattern.compile(".*?\"id\"\\s*:\\s*\"(.*?)\".*", Pattern.MULTILINE).matcher(response);
+ jsonObjectMatcher.find();
+ String customMeasureId = jsonObjectMatcher.group(1);
+
+ PostRequest postRequest = new PostRequest("api/custom_measures/delete")
+ .setParam("id", customMeasureId);
+ tester.wsClient().wsConnector().call(postRequest);
+ }
+
+ private Double getMeasureAsDouble(String metricKey) {
+ return ItUtils.getMeasureAsDouble(orchestrator, PROJECT_KEY, metricKey);
+ }
+}
package org.sonarqube.tests.measure;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category3Suite;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
import util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
* Requires the plugin "batch-plugin"
*/
@ClassRule
- public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
+
+ @Rule
+ public Tester tester = new Tester(orchestrator);
@Test
public void override_decimal_scale_of_numeric_metric() {
package org.sonarqube.tests.measure;
import com.sonar.orchestrator.Orchestrator;
-import org.sonarqube.tests.Category1Suite;
import java.util.Date;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.ws.client.WsClient;
-import org.sonarqube.qa.util.pageobjects.Navigation;
+import org.sonarqube.qa.util.Tester;
import util.ItUtils;
-import util.user.UserRule;
import static org.apache.commons.lang.time.DateUtils.addDays;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.formatDate;
import static util.ItUtils.getLeakPeriodValue;
import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
-import static util.ItUtils.newAdminWsClient;
-import static util.ItUtils.resetPeriod;
import static util.ItUtils.runProjectAnalysis;
-import static util.ItUtils.setServerProperty;
public class DifferentialPeriodsTest {
- static final String PROJECT_KEY = "sample";
- static final String MULTI_MODULE_PROJECT_KEY = "com.sonarsource.it.samples:multi-modules-sample";
-
- static WsClient CLIENT;
+ private static final String PROJECT_KEY = "sample";
+ private static final String MULTI_MODULE_PROJECT_KEY = "com.sonarsource.it.samples:multi-modules-sample";
@ClassRule
- public static final Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ public static final Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
@Rule
- public UserRule userRule = UserRule.from(orchestrator);
-
- private String adminUser;
-
- @BeforeClass
- public static void createWsClient() throws Exception {
- CLIENT = newAdminWsClient(orchestrator);
- }
-
- @Before
- public void cleanUpAnalysisData() {
- orchestrator.resetData();
- adminUser = userRule.createAdminUser();
- }
-
- @After
- public void reset() throws Exception {
- resetPeriod(orchestrator);
- }
+ public Tester tester = new Tester(orchestrator);
/**
* SONAR-7093
orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
// Set a global property and a project property to ensure project property is used
- setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
- setServerProperty(orchestrator, PROJECT_KEY, "sonar.leak.period", "30");
+ tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
+ tester.settings().setProjectSetting(PROJECT_KEY, "sonar.leak.period", "30");
// Execute an analysis in the past to have a past snapshot without any issues
orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "empty");
assertThat(getLeakPeriodValue(orchestrator, PROJECT_KEY, "violations")).isEqualTo(17);
// Check on ui that it's possible to define leak period on project
- Navigation.create(orchestrator).openHome().logIn().submitCredentials(adminUser).openSettings("sample")
+ tester.wsClient().users().skipOnboardingTutorial();
+ tester.openBrowser().openHome().logIn().submitCredentials("admin", "admin").openSettings("sample")
.assertSettingDisplayed("sonar.leak.period");
}
@Test
public void ensure_differential_measures_are_computed_when_adding_new_component_after_period() throws Exception {
orchestrator.getServer().provisionProject(MULTI_MODULE_PROJECT_KEY, MULTI_MODULE_PROJECT_KEY);
- setServerProperty(orchestrator, MULTI_MODULE_PROJECT_KEY, "sonar.leak.period", "30");
+ tester.settings().setProjectSetting(MULTI_MODULE_PROJECT_KEY, "sonar.leak.period", "30");
// Execute an analysis 60 days ago without module b
orchestrator.getServer().associateProjectToQualityProfile(MULTI_MODULE_PROJECT_KEY, "xoo", "empty");
@Test
public void compute_no_new_lines_measures_when_changes_but_no_scm() throws Exception {
orchestrator.getServer().provisionProject(MULTI_MODULE_PROJECT_KEY, MULTI_MODULE_PROJECT_KEY);
- setServerProperty(orchestrator, MULTI_MODULE_PROJECT_KEY, "sonar.leak.period", "previous_version");
+ tester.settings().setProjectSetting(MULTI_MODULE_PROJECT_KEY, "sonar.leak.period", "previous_version");
// Execute an analysis 60 days ago without module b
orchestrator.getServer().associateProjectToQualityProfile(MULTI_MODULE_PROJECT_KEY, "xoo", "empty");
public void compute_zero_new_lines_measures_when_no_changes_and_scm_available() throws Exception {
String projectKey = "sample-scm";
orchestrator.getServer().provisionProject(projectKey, projectKey);
- setServerProperty(orchestrator, projectKey, "sonar.leak.period", "previous_version");
+ tester.settings().setProjectSetting(projectKey, "sonar.leak.period", "previous_version");
// Execute an analysis 60 days ago
runProjectAnalysis(orchestrator, "scm/xoo-sample-with-scm", "sonar.projectDate", formatDate(addDays(new Date(), -60)),
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonarqube.tests.measure;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+import static util.ItUtils.pluginArtifact;
+import static util.ItUtils.xooPlugin;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ ComplexityMeasuresTest.class,
+ CustomMeasuresTest.class,
+ DecimalScaleMetricTest.class,
+ DifferentialPeriodsTest.class,
+ MeasuresWsTest.class,
+ ProjectDashboardTest.class,
+ ProjectMeasuresPageTest.class,
+ SincePreviousVersionHistoryTest.class,
+ SinceXDaysHistoryTest.class,
+ TimeMachineTest.class
+})
+public class MeasureSuite {
+
+ @ClassRule
+ public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+ // reduce memory for Elasticsearch
+ .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m")
+
+ .addPlugin(xooPlugin())
+
+ // used by DecimalScaleMetricTest
+ .addPlugin(pluginArtifact("batch-plugin"))
+
+ .build();
+
+}
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category1Suite;
import java.util.List;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsMeasures;
import org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse;
import org.sonarqube.ws.WsMeasures.ComponentWsResponse;
-import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.measure.ComponentTreeWsRequest;
import org.sonarqube.ws.client.measure.ComponentWsRequest;
-import util.ItUtils;
import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.projectDir;
-import static util.ItUtils.setServerProperty;
public class MeasuresWsTest {
- @ClassRule
- public static final Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
private static final String FILE_KEY = "sample:src/main/xoo/sample/Sample.xoo";
private static final String DIR_KEY = "sample:src/main/xoo/sample";
- WsClient wsClient;
- @BeforeClass
- public static void initPeriod() throws Exception {
- setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
- }
+ @ClassRule
+ public static final Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
- @AfterClass
- public static void resetPeriod() throws Exception {
- ItUtils.resetPeriod(orchestrator);
- }
+ @Rule
+ public Tester tester = new Tester(orchestrator);
@Before
- public void inspectProject() {
- orchestrator.resetData();
-
- wsClient = ItUtils.newAdminWsClient(orchestrator);
+ public void setUp() {
+ tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
}
@Test
public void component_tree() {
scanXooSample();
- ComponentTreeWsResponse response = wsClient.measures().componentTree(new ComponentTreeWsRequest()
- .setBaseComponentKey("sample")
+ ComponentTreeWsResponse response = tester.wsClient().measures().componentTree(new ComponentTreeWsRequest()
+ .setComponent("sample")
.setMetricKeys(singletonList("ncloc"))
- .setAdditionalFields(newArrayList("metrics", "periods")));
+ .setAdditionalFields(asList("metrics", "periods")));
assertThat(response).isNotNull();
assertThat(response.getBaseComponent().getKey()).isEqualTo("sample");
}
/**
- * @see SONAR-7958
+ * SONAR-7958
*/
@Test
public void component_tree_supports_module_move_down() {
}
/**
- * @see SONAR-7958
+ * SONAR-7958
*/
@Test
public void component_tree_supports_module_move_up() {
}
private void verifyComponentTreeWithChildren(String baseComponentKey, String... childKeys) {
- ComponentTreeWsResponse response = wsClient.measures().componentTree(new ComponentTreeWsRequest()
- .setBaseComponentKey(baseComponentKey)
+ ComponentTreeWsResponse response = tester.wsClient().measures().componentTree(new ComponentTreeWsRequest()
+ .setComponent(baseComponentKey)
.setMetricKeys(singletonList("ncloc"))
.setStrategy("children"));
public void component() {
scanXooSample();
- ComponentWsResponse response = wsClient.measures().component(new ComponentWsRequest()
- .setComponentKey("sample")
+ ComponentWsResponse response = tester.wsClient().measures().component(new ComponentWsRequest()
+ .setComponent("sample")
.setMetricKeys(singletonList("ncloc"))
.setAdditionalFields(newArrayList("metrics", "periods")));
import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.Keys;
-import org.sonarqube.qa.util.pageobjects.Navigation;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.qa.util.pageobjects.ProjectDashboardPage;
-import org.sonarqube.tests.Category1Suite;
import org.sonarqube.ws.client.PostRequest;
-import org.sonarqube.ws.client.WsClient;
-import util.user.UserRule;
import static com.codeborne.selenide.Condition.exist;
-import static com.codeborne.selenide.Condition.hasText;
import static com.codeborne.selenide.Condition.text;
-import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.projectDir;
import static util.selenium.Selenese.runSelenese;
public class ProjectDashboardTest {
@ClassRule
- public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
@Rule
- public UserRule userRule = UserRule.from(orchestrator);
+ public Tester tester = new Tester(orchestrator);
- private Navigation nav = Navigation.create(orchestrator);
-
- private static WsClient wsClient;
private String adminUser;
@Before
public void setUp() throws Exception {
- wsClient = newAdminWsClient(orchestrator);
- orchestrator.resetData();
- adminUser = userRule.createAdminUser();
+ adminUser = tester.users().generateAdministratorOnDefaultOrganization().getLogin();
}
@Test
public void display_size() {
executeBuild("shared/xoo-sample", "sample", "Sample");
- ProjectDashboardPage page = Navigation.create(orchestrator).openProjectDashboard("sample");
+ ProjectDashboardPage page = tester.openBrowser().openProjectDashboard("sample");
- page.getLinesOfCode().should(hasText("13"));
- page.getLanguageDistribution().should(hasText("Xoo"), hasText("13"));
+ page.getLinesOfCode().should(text("13"));
+ page.getLanguageDistribution().should(text("Xoo"), text("13"));
}
@Test
executeBuild("shared/xoo-sample", "sample", "Sample");
// Add some tags to the project
- wsClient.wsConnector().call(
+ tester.wsClient().wsConnector().call(
new PostRequest("api/project_tags/set")
.setParam("project", "sample")
.setParam("tags", "foo,bar,baz"));
- ProjectDashboardPage page = Navigation.create(orchestrator).openProjectDashboard("sample");
+ ProjectDashboardPage page = tester.openBrowser().openProjectDashboard("sample");
page
.shouldHaveTags("foo", "bar", "baz")
.shouldNotBeEditable();
public void display_tags_with_edit() {
executeBuild("shared/xoo-sample", "sample-with-tags", "Sample with tags");
// Add some tags to another project to have them in the list
- wsClient.wsConnector().call(
+ tester.wsClient().wsConnector().call(
new PostRequest("api/project_tags/set")
.setParam("project", "sample-with-tags")
.setParam("tags", "foo,bar,baz"));
executeBuild("shared/xoo-sample", "sample", "Sample");
- ProjectDashboardPage page = nav.logIn().submitCredentials(adminUser).openProjectDashboard("sample");
+ ProjectDashboardPage page = tester.openBrowser().logIn().submitCredentials(adminUser).openProjectDashboard("sample");
page
.shouldHaveTags("No tags")
.shouldBeEditable()
page
.shouldHaveTags("foo")
.sendKeysToTagsInput("test")
- .getTagAtIdx(0).should(hasText("+ test")).click();
+ .getTagAtIdx(0).should(text("+ test")).click();
page
.shouldHaveTags("foo", "test")
- .getTagAtIdx(1).should(hasText("test"));
+ .getTagAtIdx(1).should(text("test"));
page
.sendKeysToTagsInput(Keys.ENTER)
.shouldHaveTags("test");
public void display_project_activity_shortcut() {
executeBuild("shared/xoo-sample", "sample-with-tags", "Sample with tags");
// Add some tags to another project to have them in the list
- wsClient.wsConnector().call(
+ tester.wsClient().wsConnector().call(
new PostRequest("api/project_tags/set")
.setParam("project", "sample-with-tags")
.setParam("tags", "foo,bar,baz"));
executeBuild("shared/xoo-sample", "sample", "Sample");
- ProjectDashboardPage page = nav.logIn().submitCredentials(adminUser).openProjectDashboard("sample");
+ ProjectDashboardPage page = tester.openBrowser()
+ .logIn()
+ .submitCredentials(adminUser)
+ .openProjectDashboard("sample");
page.getOverviewMeasure("Debt").$(".overview-domain-measure-history-link").should(exist);
}
@Test
public void display_a_nice_error_when_requesting_unknown_project() {
- nav.open("/dashboard/index?id=unknown");
+ tester.openBrowser().open("/dashboard/index?id=unknown");
Selenide.$("#nonav").should(text("The requested project does not exist. Either it has never been analyzed successfully or it has been deleted."));
// TODO verify that on global homepage
}
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
-import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.ClassRule;
-import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.qa.util.pageobjects.Navigation;
import org.sonarqube.qa.util.pageobjects.measures.MeasureContent;
import org.sonarqube.qa.util.pageobjects.measures.MeasuresPage;
-import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.qa.util.Tester;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
public class ProjectMeasuresPageTest {
+ private static final String PROJECT_KEY = "project-measures-page-test-project";
+
@ClassRule
- public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
- @Rule
- public Tester tester = new Tester(orchestrator).disableOrganizations();
+ private static Tester tester = new Tester(orchestrator);
- private static String projectKey = "project-measures-page-test-project";
+ @ClassRule
+ public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester);
- @Before
- public void inspectProject() {
+ @BeforeClass
+ public static void setUp() {
orchestrator.executeBuild(
SonarScanner
.create(projectDir("shared/xoo-sample"))
- .setProperty("sonar.projectKey", projectKey)
+ .setProperty("sonar.projectKey", PROJECT_KEY)
.setProperty("sonar.projectName", "ProjectMeasuresPageTest Project"));
// one more time
orchestrator.executeBuild(
SonarScanner
.create(projectDir("shared/xoo-sample"))
- .setProperty("sonar.projectKey", projectKey)
+ .setProperty("sonar.projectKey", PROJECT_KEY)
.setProperty("sonar.projectName", "ProjectMeasuresPageTest Project"));
}
@Test
public void should_display_measures_page() {
- MeasuresPage page = tester.openBrowser().openProjectMeasures(projectKey);
+ MeasuresPage page = tester.openBrowser().openProjectMeasures(PROJECT_KEY);
page
.displayBubbleChart("Risk")
.openFacet("Maintainability")
@Test
public void should_drilldown_on_list_view() {
- MeasuresPage page = tester.openBrowser().openProjectMeasures(projectKey);
+ MeasuresPage page = tester.openBrowser().openProjectMeasures(PROJECT_KEY);
MeasureContent content = page
.openFacet("Size").openMeasureContent("ncloc");
content
@Test
public void should_drilldown_on_tree_view() {
- MeasuresPage page = tester.openBrowser().openProjectMeasures(projectKey);
+ MeasuresPage page = tester.openBrowser().openProjectMeasures(PROJECT_KEY);
MeasureContent content = page
.openFacet("Size").openMeasureContent("ncloc");
page.switchView("tree");
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category1Suite;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.Nullable;
import org.apache.commons.lang.time.DateUtils;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
-import util.ItUtils;
+import org.sonarqube.qa.util.Tester;
import static java.lang.Integer.parseInt;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.getLeakPeriodValue;
import static util.ItUtils.getMeasureWithVariation;
import static util.ItUtils.projectDir;
-import static util.ItUtils.setServerProperty;
public class SincePreviousVersionHistoryTest {
- private static final String PROJECT = "com.sonarsource.it.samples:multi-modules-sample";
- @ClassRule
- public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
-
- @BeforeClass
- public static void initPeriod() throws Exception {
- setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
- }
-
- @AfterClass
- public static void resetPeriod() throws Exception {
- ItUtils.resetPeriod(orchestrator);
- }
-
- private static void analyzeProject(String version) {
- analyzeProject(version, null, null);
- }
-
- private static void analyzeProjectWithExclusions(String version, String exclusions) {
- analyzeProject(version, exclusions, null);
- }
-
- private static void analyzeProjectWithDate(String version, String date) {
- analyzeProject(version, null, date);
- }
+ private static final String PROJECT_KEY = "com.sonarsource.it.samples:multi-modules-sample";
- private static void analyzeProject(String version, @Nullable String exclusions, @Nullable String date) {
- SonarScanner build = SonarScanner.create(projectDir("shared/xoo-multi-modules-sample"))
- .setProperties("sonar.projectVersion", version);
- if (exclusions != null) {
- build.setProperties("sonar.exclusions", exclusions);
- }
- if (date != null) {
- build.setProperty("sonar.projectDate", date);
- }
- orchestrator.executeBuild(build);
- }
+ @ClassRule
+ public static Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
- public static String toStringDate(Date date) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- return sdf.format(date);
- }
+ @Rule
+ public Tester tester = new Tester(orchestrator);
@Before
- public void resetData() throws Exception {
- orchestrator.resetData();
+ public void setUp() throws Exception {
+ tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
}
/**
analyzeProject("1.0-SNAPSHOT");
analyzeProject("1.0-SNAPSHOT");
- Measure measure = getMeasureWithVariation(orchestrator, PROJECT, "files");
+ Measure measure = getMeasureWithVariation(orchestrator, PROJECT_KEY, "files");
// There are 4 files
assertThat(parseInt(measure.getValue())).isEqualTo(4);
// Analyze project by excluding some files
analyzeProject("1.0-SNAPSHOT", "**/*2.xoo", toStringDate(DateUtils.addDays(now, -2)));
// No difference measure after first analysis
- assertThat(getLeakPeriodValue(orchestrator, PROJECT, "files")).isNull();
+ assertThat(getLeakPeriodValue(orchestrator, PROJECT_KEY, "files")).isNull();
analyzeProjectWithDate("1.0-SNAPSHOT", toStringDate(DateUtils.addDays(now, -1)));
// No new version, first analysis is used -> 2 new files
- assertThat(getLeakPeriodValue(orchestrator, PROJECT, "files")).isEqualTo(2);
+ assertThat(getLeakPeriodValue(orchestrator, PROJECT_KEY, "files")).isEqualTo(2);
analyzeProjectWithDate("1.0-SNAPSHOT", toStringDate(now));
// Still no new version, first analysis is used -> 2 new files
- assertThat(getLeakPeriodValue(orchestrator, PROJECT, "files")).isEqualTo(2);
+ assertThat(getLeakPeriodValue(orchestrator, PROJECT_KEY, "files")).isEqualTo(2);
+ }
+
+
+ private static void analyzeProject(String version) {
+ analyzeProject(version, null, null);
+ }
+
+ private static void analyzeProjectWithExclusions(String version, String exclusions) {
+ analyzeProject(version, exclusions, null);
+ }
+
+ private static void analyzeProjectWithDate(String version, String date) {
+ analyzeProject(version, null, date);
}
+ private static void analyzeProject(String version, @Nullable String exclusions, @Nullable String date) {
+ SonarScanner build = SonarScanner.create(projectDir("shared/xoo-multi-modules-sample"))
+ .setProperties("sonar.projectVersion", version);
+ if (exclusions != null) {
+ build.setProperties("sonar.exclusions", exclusions);
+ }
+ if (date != null) {
+ build.setProperty("sonar.projectDate", date);
+ }
+ orchestrator.executeBuild(build);
+ }
+
+ private static String toStringDate(Date date) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ return sdf.format(date);
+ }
}
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category1Suite;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.Nullable;
import org.apache.commons.lang.time.DateUtils;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsMeasures;
import util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.getMeasureWithVariation;
import static util.ItUtils.projectDir;
-import static util.ItUtils.setServerProperty;
public class SinceXDaysHistoryTest {
+ private static final String PROJECT = "multi-files-sample";
+
@ClassRule
- public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
- private static final String PROJECT = "multi-files-sample";
+ private static Tester tester = new Tester(orchestrator);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester);
@BeforeClass
public static void analyseProjectWithHistory() {
- initPeriod();
+ tester.settings().setGlobalSettings("sonar.leak.period", "30");
- orchestrator.resetData();
ItUtils.restoreProfile(orchestrator, SinceXDaysHistoryTest.class.getResource("/measure/one-issue-per-line-profile.xml"));
orchestrator.getServer().provisionProject(PROJECT, PROJECT);
orchestrator.getServer().associateProjectToQualityProfile(PROJECT, "xoo", "one-issue-per-line");
analyzeProject();
}
- private static void initPeriod() {
- setServerProperty(orchestrator, "sonar.leak.period", "30");
- }
-
- @AfterClass
- public static void resetPeriods() throws Exception {
- ItUtils.resetPeriod(orchestrator);
- }
-
@Test
public void check_files_variation() throws Exception {
checkMeasure("files", 3);
package org.sonarqube.tests.measure;
import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarScanner;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
-import org.sonarqube.tests.Category1Suite;
+import org.junit.rules.RuleChain;
+import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.WsMeasures.Measure;
import org.sonarqube.ws.WsMeasures.SearchHistoryResponse;
import org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryValue;
-import org.sonarqube.ws.client.measure.MeasuresService;
import org.sonarqube.ws.client.measure.SearchHistoryRequest;
import util.ItUtils;
import util.ItUtils.ComponentNavigation;
import static util.ItUtils.getComponentNavigation;
import static util.ItUtils.getMeasuresByMetricKey;
import static util.ItUtils.getMeasuresWithVariationsByMetricKey;
-import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.projectDir;
-import static util.ItUtils.setServerProperty;
public class TimeMachineTest {
- private static final String PROJECT = "sample";
+ private static final String PROJECT_KEY = "sample";
@ClassRule
- public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
- private static MeasuresService wsMeasures;
+ public static Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR;
+
+ private static Tester tester = new Tester(orchestrator);
+
+ @ClassRule
+ public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester);
@BeforeClass
- public static void initialize() {
- orchestrator.resetData();
- initPeriod();
+ public static void setUp() {
+ tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
ItUtils.restoreProfile(orchestrator, TimeMachineTest.class.getResource("/measure/one-issue-per-line-profile.xml"));
orchestrator.getServer().provisionProject("sample", "Sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
String aMonthAgo = formatDate(addDays(now, -30));
analyzeProject("measure/xoo-history-v1", aMonthAgo);
analyzeProject("measure/xoo-history-v2", yesterday);
-
- wsMeasures = newAdminWsClient(orchestrator).measures();
- }
-
- private static void initPeriod() {
- setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
- }
-
- @AfterClass
- public static void resetPeriod() throws Exception {
- ItUtils.resetPeriod(orchestrator);
- }
-
- private static BuildResult analyzeProject(String path, String date) {
- return orchestrator.executeBuild(SonarScanner.create(projectDir(path), "sonar.projectDate", date));
}
@Test
public void projectIsAnalyzed() {
- ComponentNavigation component = getComponentNavigation(orchestrator, PROJECT);
+ ComponentNavigation component = getComponentNavigation(orchestrator, PROJECT_KEY);
assertThat(component.getVersion()).isEqualTo("1.0-SNAPSHOT");
}
public void noDataForInterval() {
Date now = new Date();
- SearchHistoryResponse response = wsMeasures.searchHistory(SearchHistoryRequest.builder()
- .setComponent(PROJECT)
+ SearchHistoryResponse response = tester.wsClient().measures().searchHistory(SearchHistoryRequest.builder()
+ .setComponent(PROJECT_KEY)
.setMetrics(singletonList("lines"))
.setFrom(formatDate(now))
.setTo(formatDate(now))
*/
@Test
public void measure_variations_are_only_meaningful_when_additional_fields_contains_periods() {
- Map<String, Measure> measures = getMeasuresWithVariationsByMetricKey(orchestrator, PROJECT, "violations", "new_violations");
+ Map<String, Measure> measures = getMeasuresWithVariationsByMetricKey(orchestrator, PROJECT_KEY, "violations", "new_violations");
assertThat(measures.get("violations")).isNotNull();
assertThat(measures.get("new_violations")).isNotNull();
SearchHistoryResponse response = searchHistory("new_violations");
assertThat(response.getMeasures(0).getHistoryCount()).isGreaterThan(0);
- measures = getMeasuresByMetricKey(orchestrator, PROJECT, "violations", "new_violations");
+ measures = getMeasuresByMetricKey(orchestrator, PROJECT_KEY, "violations", "new_violations");
assertThat(measures.get("violations")).isNotNull();
assertThat(measures.get("new_violations")).isNull();
}
+ private static void analyzeProject(String path, String date) {
+ orchestrator.executeBuild(SonarScanner.create(projectDir(path), "sonar.projectDate", date));
+ }
+
private static SearchHistoryResponse searchHistory(String... metrics) {
- return wsMeasures.searchHistory(SearchHistoryRequest.builder()
- .setComponent(PROJECT)
+ return tester.wsClient().measures().searchHistory(SearchHistoryRequest.builder()
+ .setComponent(PROJECT_KEY)
.setMetrics(Arrays.asList(metrics))
.build());
}