aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-08-21 11:07:55 +0200
committerTeryk Bellahsene <teryk@users.noreply.github.com>2017-08-30 16:24:53 +0200
commit972b352ce1166382b420aef8af3601418071a774 (patch)
tree76a6d275ccee3eb6acda14cab91425b394bf9bb7 /tests
parent3bf1fff4825f4dfcb7ba9bab8272a188ceda45a8 (diff)
downloadsonarqube-972b352ce1166382b420aef8af3601418071a774.tar.gz
sonarqube-972b352ce1166382b420aef8af3601418071a774.zip
SONAR-9721 Send Server UUID to Telemetry server
Diffstat (limited to 'tests')
-rw-r--r--tests/src/test/java/org/sonarqube/tests/Category5Suite.java2
-rw-r--r--tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryTest.java72
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category5Suite.java b/tests/src/test/java/org/sonarqube/tests/Category5Suite.java
index 98587c47027..6c563a32294 100644
--- a/tests/src/test/java/org/sonarqube/tests/Category5Suite.java
+++ b/tests/src/test/java/org/sonarqube/tests/Category5Suite.java
@@ -30,6 +30,7 @@ import org.sonarqube.tests.serverSystem.RestartTest;
import org.sonarqube.tests.serverSystem.ServerSystemRestartingOrchestrator;
import org.sonarqube.tests.settings.LicensesPageTest;
import org.sonarqube.tests.settings.SettingsTestRestartingOrchestrator;
+import org.sonarqube.tests.telemetry.TelemetryTest;
import org.sonarqube.tests.updateCenter.UpdateCenterTest;
import org.sonarqube.tests.user.OnboardingTest;
import org.sonarqube.tests.user.RealmAuthenticationTest;
@@ -57,6 +58,7 @@ import org.sonarqube.tests.user.UserEsResilienceTest;
ActiveRuleEsResilienceTest.class,
RuleEsResilienceTest.class,
UserEsResilienceTest.class,
+ TelemetryTest.class,
// ce
CeWorkersTest.class
})
diff --git a/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryTest.java b/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryTest.java
new file mode 100644
index 00000000000..48797c7a7d5
--- /dev/null
+++ b/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.telemetry;
+
+import com.sonar.orchestrator.Orchestrator;
+import java.util.concurrent.TimeUnit;
+import javax.ws.rs.core.HttpHeaders;
+import okhttp3.mockwebserver.MockWebServer;
+import okhttp3.mockwebserver.RecordedRequest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.xooPlugin;
+
+public class TelemetryTest {
+
+ private static Orchestrator orchestrator;
+
+ private MockWebServer server;
+ private String url;
+
+ @Before
+ public void setUp() throws Exception {
+ server = new MockWebServer();
+ server.start();
+ url = server.url("").url().toString();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ server.shutdown();
+ }
+
+ @Test
+ public void send_telemetry_data_at_startup() throws Exception {
+ String serverId = randomAlphanumeric(40);
+ orchestrator = Orchestrator.builderEnv()
+ .addPlugin(xooPlugin())
+ .setServerProperty("sonar.telemetry.url", url)
+ .setServerProperty("sonar.core.id", serverId)
+ .build();
+ orchestrator.start();
+
+ RecordedRequest request = server.takeRequest(1, TimeUnit.SECONDS);
+
+ assertThat(request.getMethod()).isEqualTo("POST");
+ assertThat(request.getBody().readUtf8()).contains(serverId);
+ assertThat(request.getHeader(HttpHeaders.USER_AGENT)).contains("SonarQube");
+
+ orchestrator.stop();
+ }
+}