diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-05-22 23:07:49 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-05-22 23:10:30 +0200 |
commit | 1b615d58ed9f268d9c21d7975fcb250dfd35fb33 (patch) | |
tree | 1df738966c888f88f2447a0583b15818fa56afb5 /sonar-plugin-api | |
parent | cf457fb8482f6fcb46e3f15b4cbb4b501d197e54 (diff) | |
download | sonarqube-1b615d58ed9f268d9c21d7975fcb250dfd35fb33.tar.gz sonarqube-1b615d58ed9f268d9c21d7975fcb250dfd35fb33.zip |
SONAR-5007 improve management of active rules in api/rules/search and api/rules/show
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java | 15 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java | 54 |
2 files changed, 63 insertions, 6 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java index 5e464a4200f..d656213f30e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java @@ -32,10 +32,13 @@ import org.sonar.api.ServerExtension; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; - import java.io.IOException; import java.net.URL; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Defines a web service. Note that contrary to the deprecated {@link org.sonar.api.web.Webservice} @@ -457,8 +460,8 @@ public interface WebService extends ServerExtension { /** * @since 4.4 */ - public NewParam setExampleValue(@Nullable String s) { - this.exampleValue = s; + public NewParam setExampleValue(@Nullable Object s) { + this.exampleValue = (s != null ? s.toString() : null); return this; } @@ -500,8 +503,8 @@ public interface WebService extends ServerExtension { /** * @since 4.4 */ - public NewParam setDefaultValue(@Nullable String s) { - this.defaultValue = s; + public NewParam setDefaultValue(@Nullable Object o) { + this.defaultValue = (o != null ? o.toString() : null); return this; } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java index 4dab17f0641..aed3c7d78c6 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java @@ -21,9 +21,11 @@ package org.sonar.api.server.ws; import org.apache.commons.lang.StringUtils; import org.junit.Test; +import org.sonar.api.rule.RuleStatus; import java.net.MalformedURLException; import java.net.URL; +import java.util.Collection; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; @@ -275,6 +277,58 @@ public class WebServiceTest { } @Test + public void param_metadata_as_objects() { + new WebService() { + @Override + public void define(Context context) { + NewController newController = context.createController("api/rule"); + NewAction create = newController.createAction("create").setHandler(mock(RequestHandler.class)); + create.createParam("status") + .setDefaultValue(RuleStatus.BETA) + .setPossibleValues(RuleStatus.BETA, RuleStatus.READY) + .setExampleValue(RuleStatus.BETA); + create.createParam("max") + .setDefaultValue(11) + .setPossibleValues(11, 13, 17) + .setExampleValue(17); + newController.done(); + } + }.define(context); + + WebService.Action action = context.controller("api/rule").action("create"); + assertThat(action.param("status").defaultValue()).isEqualTo("BETA"); + assertThat(action.param("status").possibleValues()).containsOnly("BETA", "READY"); + assertThat(action.param("status").exampleValue()).isEqualTo("BETA"); + assertThat(action.param("max").defaultValue()).isEqualTo("11"); + assertThat(action.param("max").possibleValues()).containsOnly("11", "13", "17"); + assertThat(action.param("max").exampleValue()).isEqualTo("17"); + } + + @Test + public void param_null_metadata() { + new WebService() { + @Override + public void define(Context context) { + NewController newController = context.createController("api/rule"); + NewAction create = newController.createAction("create").setHandler(mock(RequestHandler.class)); + create.createParam("status") + .setDefaultValue(null) + .setPossibleValues((Collection) null) + .setExampleValue(null); + create.createParam("max") + .setPossibleValues((String[]) null); + newController.done(); + } + }.define(context); + + WebService.Action action = context.controller("api/rule").action("create"); + assertThat(action.param("status").defaultValue()).isNull(); + assertThat(action.param("status").possibleValues()).isNull(); + assertThat(action.param("status").exampleValue()).isNull(); + assertThat(action.param("max").possibleValues()).isNull(); + } + + @Test public void fail_if_duplicated_action_parameters() { try { new WebService() { |