diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-12-18 15:54:29 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-12-18 17:03:50 +0100 |
commit | b1bb7f5c17b0e3ba56b6cec2995bae1acaebd5b4 (patch) | |
tree | 14a358d400d0b9b2b11ae84bf84c5adf72bb142a /sonar-plugin-api | |
parent | 6449facdc365c9072ea1ea4aa347cdc86ba9de4f (diff) | |
download | sonarqube-b1bb7f5c17b0e3ba56b6cec2995bae1acaebd5b4.tar.gz sonarqube-b1bb7f5c17b0e3ba56b6cec2995bae1acaebd5b4.zip |
SONAR-5934 Rewrite create users WS, SONAR-5961 Rewrite the update user WS
Diffstat (limited to 'sonar-plugin-api')
4 files changed, 33 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java index 89e920e5338..2cbd0ef0b4d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java @@ -43,6 +43,11 @@ public abstract class Request { public abstract String method(); /** + * Return true of the parameter is set. + */ + public abstract boolean hasParam(String key); + + /** * Returns a non-null value. To be used when parameter is required or has a default value. * * @throws java.lang.IllegalArgumentException is value is null or blank diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/SimpleGetRequest.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/SimpleGetRequest.java index 1053ebece29..d2ee7a65d9f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/SimpleGetRequest.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/SimpleGetRequest.java @@ -43,6 +43,11 @@ public class SimpleGetRequest extends Request { } @Override + public boolean hasParam(String key) { + return params.keySet().contains(key); + } + + @Override public String param(String key) { return params.get(key); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java index 6a86cc48e6f..ad7e00aea17 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java @@ -48,6 +48,11 @@ public class RequestTest { return "GET"; } + @Override + public boolean hasParam(String key) { + return params.keySet().contains(key); + } + public SimpleRequest setParam(String key, @Nullable String value) { if (value != null) { params.put(key, value); @@ -114,6 +119,14 @@ public class RequestTest { } @Test + public void has_param() throws Exception { + request.setParam("a_required_string", "foo"); + + assertThat(request.hasParam("a_required_string")).isTrue(); + assertThat(request.hasParam("unknown")).isFalse(); + } + + @Test public void required_param_is_missing() throws Exception { try { request.mandatoryParam("required_param"); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/internal/SimpleGetRequestTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/internal/SimpleGetRequestTest.java index 26be2948d03..4ee4a6857e7 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/internal/SimpleGetRequestTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/internal/SimpleGetRequestTest.java @@ -34,4 +34,14 @@ public class SimpleGetRequestTest { assertThat(request.param("foo")).isEqualTo("bar"); assertThat(request.param("unknown")).isNull(); } + + @Test + public void has_param() throws Exception { + SimpleGetRequest request = new SimpleGetRequest(); + assertThat(request.method()).isEqualTo("GET"); + + request.setParam("foo", "bar"); + assertThat(request.hasParam("foo")).isTrue(); + assertThat(request.hasParam("unknown")).isFalse(); + } } |