]> source.dussan.org Git - sonarqube.git/commitdiff
Add category "test" to integration tests
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 10 Nov 2017 13:27:34 +0000 (14:27 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Tue, 14 Nov 2017 12:10:17 +0000 (13:10 +0100)
cix.sh
tests/src/test/java/org/sonarqube/tests/Category2Suite.java
tests/src/test/java/org/sonarqube/tests/test/CoverageTest.java
tests/src/test/java/org/sonarqube/tests/test/CoverageTrackingTest.java
tests/src/test/java/org/sonarqube/tests/test/NewCoverageTest.java
tests/src/test/java/org/sonarqube/tests/test/TestExecutionTest.java
tests/src/test/java/org/sonarqube/tests/test/TestSuite.java [new file with mode: 0644]

diff --git a/cix.sh b/cix.sh
index 879206325ea0adc3cdfde18893693215d0ab72e2..96a877df2bfe8ed1af22bfc80e7a298cc9ec8809 100755 (executable)
--- a/cix.sh
+++ b/cix.sh
@@ -38,6 +38,7 @@ case "$RUN_ACTIVITY" in
 
         Category2)
           CATEGORY=Category2 && runCategory
+          CATEGORY=test && runCategory
           ;;
 
         Category3)
index 10e6fbca5dc3023f070121f243a8e927484a755b..f507e9d65b892fb41cf1f0e9a24770328baf735d 100644 (file)
@@ -51,21 +51,12 @@ 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 org.sonarqube.tests.test.CoverageTest;
-import org.sonarqube.tests.test.CoverageTrackingTest;
-import org.sonarqube.tests.test.NewCoverageTest;
-import org.sonarqube.tests.test.TestExecutionTest;
 
 import static util.ItUtils.pluginArtifact;
 import static util.ItUtils.xooPlugin;
 
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
-  // test
-  CoverageTrackingTest.class,
-  CoverageTest.class,
-  NewCoverageTest.class,
-  TestExecutionTest.class,
   // issue
   AutoAssignTest.class,
   CommonRulesTest.class,
index fb38e03cc326c998ef8803d6727c7b38e25e3c47..27e507db8d9104584996f8de7105d8c0201ef1ea 100644 (file)
@@ -21,7 +21,6 @@ package org.sonarqube.tests.test;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import java.io.File;
 import java.util.Map;
 import org.apache.commons.io.FileUtils;
