aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--it/it-tests/src/test/java/it/Category4Suite.java2
-rw-r--r--it/it-tests/src/test/java/it/serverSystem/PingTest.java43
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/ws/PingAction.java43
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/platform/ws/ping-example.txt1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/ws/PingActionTest.java52
6 files changed, 143 insertions, 0 deletions
diff --git a/it/it-tests/src/test/java/it/Category4Suite.java b/it/it-tests/src/test/java/it/Category4Suite.java
index db87ef57d3c..897cf0b023e 100644
--- a/it/it-tests/src/test/java/it/Category4Suite.java
+++ b/it/it-tests/src/test/java/it/Category4Suite.java
@@ -35,6 +35,7 @@ import it.projectSearch.SearchProjectsTest;
import it.qualityProfile.QualityProfilesPageTest;
import it.serverSystem.HttpHeadersTest;
import it.serverSystem.LogsTest;
+import it.serverSystem.PingTest;
import it.serverSystem.ServerSystemTest;
import it.ui.SourceViewerTest;
import it.ui.UiTest;
@@ -58,6 +59,7 @@ import static util.ItUtils.xooPlugin;
@Suite.SuiteClasses({
// server system
ServerSystemTest.class,
+ PingTest.class,
// user
MyAccountPageTest.class,
FavoritesWsTest.class,
diff --git a/it/it-tests/src/test/java/it/serverSystem/PingTest.java b/it/it-tests/src/test/java/it/serverSystem/PingTest.java
new file mode 100644
index 00000000000..41cf78b8a5c
--- /dev/null
+++ b/it/it-tests/src/test/java/it/serverSystem/PingTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.serverSystem;
+
+import com.sonar.orchestrator.Orchestrator;
+import it.Category4Suite;
+import okhttp3.Response;
+import org.junit.ClassRule;
+import org.junit.Test;
+import util.ItUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PingTest {
+
+ @ClassRule
+ public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+
+ @Test
+ public void ping_answers_pong() throws Exception {
+ Response response = ItUtils.call(orchestrator.getServer().getUrl() + "/api/system/ping");
+
+ assertThat(response.body().string()).isEqualTo("pong");
+ assertThat(response.header("Content-Type")).isEqualTo("text/plain");
+ }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
index be66249b2ec..e21f40ff161 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
@@ -110,6 +110,7 @@ import org.sonar.server.platform.ws.InfoAction;
import org.sonar.server.platform.ws.L10nWs;
import org.sonar.server.platform.ws.LogsAction;
import org.sonar.server.platform.ws.MigrateDbAction;
+import org.sonar.server.platform.ws.PingAction;
import org.sonar.server.platform.ws.RestartAction;
import org.sonar.server.platform.ws.ServerWs;
import org.sonar.server.platform.ws.StatusAction;
@@ -459,6 +460,7 @@ public class PlatformLevel4 extends PlatformLevel {
ServerLogging.class,
RestartAction.class,
InfoAction.class,
+ PingAction.class,
UpgradesAction.class,
StatusAction.class,
SystemWs.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/PingAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/PingAction.java
new file mode 100644
index 00000000000..496b2104fed
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/PingAction.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.sonar.server.platform.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+
+import static org.apache.commons.io.IOUtils.write;
+
+public class PingAction implements SystemWsAction {
+ @Override
+ public void define(WebService.NewController controller) {
+ controller.createAction("ping")
+ .setDescription("Answers \"pong\" as plain-text")
+ .setSince("6.3")
+ .setResponseExample(getClass().getResource("ping-example.txt"))
+ .setHandler(this);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ response.stream().setMediaType("text/plain");
+ write("pong", response.stream().output());
+ }
+}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/platform/ws/ping-example.txt b/server/sonar-server/src/main/resources/org/sonar/server/platform/ws/ping-example.txt
new file mode 100644
index 00000000000..8e5546941b0
--- /dev/null
+++ b/server/sonar-server/src/main/resources/org/sonar/server/platform/ws/ping-example.txt
@@ -0,0 +1 @@
+pong
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/PingActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/PingActionTest.java
new file mode 100644
index 00000000000..4da578d99d2
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/PingActionTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.sonar.server.platform.ws;
+
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.ws.TestResponse;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PingActionTest {
+
+ private PingAction underTest = new PingAction();
+ private WsActionTester tester = new WsActionTester(underTest);
+
+ @Test
+ public void test_definition() {
+ WebService.Action action = tester.getDef();
+
+ assertThat(action.key()).isEqualTo("ping");
+ assertThat(action.isPost()).isFalse();
+ assertThat(action.isInternal()).isFalse();
+ assertThat(action.params()).isEmpty();
+ }
+
+ @Test
+ public void returns_pong_as_plain_text() {
+ TestResponse response = tester.newRequest().execute();
+
+ assertThat(response.getMediaType()).isEqualTo("text/plain");
+ assertThat(response.getInput()).isEqualTo("pong");
+ assertThat(response.getInput()).isEqualTo(tester.getDef().responseExampleAsString());
+ }
+}