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;
@Suite.SuiteClasses({
// server system
ServerSystemTest.class,
+ PingTest.class,
// user
MyAccountPageTest.class,
FavoritesWsTest.class,
--- /dev/null
+/*
+ * 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");
+ }
+}
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;
ServerLogging.class,
RestartAction.class,
InfoAction.class,
+ PingAction.class,
UpgradesAction.class,
StatusAction.class,
SystemWs.class,
--- /dev/null
+/*
+ * 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());
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+}