@@ -33,6 +32,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonarqube.qa.util.Tester;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.WsRequest;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
@@ -40,18 +41,17 @@ import static util.ItUtils.projectDir;
 
 public class CoverageTest {
 
-  @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
-
-  private static final String[] ALL_COVERAGE_METRICS = new String[] {
+  private static final String[] ALL_COVERAGE_METRICS = new String[]{
     "line_coverage", "lines_to_cover", "uncovered_lines", "branch_coverage", "conditions_to_cover", "uncovered_conditions", "coverage",
     "it_line_coverage", "it_lines_to_cover", "it_uncovered_lines", "it_branch_coverage", "it_conditions_to_cover", "it_uncovered_conditions", "it_coverage",
     "overall_line_coverage", "overall_lines_to_cover", "overall_uncovered_lines", "overall_branch_coverage", "overall_conditions_to_cover", "overall_uncovered_conditions",
-    "overall_coverage"
-  };
+    "overall_coverage"};
+
+  @ClassRule
+  public static Orchestrator orchestrator = TestSuite.ORCHESTRATOR;
 
   @Rule
-  public Tester tester = new Tester(orchestrator).disableOrganizations();
+  public Tester tester = new Tester(orchestrator);
 
   @Test
   public void coverage() throws Exception {
@@ -70,7 +70,8 @@ public class CoverageTest {
 
     assertThat(measures.get("overall_coverage")).isNull();
 
-    String coverage = cleanupScmAndDuplication(orchestrator.getServer().adminWsClient().get("api/sources/lines", "key", "sample-ut-coverage:src/main/xoo/sample/Sample.xoo"));
+    GetRequest getRequest = new GetRequest("api/sources/lines").setParam("key", "sample-ut-coverage:src/main/xoo/sample/Sample.xoo");
+    String coverage = cleanupScmAndDuplication(tester.wsClient().wsConnector().call(getRequest).content());
     // Use strict checking to be sure IT coverage is not present
     JSONAssert.assertEquals(IOUtils.toString(this.getClass().getResourceAsStream("/test/CoverageTest/unit_test_coverage-expected.json"), "UTF-8"), coverage, true);
 
@@ -101,7 +102,8 @@ public class CoverageTest {
 
     assertThat(measures.get("overall_coverage")).isNull();
 
-    String coverage = cleanupScmAndDuplication(orchestrator.getServer().adminWsClient().get("api/sources/lines", "key", "sample-ut-coverage:src/main/xoo/sample/Sample.xoo"));
+    WsRequest getRequest = new GetRequest("api/sources/lines").setParam("key", "sample-ut-coverage:src/main/xoo/sample/Sample.xoo");
+    String coverage = cleanupScmAndDuplication(tester.wsClient().wsConnector().call(getRequest).content());
     // Use strict checking to be sure IT coverage is not present
     JSONAssert.assertEquals(IOUtils.toString(this.getClass().getResourceAsStream("/test/CoverageTest/unit_test_coverage_no_condition-expected.json"), "UTF-8"), coverage,
       true);
@@ -129,7 +131,8 @@ public class CoverageTest {
 
     assertThat(measures.get("overall_coverage")).isNull();
 
-    String coverage = cleanupScmAndDuplication(orchestrator.getServer().adminWsClient().get("api/sources/lines", "key", "sample-it-coverage:src/main/xoo/sample/Sample.xoo"));
+    WsRequest getRequest = new GetRequest("api/sources/lines").setParam("key", "sample-it-coverage:src/main/xoo/sample/Sample.xoo");
+    String coverage = cleanupScmAndDuplication(tester.wsClient().wsConnector().call(getRequest).content());
     // Use strict checking to be sure UT coverage is not present
     JSONAssert.assertEquals(IOUtils.toString(this.getClass().getResourceAsStream("/test/CoverageTest/it_coverage-expected.json"), "UTF-8"), coverage, true);
 
@@ -155,7 +158,8 @@ public class CoverageTest {
 
     assertThat(measures.get("overall_coverage")).isNull();
 
-    String coverage = cleanupScmAndDuplication(orchestrator.getServer().adminWsClient().get("api/sources/lines", "key", "sample-overall-coverage:src/main/xoo/sample/Sample.xoo"));
+    WsRequest getRequest = new GetRequest("api/sources/lines").setParam("key", "sample-overall-coverage:src/main/xoo/sample/Sample.xoo");
+    String coverage = cleanupScmAndDuplication(tester.wsClient().wsConnector().call(getRequest).content());
     // Use strict checking to be sure no extra coverage is present
     JSONAssert.assertEquals(IOUtils.toString(this.getClass().getResourceAsStream("/test/CoverageTest/ut_and_it_coverage-expected.json"), "UTF-8"), coverage, true);
 
index c1a9545b55b6e7fc20729c1586bdbe54a26fbf80..5cfd2553684f846c37f3909d8b8665c446e71acd 100644 (file)
@@ -21,7 +21,6 @@ package org.sonarqube.tests.test;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.apache.commons.io.IOUtils;
@@ -30,22 +29,25 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonarqube.qa.util.Tester;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.WsRequest;
 
 import static util.ItUtils.projectDir;
 
 public class CoverageTrackingTest {
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = TestSuite.ORCHESTRATOR;
 
   @Rule
-  public Tester tester = new Tester(orchestrator).disableOrganizations();
+  public Tester tester = new Tester(orchestrator);
 
   @Test
   public void test_coverage_per_test() throws Exception {
     orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-with-coverage-per-test")));
 
-    String tests = orchestrator.getServer().adminWsClient().get("api/tests/list", "testFileKey", "sample-with-tests:src/test/xoo/sample/SampleTest.xoo");
+    WsRequest getRequest = new GetRequest("api/tests/list").setParam("testFileKey", "sample-with-tests:src/test/xoo/sample/SampleTest.xoo");
+    String tests = tester.wsClient().wsConnector().call(getRequest).content();
     JSONAssert.assertEquals(IOUtils.toString(this.getClass().getResourceAsStream("/test/CoverageTrackingTest/tests-expected.json"), "UTF-8"), tests, false);
 
     String covered_files = orchestrator.getServer().adminWsClient()
index 6a331207e325fa86b40b44048f33594b3c4478d7..670d54404795692e4325236d42111c4b22fc8a5a 100644 (file)
@@ -21,12 +21,12 @@ package org.sonarqube.tests.test;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import java.util.Map;
 import org.assertj.core.data.Offset;
-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 static java.lang.Double.parseDouble;
@@ -36,30 +36,24 @@ import static util.ItUtils.projectDir;
 
 public class NewCoverageTest {
 
-  @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
-
   private static final String PROJECT_KEY = "sample-new-coverage";
-
   private static final Offset<Double> DEFAULT_OFFSET = Offset.offset(0.1d);
+  private static final String[] ALL_NEW_COVERAGE_METRICS = new String[]{"new_coverage", "new_line_coverage", "new_branch_coverage"};
 
-  private static final String[] ALL_NEW_COVERAGE_METRICS = new String[] {
-    "new_coverage", "new_line_coverage", "new_branch_coverage"
-  };
+  @ClassRule
+  public static Orchestrator orchestrator = TestSuite.ORCHESTRATOR;
 
-  @BeforeClass
-  public static void analyze_project() {
-    orchestrator.resetData();
+  @Rule
+  public Tester tester = new Tester(orchestrator);
 
+  @Test
+  public void new_coverage() throws Exception {
     orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-new-coverage-v1"))
       .setProperty("sonar.projectDate", "2015-02-01")
       .setProperty("sonar.scm.disabled", "false"));
     orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-new-coverage-v2"))
       .setProperty("sonar.scm.disabled", "false"));
-  }
 
-  @Test
-  public void new_coverage() throws Exception {
     Map<String, WsMeasures.Measure> measures = getMeasuresWithVariationsByMetricKey(orchestrator, PROJECT_KEY, ALL_NEW_COVERAGE_METRICS);
     assertThat(parseDouble(measures.get("new_coverage").getPeriods().getPeriodsValue(0).getValue())).isEqualTo(66.6d, DEFAULT_OFFSET);
     assertThat(parseDouble(measures.get("new_line_coverage").getPeriods().getPeriodsValue(0).getValue())).isEqualTo(100d, DEFAULT_OFFSET);
index bb5edbb55f3cb0c179c4bbc5963a282a2a571bf2..43690fd6b5f07d71fa0c8f1652333895bd461ac5 100644 (file)
@@ -21,13 +21,15 @@ package org.sonarqube.tests.test;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category2Suite;
 import java.util.Map;
 import org.apache.commons.io.IOUtils;
-import org.junit.Before;
 import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.skyscreamer.jsonassert.JSONAssert;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.WsRequest;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static util.ItUtils.getMeasuresAsDoubleByMetricKey;
@@ -36,12 +38,10 @@ import static util.ItUtils.projectDir;
 public class TestExecutionTest {
 
   @ClassRule
-  public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = TestSuite.ORCHESTRATOR;
 
-  @Before
-  public void delete_data() {
-    orchestrator.resetData();
-  }
+  @Rule
+  public Tester tester = new Tester(orchestrator);
 
   @Test
   public void test_execution_details() throws Exception {
@@ -56,7 +56,8 @@ public class TestExecutionTest {
     assertThat(measures.get("skipped_tests")).isEqualTo(1);
     assertThat(measures.get("test_execution_time")).isEqualTo(8);
 
-    String json = orchestrator.getServer().adminWsClient().get("api/tests/list", "testFileKey", "sample-with-tests:src/test/xoo/sample/SampleTest.xoo");
+    WsRequest getRequest = new GetRequest("api/tests/list").setParam("testFileKey", "sample-with-tests:src/test/xoo/sample/SampleTest.xoo");
+    String json = tester.wsClient().wsConnector().call(getRequest).content();
     JSONAssert.assertEquals(IOUtils.toString(this.getClass().getResourceAsStream("/test/TestExecutionTest/expected.json"), "UTF-8"), json, false);
   }
 
diff --git a/tests/src/test/java/org/sonarqube/tests/test/TestSuite.java b/tests/src/test/java/org/sonarqube/tests/test/TestSuite.java
new file mode 100644 (file)
index 0000000..49b7795
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.test;
+
+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({
+  CoverageTrackingTest.class,
+  CoverageTest.class,
+  NewCoverageTest.class,
+  TestExecutionTest.class,
+})
+public class TestSuite {
+
+  @ClassRule
+  public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+    .addPlugin(xooPlugin())
+
+    // reduce memory for Elasticsearch
+    .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m")
+
+    .build();
+
+}