]> source.dussan.org Git - sonarqube.git/commitdiff
Add category qualityModel to integration tests
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sat, 11 Nov 2017 15:57:30 +0000 (16:57 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Tue, 14 Nov 2017 12:10:17 +0000 (13:10 +0100)
15 files changed:
cix.sh
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QModelTester.java [new file with mode: 0644]
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/Tester.java
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/TesterSession.java
tests/src/test/java/org/sonarqube/tests/Category2Suite.java
tests/src/test/java/org/sonarqube/tests/qualityModel/DebtConfigurationRule.java [deleted file]
tests/src/test/java/org/sonarqube/tests/qualityModel/MaintainabilityMeasureTest.java
tests/src/test/java/org/sonarqube/tests/qualityModel/MaintainabilityRatingMeasureTest.java
tests/src/test/java/org/sonarqube/tests/qualityModel/NewDebtRatioMeasureTest.java
tests/src/test/java/org/sonarqube/tests/qualityModel/QualityModelSuite.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/qualityModel/ReliabilityMeasureTest.java
tests/src/test/java/org/sonarqube/tests/qualityModel/SecurityMeasureTest.java
tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtAndIssueNewMeasuresTest.java
tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtInIssueChangelogTest.java
tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtTest.java

diff --git a/cix.sh b/cix.sh
index 61f588d95dec9be9c6b78ccca5c8a71546d6f4ae..62b06de33c9fa262a23bb32426d450bff3045533 100755 (executable)
--- a/cix.sh
+++ b/cix.sh
@@ -40,6 +40,7 @@ case "$RUN_ACTIVITY" in
         Category2)
           CATEGORY=Category2 && runCategory
           CATEGORY=test && runCategory
+          CATEGORY=qualityModel && runCategory
           ;;
 
         Category3)
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QModelTester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QModelTester.java
new file mode 100644 (file)
index 0000000..e4c86b6
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.qa.util;
+
+import com.google.common.base.Joiner;
+
+import static com.google.common.base.Preconditions.checkState;
+
+public class QModelTester {
+
+  private static final String DEV_COST_PROPERTY = "sonar.technicalDebt.developmentCost";
+  private static final String RATING_GRID_PROPERTY = "sonar.technicalDebt.ratingGrid";
+  private static final String DEV_COST_LANGUAGE_PROPERTY = "languageSpecificParameters";
+  private static final String DEV_COST_LANGUAGE_NAME_PROPERTY = DEV_COST_LANGUAGE_PROPERTY + ".0.language";
+  private static final String DEV_COST_LANGUAGE_COST_PROPERTY = DEV_COST_LANGUAGE_PROPERTY + ".0.man_days";
+  private static final Joiner COMMA_JOINER = Joiner.on(",");
+
+  private final TesterSession session;
+
+  QModelTester(TesterSession session) {
+    this.session = session;
+  }
+
+  public void updateDevelopmentCost(int developmentCost) {
+    session.settings().setGlobalSettings(DEV_COST_PROPERTY, Integer.toString(developmentCost));
+  }
+
+  public void updateLanguageDevelopmentCost(String language, int developmentCost) {
+    session.settings().setGlobalSettings(DEV_COST_LANGUAGE_PROPERTY, "0");
+    session.settings().setGlobalSettings(DEV_COST_LANGUAGE_NAME_PROPERTY, language);
+    session.settings().setGlobalSettings(DEV_COST_LANGUAGE_COST_PROPERTY, Integer.toString(developmentCost));
+  }
+
+  public void updateRatingGrid(Double... ratingGrid) {
+    checkState(ratingGrid.length == 4, "Rating grid must contains 4 values");
+    session.settings().setGlobalSettings(RATING_GRID_PROPERTY, COMMA_JOINER.join(ratingGrid));
+  }
+}
index f5077ad32667fb6f4b62aa4b748f087fabeba84f..a755c60e1d3f9dbbc5a0e9e8eef96c33afa3d637 100644 (file)
@@ -177,6 +177,11 @@ public class Tester extends ExternalResource implements TesterSession {
     return rootSession.projects();
   }
 
