aboutsummaryrefslogtreecommitdiffstats
path: root/it
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-05-10 17:23:32 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-05-11 17:01:49 +0200
commit87a609a4c529fc25c89c425dc11a2cb49ef3fbf8 (patch)
treec5d76a01362d43b8e701be94db6638b1cc4fb7df /it
parent1eb0636088b70e8d744074fc6bccee8561c27c1c (diff)
downloadsonarqube-87a609a4c529fc25c89c425dc11a2cb49ef3fbf8.tar.gz
sonarqube-87a609a4c529fc25c89c425dc11a2cb49ef3fbf8.zip
SONAR-6897 add IT
Diffstat (limited to 'it')
-rw-r--r--it/it-projects/scm/xoo-sample-with-scm/sonar-project.properties (renamed from it/it-projects/testing/xoo-sample-highlighting/sonar-project.properties)4
-rw-r--r--it/it-projects/scm/xoo-sample-with-scm/src/main/xoo/sample/Sample.xoo7
-rw-r--r--it/it-projects/scm/xoo-sample-with-scm/src/main/xoo/sample/Sample.xoo.scm8
-rw-r--r--it/it-projects/testing/xoo-sample-highlighting/src/main/xoo/sample/Sample.xoo16
-rw-r--r--it/it-projects/testing/xoo-sample-highlighting/src/main/xoo/sample/Sample.xoo.highlighting3
-rw-r--r--it/it-tests/src/test/java/it/Category2Suite.java3
-rw-r--r--it/it-tests/src/test/java/it/scm/ScmTest.java139
-rw-r--r--it/it-tests/src/test/java/it/scm/ToDoTest.java23
8 files changed, 159 insertions, 44 deletions
diff --git a/it/it-projects/testing/xoo-sample-highlighting/sonar-project.properties b/it/it-projects/scm/xoo-sample-with-scm/sonar-project.properties
index 86ba98aee61..73645df942f 100644
--- a/it/it-projects/testing/xoo-sample-highlighting/sonar-project.properties
+++ b/it/it-projects/scm/xoo-sample-with-scm/sonar-project.properties
@@ -1,5 +1,5 @@
-sonar.projectKey=sample-highlighting
-sonar.projectName=Sample Highlighting
+sonar.projectKey=sample-scm
+sonar.projectName=Sample SCM
sonar.projectVersion=1.0-SNAPSHOT
sonar.sources=src/main/xoo
sonar.language=xoo
diff --git a/it/it-projects/scm/xoo-sample-with-scm/src/main/xoo/sample/Sample.xoo b/it/it-projects/scm/xoo-sample-with-scm/src/main/xoo/sample/Sample.xoo
new file mode 100644
index 00000000000..9dc354b8608
--- /dev/null
+++ b/it/it-projects/scm/xoo-sample-with-scm/src/main/xoo/sample/Sample.xoo
@@ -0,0 +1,7 @@
+package sample;
+
+public class Sample {
+
+ private String myMethod() {
+ }
+}
diff --git a/it/it-projects/scm/xoo-sample-with-scm/src/main/xoo/sample/Sample.xoo.scm b/it/it-projects/scm/xoo-sample-with-scm/src/main/xoo/sample/Sample.xoo.scm
new file mode 100644
index 00000000000..10d0952cf74
--- /dev/null
+++ b/it/it-projects/scm/xoo-sample-with-scm/src/main/xoo/sample/Sample.xoo.scm
@@ -0,0 +1,8 @@
+1,jhenry,2013-01-04
+1,jhenry,2013-01-04
+2,jhenry,2013-01-04
+1,jhenry,2013-01-04
+1,jhenry,2013-01-04
+1,jhenry,2013-01-04
+1,jhenry,2013-01-04
+3,toto,2014-01-04
diff --git a/it/it-projects/testing/xoo-sample-highlighting/src/main/xoo/sample/Sample.xoo b/it/it-projects/testing/xoo-sample-highlighting/src/main/xoo/sample/Sample.xoo
deleted file mode 100644
index 41871e123a3..00000000000
--- a/it/it-projects/testing/xoo-sample-highlighting/src/main/xoo/sample/Sample.xoo
+++ /dev/null
@@ -1,16 +0,0 @@
-package sample;
-
-public class Sample {
-
- public Sample(int i) {
- int j = i++;
- }
-
- private String myMethod() {
- if (foo == bar) {
- return "hello";
- } else {
- throw new IllegalStateException();
- }
- }
-}
diff --git a/it/it-projects/testing/xoo-sample-highlighting/src/main/xoo/sample/Sample.xoo.highlighting b/it/it-projects/testing/xoo-sample-highlighting/src/main/xoo/sample/Sample.xoo.highlighting
deleted file mode 100644
index 4530b0c572b..00000000000
--- a/it/it-projects/testing/xoo-sample-highlighting/src/main/xoo/sample/Sample.xoo.highlighting
+++ /dev/null
@@ -1,3 +0,0 @@
-# <startOffset>:<endOffset>:<typeOfText>
-
-20:20:k
diff --git a/it/it-tests/src/test/java/it/Category2Suite.java b/it/it-tests/src/test/java/it/Category2Suite.java
index c008a6be085..2af51cf7aa6 100644
--- a/it/it-tests/src/test/java/it/Category2Suite.java
+++ b/it/it-tests/src/test/java/it/Category2Suite.java
@@ -44,6 +44,7 @@ import it.qualityModel.TechnicalDebtInIssueChangelogTest;
import it.qualityModel.TechnicalDebtMeasureVariationTest;
import it.qualityModel.TechnicalDebtTest;
import it.qualityModel.TechnicalDebtWidgetTest;
+import it.scm.ScmTest;
import it.test.CoverageTest;
import it.test.CoverageTrackingTest;
import it.test.NewCoverageTest;
@@ -62,6 +63,8 @@ import static util.ItUtils.xooPlugin;
CoverageTest.class,
NewCoverageTest.class,
TestExecutionTest.class,
+ // scm
+ ScmTest.class,
// issue
AutoAssignTest.class,
CommonRulesTest.class,
diff --git a/it/it-tests/src/test/java/it/scm/ScmTest.java b/it/it-tests/src/test/java/it/scm/ScmTest.java
new file mode 100644
index 00000000000..f6329b5eef0
--- /dev/null
+++ b/it/it-tests/src/test/java/it/scm/ScmTest.java
@@ -0,0 +1,139 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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 it.scm;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.BuildResult;
+import com.sonar.orchestrator.build.SonarScanner;
+import it.Category2Suite;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.assertj.core.data.MapEntry;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.wsclient.jsonsimple.JSONArray;
+import org.sonar.wsclient.jsonsimple.JSONObject;
+import org.sonar.wsclient.jsonsimple.JSONValue;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.projectDir;
+
+public class ScmTest {
+
+ @ClassRule
+ public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR;
+
+ private static final SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+
+ @Before
+ public void delete_data() {
+ orchestrator.resetData();
+ }
+
+ @Test
+ public void scm_optimization() throws Exception {
+ SonarScanner build = SonarScanner.create(projectDir("scm/xoo-sample-with-scm"))
+ .setProperty("sonar.scm.provider", "xoo")
+ .setProperty("sonar.scm.disabled", "false");
+
+ // First run
+ BuildResult buildResult = orchestrator.executeBuild(build);
+
+ assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo"))
+ .containsExactly(
+ MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0100", "jhenry")),
+ MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0100", "jhenry")),
+ MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0100", "jhenry")),
+ MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0100", "toto")));
+
+ assertThat(buildResult.getLogs()).containsSequence("1 files to be analyzed", "1/1 files analyzed");
+
+ // Second run with same file should not trigger blame but SCM data are copied from previous analysis
+ buildResult = orchestrator.executeBuild(build);
+
+ assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo"))
+ .containsExactly(
+ MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0100", "jhenry")),
+ MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0100", "jhenry")),
+ MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0100", "jhenry")),
+ MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0100", "toto")));
+
+ assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed");
+ assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed");
+
+ // Now if SCM is explicitely disabled it should clear SCM data on server side
+ buildResult = orchestrator.executeBuild(build.setProperty("sonar.scm.disabled", "true"));
+
+ assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")).isEmpty();
+
+ assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed");
+ assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed");
+ }
+
+ private class LineData {
+
+ final String revision;
+ final Date date;
+ final String author;
+
+ public LineData(String revision, String datetime, String author) throws ParseException {
+ this.revision = revision;
+ this.date = DATETIME_FORMAT.parse(datetime);
+ this.author = author;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return EqualsBuilder.reflectionEquals(this, obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(revision).append(date).append(author).toHashCode();
+ }
+
+ @Override
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE);
+ }
+ }
+
+ private Map<Integer, LineData> getScmData(String fileKey) throws ParseException {
+ Map<Integer, LineData> result = new HashMap<>();
+ String json = orchestrator.getServer().adminWsClient().get("api/sources/scm", "key", fileKey);
+ JSONObject obj = (JSONObject) JSONValue.parse(json);
+ JSONArray array = (JSONArray) obj.get("scm");
+ for (Object anArray : array) {
+ JSONArray item = (JSONArray) anArray;
+ String datetime = (String) item.get(2);
+ result.put(((Long) item.get(0)).intValue(), new LineData((String) item.get(3), datetime, (String) item.get(1)));
+ }
+ return result;
+ }
+
+}
diff --git a/it/it-tests/src/test/java/it/scm/ToDoTest.java b/it/it-tests/src/test/java/it/scm/ToDoTest.java
deleted file mode 100644
index 4c8ca630507..00000000000
--- a/it/it-tests/src/test/java/it/scm/ToDoTest.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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 it.scm;
-
-public class ToDoTest {
-}