aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2018-01-10 15:04:43 +0100
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2018-01-25 15:16:50 +0100
commitd9280761c4e45c6fce77ef507ea50e2c2d0c4f8e (patch)
tree0b6bcbc8cf0f06c3d6bc8d6dbb30cfe5e56fc1a3 /server
parentb14f6c7ac546061aed4f2a5d8e33e9853c509000 (diff)
downloadsonarqube-d9280761c4e45c6fce77ef507ea50e2c2d0c4f8e.tar.gz
sonarqube-d9280761c4e45c6fce77ef507ea50e2c2d0c4f8e.zip
SONAR-10266 Create stub for api/project_badges WS
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/badge/ws/MeasureAction.java58
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWs.java42
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWsAction.java26
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWsModule.java45
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java59
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/badge/ws/package-info.java23
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java4
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/badge/ws/measure-example.svg22
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/badge/ws/quality_gate-example.svg22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java56
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/badge/ws/ProjectBadgesWsModuleTest.java53
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java56
12 files changed, 466 insertions, 0 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/badge/ws/MeasureAction.java b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/MeasureAction.java
new file mode 100644
index 00000000000..d0fceddd9eb
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/MeasureAction.java
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.sonar.server.badge.ws;
+
+import com.google.common.io.Resources;
+import org.apache.commons.io.IOUtils;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.NewAction;
+
+import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
+
+public class MeasureAction implements ProjectBadgesWsAction {
+
+ public static final String PARAM_COMPONENT = "component";
+ public static final String PARAM_METRIC = "metric";
+
+ @Override
+ public void define(WebService.NewController controller) {
+ NewAction action = controller.createAction("measure")
+ .setHandler(this)
+ .setDescription("Generate badge for measure as an SVG")
+ .setResponseExample(Resources.getResource(getClass(), "measure-example.svg"));
+ action.createParam(PARAM_COMPONENT)
+ .setDescription("Project key")
+ .setRequired(true)
+ .setExampleValue(KEY_PROJECT_EXAMPLE_001);
+ action.createParam(PARAM_METRIC)
+ .setDescription("Metric key")
+ .setRequired(true)
+ .setExampleValue(KEY_PROJECT_EXAMPLE_001);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ response.stream().setMediaType("image/svg+xml");
+ IOUtils.copy(Resources.getResource(getClass(), "measure-example.svg").openStream(), response.stream().output());
+ }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWs.java b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWs.java
new file mode 100644
index 00000000000..2b95f7b8ded
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWs.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.sonar.server.badge.ws;
+
+import java.util.List;
+import org.sonar.api.server.ws.WebService;
+
+public class ProjectBadgesWs implements WebService {
+
+ private final List<ProjectBadgesWsAction> actions;
+
+ public ProjectBadgesWs(List<ProjectBadgesWsAction> actions) {
+ this.actions = actions;
+ }
+
+ @Override
+ public void define(Context context) {
+ NewController controller = context.createController("api/project_badges");
+ controller.setDescription("Generate badges based on quality gates or measures");
+ controller.setSince("7.1");
+ actions.forEach(action -> action.define(controller));
+ controller.done();
+ }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWsAction.java
new file mode 100644
index 00000000000..5e8381b1299
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWsAction.java
@@ -0,0 +1,26 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.sonar.server.badge.ws;
+
+import org.sonar.server.ws.WsAction;
+
+interface ProjectBadgesWsAction extends WsAction {
+ // Marker interface
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWsModule.java
new file mode 100644
index 00000000000..085fdc36291
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/ProjectBadgesWsModule.java
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.sonar.server.badge.ws;
+
+import org.sonar.api.config.Configuration;
+import org.sonar.core.config.WebConstants;
+import org.sonar.core.platform.Module;
+
+public class ProjectBadgesWsModule extends Module {
+
+ private final Configuration config;
+
+ public ProjectBadgesWsModule(Configuration config) {
+ this.config = config;
+ }
+
+ @Override
+ protected void configureModule() {
+ if (!config.getBoolean(WebConstants.SONARCLOUD_ENABLED).orElse(false)) {
+ return;
+ }
+ add(
+ ProjectBadgesWs.class,
+ QualityGateAction.class,
+ MeasureAction.class
+ );
+ }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java
new file mode 100644
index 00000000000..6f605191db2
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java
@@ -0,0 +1,59 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.sonar.server.badge.ws;
+
+import com.google.common.io.Resources;
+import org.apache.commons.io.IOUtils;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.NewAction;
+
+import static java.util.Arrays.asList;
+import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
+
+public class QualityGateAction implements ProjectBadgesWsAction {
+
+ public static final String PARAM_COMPONENT = "component";
+ public static final String PARAM_TYPE = "type";
+
+ @Override
+ public void define(WebService.NewController controller) {
+ NewAction action = controller.createAction("quality_gate")
+ .setHandler(this)
+ .setDescription("Generate badge for quality gate as an SVG")
+ .setResponseExample(Resources.getResource(getClass(), "quality_gate-example.svg"));
+ action.createParam(PARAM_COMPONENT)
+ .setDescription("Project key")
+ .setRequired(true)
+ .setExampleValue(KEY_PROJECT_EXAMPLE_001);
+ action.createParam(PARAM_TYPE)
+ .setDescription("Type of badge.")
+ .setRequired(false)
+ .setPossibleValues(asList("BADGE", "CARD"));
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ response.stream().setMediaType("image/svg+xml");
+ IOUtils.copy(Resources.getResource(getClass(), "quality_gate-example.svg").openStream(), response.stream().output());
+ }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/badge/ws/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/package-info.java
new file mode 100644
index 00000000000..747c157c316
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/badge/ws/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.badge.ws;
+
+import javax.annotation.ParametersAreNonnullByDefault;
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 db08d7499b5..89cf7930d08 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
@@ -35,6 +35,7 @@ import org.sonar.core.component.DefaultResourceTypes;
import org.sonar.core.timemachine.Periods;
import org.sonar.server.authentication.AuthenticationModule;
import org.sonar.server.authentication.LogOAuthWarning;
+import org.sonar.server.badge.ws.ProjectBadgesWsModule;
import org.sonar.server.batch.BatchWsModule;
import org.sonar.server.branch.BranchFeatureProxyImpl;
import org.sonar.server.branch.ws.BranchWsModule;
@@ -535,6 +536,9 @@ public class PlatformLevel4 extends PlatformLevel {
// Branch
BranchFeatureProxyImpl.class,
+ // Project badges
+ ProjectBadgesWsModule.class,
+
// privileged plugins
PrivilegedPluginsBootstraper.class,
PrivilegedPluginsStopper.class,
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/badge/ws/measure-example.svg b/server/sonar-server/src/main/resources/org/sonar/server/badge/ws/measure-example.svg
new file mode 100644
index 00000000000..8934ac3cfc2
--- /dev/null
+++ b/server/sonar-server/src/main/resources/org/sonar/server/badge/ws/measure-example.svg
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" height="20" width="191">
+ <linearGradient id="smooth" x2="0" y2="100%">
+ <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
+ <stop offset="1" stop-opacity=".1"/>
+ </linearGradient>
+ <mask id="round">
+ <rect fill="#fff" height="20" rx="3" width="191"/>
+ </mask>
+ <g mask="url(#round)">
+ <rect fill="#666" height="20" width="136"/>
+ <rect fill="#969696" height="20" width="55" x="136"/>
+ <rect fill="url(#smooth)" height="20" width="191"/>
+ </g>
+ <g fill="#fff" font-family="DejaVu Sans,Verdana,Sans PT,Lucida Grande,Tahoma,Helvetica,Arial,sans-serif"
+ font-size="11" text-anchor="middle">
+ <text fill="#010101" fill-opacity=".3" x="68" y="15">Coverage</text>
+ <text x="68" y="14">Coverage</text>
+ <text fill="#010101" fill-opacity=".3" x="163" y="15">100.0%</text>
+ <text x="163" y="14">100.0%</text>
+ </g>
+</svg> \ No newline at end of file
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/badge/ws/quality_gate-example.svg b/server/sonar-server/src/main/resources/org/sonar/server/badge/ws/quality_gate-example.svg
new file mode 100644
index 00000000000..038231f8b52
--- /dev/null
+++ b/server/sonar-server/src/main/resources/org/sonar/server/badge/ws/quality_gate-example.svg
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" height="20" width="123">
+ <linearGradient id="smooth" x2="0" y2="100%">
+ <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
+ <stop offset="1" stop-opacity=".1"/>
+ </linearGradient>
+ <mask id="round">
+ <rect fill="#fff" height="20" rx="3" width="123"/>
+ </mask>
+ <g mask="url(#round)">
+ <rect fill="#666" height="20" width="77"/>
+ <rect fill="#E05D44" height="20" width="46" x="77"/>
+ <rect fill="url(#smooth)" height="20" width="123"/>
+ </g>
+ <g fill="#fff" font-family="Sans PT,Lucida Grande,Tahoma,Helvetica,Arial,sans-serif" font-size="11"
+ text-anchor="middle">
+ <text fill="#010101" fill-opacity=".3" x="38" y="15">Quality Gate</text>
+ <text x="38" y="14">Quality Gate</text>
+ <text fill="#010101" fill-opacity=".3" x="100" y="15">failing</text>
+ <text x="100" y="14">failing</text>
+ </g>
+</svg> \ No newline at end of file
diff --git a/server/sonar-server/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java
new file mode 100644
index 00000000000..51b619e5f92
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/badge/ws/MeasureActionTest.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.sonar.server.badge.ws;
+
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class MeasureActionTest {
+
+ private WsActionTester ws = new WsActionTester(new MeasureAction());
+
+ @Test
+ public void test_definition() {
+ WebService.Action def = ws.getDef();
+ assertThat(def.key()).isEqualTo("measure");
+ assertThat(def.isInternal()).isFalse();
+ assertThat(def.isPost()).isFalse();
+ assertThat(def.since()).isNull();
+ assertThat(def.responseExampleAsString()).isNotEmpty();
+
+ assertThat(def.params())
+ .extracting(Param::key, Param::isRequired)
+ .containsExactlyInAnyOrder(
+ tuple("component", true),
+ tuple("metric", true));
+ }
+
+ @Test
+ public void test_example() {
+ String response = ws.newRequest().execute().getInput();
+
+ assertThat(response).isEqualTo(ws.getDef().responseExampleAsString());
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/badge/ws/ProjectBadgesWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/badge/ws/ProjectBadgesWsModuleTest.java
new file mode 100644
index 00000000000..69574191e11
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/badge/ws/ProjectBadgesWsModuleTest.java
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.sonar.server.badge.ws;
+
+import org.junit.Test;
+import org.sonar.api.config.internal.MapSettings;
+import org.sonar.core.platform.ComponentContainer;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER;
+
+public class ProjectBadgesWsModuleTest {
+
+ private ComponentContainer container = new ComponentContainer();
+ private MapSettings mapSettings = new MapSettings();
+ private ProjectBadgesWsModule underTest = new ProjectBadgesWsModule(mapSettings.asConfig());
+
+ @Test
+ public void verify_count_of_added_components() {
+ mapSettings.setProperty("sonar.sonarcloud.enabled", true);
+
+ underTest.configure(container);
+
+ assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 3);
+ }
+
+ @Test
+ public void no_component_when_not_on_sonar_cloud() {
+ mapSettings.setProperty("sonar.sonarcloud.enabled", false);
+
+ underTest.configure(container);
+
+ assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER);
+ }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java
new file mode 100644
index 00000000000..cfecf96178b
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/badge/ws/QualityGateActionTest.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.sonar.server.badge.ws;
+
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class QualityGateActionTest {
+
+ private WsActionTester ws = new WsActionTester(new QualityGateAction());
+
+ @Test
+ public void test_definition() {
+ WebService.Action def = ws.getDef();
+ assertThat(def.key()).isEqualTo("quality_gate");
+ assertThat(def.isInternal()).isFalse();
+ assertThat(def.isPost()).isFalse();
+ assertThat(def.since()).isNull();
+ assertThat(def.responseExampleAsString()).isNotEmpty();
+
+ assertThat(def.params())
+ .extracting(Param::key, Param::isRequired)
+ .containsExactlyInAnyOrder(
+ tuple("component", true),
+ tuple("type", false));
+ }
+
+ @Test
+ public void test_example() {
+ String response = ws.newRequest().execute().getInput();
+
+ assertThat(response).isEqualTo(ws.getDef().responseExampleAsString());
+ }
+}