+  @Override
+  public QModelTester qModel() {
+    return rootSession.qModel();
+  }
+
   @Override
   public QProfileTester qProfiles() {
     return rootSession.qProfiles();
@@ -228,6 +233,11 @@ public class Tester extends ExternalResource implements TesterSession {
       return new ProjectTester(this);
     }
 
+    @Override
+    public QModelTester qModel() {
+      return new QModelTester(this);
+    }
+
     @Override
     public QProfileTester qProfiles() {
       return new QProfileTester(this);
index 6c2673abcb2ea4edd392b4ab279a271815f64526..551f9662816ab67c83532a8b254f1a5111bc6bac 100644 (file)
@@ -31,6 +31,8 @@ public interface TesterSession {
 
   ProjectTester projects();
 
+  QModelTester qModel();
+
   QProfileTester qProfiles();
 
   UserTester users();
index f507e9d65b892fb41cf1f0e9a24770328baf735d..7960b0ddf0b255981eddc6e5e09e8392f8c1eb78 100644 (file)
@@ -42,14 +42,6 @@ import org.sonarqube.tests.issue.IssueTrackingTest;
 import org.sonarqube.tests.issue.IssueWorkflowTest;
 import org.sonarqube.tests.issue.IssuesPageTest;
 import org.sonarqube.tests.issue.NewIssuesMeasureTest;
-import org.sonarqube.tests.qualityModel.MaintainabilityMeasureTest;
-import org.sonarqube.tests.qualityModel.MaintainabilityRatingMeasureTest;
-import org.sonarqube.tests.qualityModel.NewDebtRatioMeasureTest;
-import org.sonarqube.tests.qualityModel.ReliabilityMeasureTest;
-import org.sonarqube.tests.qualityModel.SecurityMeasureTest;
-import org.sonarqube.tests.qualityModel.TechnicalDebtAndIssueNewMeasuresTest;
-import org.sonarqube.tests.qualityModel.TechnicalDebtInIssueChangelogTest;
-import org.sonarqube.tests.qualityModel.TechnicalDebtTest;
 import org.sonarqube.tests.rule.RulesPageTest;
 
 import static util.ItUtils.pluginArtifact;
@@ -75,16 +67,6 @@ import static util.ItUtils.xooPlugin;
   IssueWorkflowTest.class,
   NewIssuesMeasureTest.class,
   IssueCreationDateQPChangedTest.class,
-  // debt
-  MaintainabilityMeasureTest.class,
-  MaintainabilityRatingMeasureTest.class,
-  NewDebtRatioMeasureTest.class,
-  ReliabilityMeasureTest.class,
-  SecurityMeasureTest.class,
-  TechnicalDebtInIssueChangelogTest.class,
-  TechnicalDebtAndIssueNewMeasuresTest.class,
-  TechnicalDebtTest.class,
-  // ui
   IssuesPageTest.class,
   // rule
   RulesPageTest.class,
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityModel/DebtConfigurationRule.java b/tests/src/test/java/org/sonarqube/tests/qualityModel/DebtConfigurationRule.java
deleted file mode 100644 (file)
index ee46483..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.qualityModel;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableSet;
-import com.sonar.orchestrator.Orchestrator;
-import java.util.Set;
-import org.junit.rules.ExternalResource;
-
-import static com.google.common.base.Preconditions.checkState;
-import static util.ItUtils.setServerProperty;
-
-/**
- * This rule should be used when dealing with technical debt properties, in order to always be sure that the properties are correctly reset between each tests.
- */
-public class DebtConfigurationRule extends ExternalResource {
-
-  private static final String DEV_COST_PROPERTY = "sonar.technicalDebt.developmentCost";
-  private static final String RATING_GRID_PROPERTY = "sonar.technicalDebt.ratingGrid";
-
-  private static final String DEV_COST_LANGUAGE_PROPERTY = "languageSpecificParameters";
-  private static final String DEV_COST_LANGUAGE_NAME_PROPERTY = DEV_COST_LANGUAGE_PROPERTY + ".0.language";
-  private static final String DEV_COST_LANGUAGE_COST_PROPERTY = DEV_COST_LANGUAGE_PROPERTY + ".0.man_days";
-
-  private static final Joiner COMA_JOINER = Joiner.on(",");
-
-  private static final Set<String> DEV_COST_PROPERTIES = ImmutableSet.of(
-    DEV_COST_PROPERTY,
-    DEV_COST_LANGUAGE_PROPERTY,
-    DEV_COST_LANGUAGE_NAME_PROPERTY,
-    DEV_COST_LANGUAGE_COST_PROPERTY,
-    RATING_GRID_PROPERTY);
-
-  private final Orchestrator orchestrator;
-
-  private DebtConfigurationRule(Orchestrator orchestrator) {
-    this.orchestrator = orchestrator;
-  }
-
-  public static DebtConfigurationRule create(Orchestrator orchestrator) {
-    return new DebtConfigurationRule(orchestrator);
-  }
-
-  @Override
-  protected void before() throws Throwable {
-    reset();
-  }
-
-  @Override
-  protected void after() {
-    reset();
-  }
-
-  public void reset() {
-    resetDevelopmentCost();
-    resetRatingGrid();
-  }
-
-  public DebtConfigurationRule updateDevelopmentCost(int developmentCost) {
-    setProperty(DEV_COST_PROPERTY, Integer.toString(developmentCost));
-    return this;
-  }
-
-  public DebtConfigurationRule updateLanguageDevelopmentCost(String language, int developmentCost) {
-    setServerProperty(orchestrator, DEV_COST_LANGUAGE_PROPERTY, "0");
-    setServerProperty(orchestrator, DEV_COST_LANGUAGE_NAME_PROPERTY, language);
-    setServerProperty(orchestrator, DEV_COST_LANGUAGE_COST_PROPERTY, Integer.toString(developmentCost));
-    return this;
-  }
-
-  public void resetDevelopmentCost() {
-    for (String property : DEV_COST_PROPERTIES) {
-      resetProperty(property);
-    }
-  }
-
-  public DebtConfigurationRule updateRatingGrid(Double... ratingGrid) {
-    checkState(ratingGrid.length == 4, "Rating grid must contains 4 values");
-    setProperty(RATING_GRID_PROPERTY, COMA_JOINER.join(ratingGrid));
-    return this;
-  }
-
-  public DebtConfigurationRule resetRatingGrid() {
-    resetProperty(RATING_GRID_PROPERTY);
-    return this;
-  }
-
-  private void setProperty(String property, String value) {
-    setServerProperty(orchestrator, property, value);
-  }
-
-  private void resetProperty(String property) {
-    setProperty(property, null);
-  }
-
-}
index 13c310481f2a9657b05398b0084c5f9863a2c980..504e5ce031f6cc72bf3d070e325e34afb0335052 100644 (file)
@@ -21,11 +21,11 @@ package org.sonarqube.tests.qualityModel;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import org.junit.Before;
 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;
@@ -49,17 +49,15 @@ public class MaintainabilityMeasureTest {
   private static final String EFFORT_TO_REACH_MAINTAINABILITY_RATING_A_METRIC = "effort_to_reach_maintainability_rating_a";
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityModelSuite.ORCHESTRATOR;
 
   @Rule
-  public DebtConfigurationRule debtConfiguration = DebtConfigurationRule.create(orchestrator);
+  public Tester tester = new Tester(orchestrator);
 
   @Before
   public void init() {
-    orchestrator.resetData();
-
     // Set rating grid values to not depend from default value
-    debtConfiguration.updateRatingGrid(0.1d, 0.2d, 0.5d, 1d);
+    tester.qModel().updateRatingGrid(0.1d, 0.2d, 0.5d, 1d);
 
     orchestrator.getServer().provisionProject(PROJECT, PROJECT);
   }
index 01834898461c7db34929b041d98d80a0596468cb..cbd789c769a4b13db936caefb18b540498e1b828 100644 (file)
@@ -21,11 +21,11 @@ package org.sonarqube.tests.qualityModel;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import org.junit.Before;
 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;
@@ -44,17 +44,15 @@ public class MaintainabilityRatingMeasureTest {
   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";
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityModelSuite.ORCHESTRATOR;
 
   @Rule
-  public DebtConfigurationRule debtConfiguration = DebtConfigurationRule.create(orchestrator);
+  public Tester tester = new Tester(orchestrator);
 
   @Before
   public void init() {
-    orchestrator.resetData();
-
     // Set rating grid values to not depend from default value
-    debtConfiguration.updateRatingGrid(0.1d, 0.2d, 0.5d, 1d);
+    tester.qModel().updateRatingGrid(0.1d, 0.2d, 0.5d, 1d);
   }
 
   @Test
@@ -97,7 +95,7 @@ public class MaintainabilityRatingMeasureTest {
 
     assertThat(getMeasureAsDouble(orchestrator, "sample", "sqale_rating")).isEqualTo(1);
 
-    debtConfiguration.updateDevelopmentCost(2);
+    tester.qModel().updateDevelopmentCost(2);
     orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
 
     assertThat(getMeasureAsDouble(orchestrator, "sample", "sqale_rating")).isEqualTo(4);
@@ -113,7 +111,7 @@ public class MaintainabilityRatingMeasureTest {
 
     assertThat(getMeasureAsDouble(orchestrator, PROJECT, "sqale_rating")).isEqualTo(1);
 
-    debtConfiguration.updateLanguageDevelopmentCost("xoo", 1);
+    tester.qModel().updateLanguageDevelopmentCost("xoo", 1);
     orchestrator.executeBuild(
       SonarScanner.create(projectDir("shared/xoo-multi-modules-sample"))
         .setProfile("one-issue-per-line"));
@@ -131,7 +129,7 @@ public class MaintainabilityRatingMeasureTest {
 
     assertThat(getMeasureAsDouble(orchestrator, "sample", "sqale_rating")).isEqualTo(1);
 
-    debtConfiguration.updateRatingGrid(0.001d, 0.005d, 0.01d, 0.015d);
+    tester.qModel().updateRatingGrid(0.001d, 0.005d, 0.01d, 0.015d);
     orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
 
     assertThat(getMeasureAsDouble(orchestrator, "sample", "sqale_rating")).isEqualTo(5);
index 9279b40d50cf7ddff1a68a3f5d668c953c34a525..9108506122a07f51bbffe66a1a5a177fff79d997 100644 (file)
@@ -22,11 +22,10 @@ package org.sonarqube.tests.qualityModel;
 import com.sonar.orchestrator.Orchestrator;
 import java.util.Date;
 import javax.annotation.Nullable;
-import org.junit.AfterClass;
-import org.junit.Before;
 import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
-import org.sonarqube.tests.Category2Suite;
+import org.sonarqube.qa.util.Tester;
 import util.ItUtils;
 
 import static org.apache.commons.lang.time.DateUtils.addDays;
@@ -34,8 +33,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.within;
 import static util.ItUtils.formatDate;
 import static util.ItUtils.getLeakPeriodValue;
-import static util.ItUtils.resetPeriod;
-import static util.ItUtils.setServerProperty;
 import static util.ItUtils.toDate;
 
 /**
@@ -44,27 +41,19 @@ import static util.ItUtils.toDate;
 public class NewDebtRatioMeasureTest {
 
   private static final String NEW_DEBT_RATIO_METRIC_KEY = "new_sqale_debt_ratio";
-
   private static final Date FIRST_COMMIT_DATE = toDate("2016-09-01");
   private static final Date SECOND_COMMIT_DATE = toDate("2016-09-17");
   private static final Date THIRD_COMMIT_DATE = toDate("2016-09-20");
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
-
-  @AfterClass
-  public static void reset() throws Exception {
-    resetPeriod(orchestrator);
-  }
+  public static Orchestrator orchestrator = QualityModelSuite.ORCHESTRATOR;
 
-  @Before
-  public void cleanUpAnalysisData() {
-    orchestrator.resetData();
-  }
+  @Rule
+  public Tester tester = new Tester(orchestrator);
 
   @Test
   public void new_debt_ratio_is_computed_from_new_debt_and_new_ncloc_count_per_file() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
+    tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
 
     // run analysis on the day of after the first commit, with 'one-issue-per-line' profile
     defineQualityProfile("one-issue-per-line");
@@ -88,7 +77,7 @@ public class NewDebtRatioMeasureTest {
 
   @Test
   public void compute_new_debt_ratio_using_number_days_in_leak_period() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "30");
+    tester.settings().setGlobalSettings("sonar.leak.period", "30");
 
     // run analysis on the day of after the first commit, with 'one-issue-per-line' profile
     defineQualityProfile("one-issue-per-line");
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityModel/QualityModelSuite.java b/tests/src/test/java/org/sonarqube/tests/qualityModel/QualityModelSuite.java
new file mode 100644 (file)
index 0000000..c55b583
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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.qualityModel;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+import static util.ItUtils.xooPlugin;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+  MaintainabilityMeasureTest.class,
+  MaintainabilityRatingMeasureTest.class,
+  NewDebtRatioMeasureTest.class,
+  ReliabilityMeasureTest.class,
+  SecurityMeasureTest.class,
+  TechnicalDebtAndIssueNewMeasuresTest.class,
+  TechnicalDebtInIssueChangelogTest.class,
+  TechnicalDebtTest.class,
+})
+public class QualityModelSuite {
+
+  @ClassRule
+  public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+    .addPlugin(xooPlugin())
+
+    // reduce memory for Elasticsearch
+    .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m")
+
+    .build();
+
+}
index 3afaa189ea9f3cec4c84319266c2a02464d72c6e..349acb7aa46fb5e42d3616c73449255b013ca6f0 100644 (file)
@@ -21,11 +21,12 @@ package org.sonarqube.tests.qualityModel;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import java.util.Map;
 import org.junit.Before;
 import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
 import org.sonarqube.ws.WsMeasures;
 import util.ItUtils;
 
@@ -49,12 +50,13 @@ public class ReliabilityMeasureTest {
   private static final String[] METRICS = new String[] {BUGS_METRIC, RELIABILITY_RATING_METRIC, RELIABILITY_REMEDIATION_EFFORT_METRIC};
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityModelSuite.ORCHESTRATOR;
 
-  @Before
-  public void init() {
-    orchestrator.resetData();
+  @Rule
+  public Tester tester = new Tester(orchestrator);
 
+  @Before
+  public void setUp() {
     orchestrator.getServer().provisionProject(PROJECT, PROJECT);
   }
 
index 5aa1d0b1428e329d252b3fc8e01f136f05c72d4a..f8c2d6cd36701036ab949d3d59606e0b5dfe2543 100644 (file)
@@ -21,11 +21,12 @@ package org.sonarqube.tests.qualityModel;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import java.util.Map;
 import org.junit.Before;
 import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
 import org.sonarqube.ws.WsMeasures;
 import util.ItUtils;
 
@@ -49,12 +50,13 @@ public class SecurityMeasureTest {
   private static final String[] METRICS = new String[] {VULNERABILITIES_METRIC, SECURITY_REMEDIATION_EFFORT_METRIC, SECURITY_RATING_METRIC};
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityModelSuite.ORCHESTRATOR;
+
+  @Rule
+  public Tester tester = new Tester(orchestrator);
 
   @Before
   public void init() {
-    orchestrator.resetData();
-
     orchestrator.getServer().provisionProject(PROJECT, PROJECT);
   }
 
index 637a6a982b393f5910e9294ff83f313c15f0bb88..153cb9a54f6fb86c8212210a6deee1787832c700 100644 (file)
@@ -22,16 +22,14 @@ package org.sonarqube.tests.qualityModel;
 import com.sonar.orchestrator.Orchestrator;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
-import org.junit.AfterClass;
-import org.junit.Before;
 import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
-import org.sonarqube.tests.Category2Suite;
+import org.sonarqube.qa.util.Tester;
 import util.ItUtils;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static util.ItUtils.getLeakPeriodValue;
-import static util.ItUtils.setServerProperty;
 
 /**
  * SONAR-4776, SONAR-9534
@@ -41,22 +39,15 @@ public class TechnicalDebtAndIssueNewMeasuresTest {
   private static final String DATE_31_DAYS_AGO = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDate.now().minusDays(31));
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityModelSuite.ORCHESTRATOR;
 
-  @AfterClass
-  public static void resetPeriod() throws Exception {
-    ItUtils.resetPeriod(orchestrator);
-  }
-
-  @Before
-  public void cleanUpAnalysisData() {
-    orchestrator.resetData();
-  }
+  @Rule
+  public Tester tester = new Tester(orchestrator);
 
   @Test
   public void since_30_days_with_constant_effort() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "30");
-    defineQualityProfile("one-issue-per-line");
+    tester.settings().setGlobalSettings("sonar.leak.period", "30");
+    restoreQualityProfile("one-issue-per-line");
     provisionSampleProject();
 
     // Execute an analysis in the past to have a past snapshot without any issues
@@ -93,8 +84,8 @@ public class TechnicalDebtAndIssueNewMeasuresTest {
 
   @Test
   public void since_30_days_with_effort_change() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "30");
-    defineQualityProfile("one-issue-per-line");
+    tester.settings().setGlobalSettings("sonar.leak.period", "30");
+    restoreQualityProfile("one-issue-per-line");
     provisionSampleProject();
 
     // Execute an analysis in the past to have a past snapshot without any issues
@@ -131,8 +122,8 @@ public class TechnicalDebtAndIssueNewMeasuresTest {
 
   @Test
   public void since_previous_version_with_constant_effort() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
-    defineQualityProfile("one-issue-per-line");
+    tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
+    restoreQualityProfile("one-issue-per-line");
     provisionSampleProject();
 
     // Execute an analysis in the past to have a past snapshot without any issues
@@ -169,8 +160,8 @@ public class TechnicalDebtAndIssueNewMeasuresTest {
 
   @Test
   public void since_previous_version_with_effort_change() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
-    defineQualityProfile("one-issue-per-line");
+    tester.settings().setGlobalSettings( "sonar.leak.period", "previous_version");
+    restoreQualityProfile("one-issue-per-line");
     provisionSampleProject();
 
     // Execute an analysis in the past to have a past snapshot without any issues
@@ -226,7 +217,7 @@ public class TechnicalDebtAndIssueNewMeasuresTest {
     orchestrator.getServer().provisionProject("sample", "sample");
   }
 
-  private void defineQualityProfile(String qualityProfileKey) {
+  private void restoreQualityProfile(String qualityProfileKey) {
     ItUtils.restoreProfile(orchestrator, getClass().getResource("/measure/" + qualityProfileKey + ".xml"));
   }
 
index cb18138689502992d3e9403cc9e7551f04a6ff47..0bf2f9db32b2c88a36ad1ff27e66db1598052a65 100644 (file)
@@ -21,21 +21,17 @@ package org.sonarqube.tests.qualityModel;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import java.util.List;
-import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.wsclient.issue.Issue;
-import org.sonar.wsclient.issue.IssueClient;
-import org.sonar.wsclient.issue.IssueQuery;
+import org.sonarqube.qa.util.Tester;
 import org.sonarqube.ws.Issues;
+import org.sonarqube.ws.client.issue.SearchWsRequest;
 import util.ItUtils;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
-import static util.ItUtils.newAdminWsClient;
 import static util.ItUtils.projectDir;
 
 /**
@@ -44,15 +40,10 @@ import static util.ItUtils.projectDir;
 public class TechnicalDebtInIssueChangelogTest {
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityModelSuite.ORCHESTRATOR;
 
   @Rule
-  public DebtConfigurationRule debtConfiguration = DebtConfigurationRule.create(orchestrator);
-
-  @Before
-  public void deleteAnalysisData() {
-    orchestrator.resetData();
-  }
+  public Tester tester = new Tester(orchestrator);
 
   @Test
   public void display_debt_in_issue_changelog() throws Exception {
@@ -67,18 +58,17 @@ public class TechnicalDebtInIssueChangelogTest {
     orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))
       .setProperties("sonar.oneIssuePerFile.effortToFix", "10"));
 
-    IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
-    Issue issue = issueClient.find(IssueQuery.create()).list().get(0);
+    Issues.Issue firstIssue = tester.wsClient().issues().search(new SearchWsRequest()).getIssues(0);
 
-    List<Issues.ChangelogWsResponse.Changelog> changes = changelog(issue.key()).getChangelogList();
+    List<Issues.ChangelogWsResponse.Changelog> changes = changelog(firstIssue.getKey()).getChangelogList();
     assertThat(changes).hasSize(1);
     assertThat(changes.get(0).getDiffsList())
       .extracting(Issues.ChangelogWsResponse.Changelog.Diff::getKey, Issues.ChangelogWsResponse.Changelog.Diff::getOldValue, Issues.ChangelogWsResponse.Changelog.Diff::getNewValue)
       .containsOnly(tuple("effort", "10", "100"));
   }
 
-  private static Issues.ChangelogWsResponse changelog(String issueKey) {
-    return newAdminWsClient(orchestrator).issues().changelog(issueKey);
+  private Issues.ChangelogWsResponse changelog(String issueKey) {
+    return tester.wsClient().issues().changelog(issueKey);
   }
 
 }
index 6eb57cc0ea3491af1a2e649d8d0f103804415e44..5ce1e174a441d04f424b9ef7eb3b9209720e0e23 100644 (file)
@@ -21,14 +21,13 @@ package org.sonarqube.tests.qualityModel;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import java.util.List;
-import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.wsclient.issue.Issue;
-import org.sonar.wsclient.issue.IssueQuery;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.ws.Issues;
+import org.sonarqube.ws.client.issue.SearchWsRequest;
 import util.ItUtils;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -37,15 +36,10 @@ import static util.ItUtils.projectDir;
 public class TechnicalDebtTest {
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityModelSuite.ORCHESTRATOR;
 
   @Rule
-  public DebtConfigurationRule debtConfiguration = DebtConfigurationRule.create(orchestrator);
-
-  @Before
-  public void deleteAnalysisData() {
-    orchestrator.resetData();
-  }
+  public Tester tester = new Tester(orchestrator);
 
   /**
    * SONAR-4716
@@ -60,10 +54,10 @@ public class TechnicalDebtTest {
     orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
 
     // All the issues should have a technical debt
-    List<Issue> issues = orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create()).list();
+    List<Issues.Issue> issues = tester.wsClient().issues().search(new SearchWsRequest()).getIssuesList();
     assertThat(issues).isNotEmpty();
-    for (Issue issue : issues) {
-      assertThat(issue.debt()).isEqualTo("1min");
+    for (Issues.Issue issue : issues) {
+      assertThat(issue.getDebt()).isEqualTo("1min");
     }
   }