aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-03-03 19:23:58 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-03-03 19:30:58 +0100
commit7c9255749502f676b11c9d7aaf71d3bc958109e1 (patch)
tree546a2a9505fa3479921bc95b35b0e90b96b4be33 /sonar-plugin-api
parent255bbbeb02638b930f934f3c550cc8b6d661cae5 (diff)
downloadsonarqube-7c9255749502f676b11c9d7aaf71d3bc958109e1.tar.gz
sonarqube-7c9255749502f676b11c9d7aaf71d3bc958109e1.zip
SONAR-5010 rename some methods before publishing API
Conflicts: sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java59
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java55
2 files changed, 85 insertions, 29 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 d033fe7bb07..91c992328d0 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
@@ -36,15 +36,12 @@ public abstract class Request {
*/
public abstract String method();
- @CheckForNull
- public abstract String param(String key);
-
/**
- * Returns value of a required parameter
+ * Returns value of a mandatory parameter
*
* @throws java.lang.IllegalArgumentException is value is null or blank
*/
- public String requiredParam(String key) {
+ public String mandatoryParam(String key) {
String value = param(key);
if (StringUtils.isBlank(value)) {
throw new IllegalArgumentException(String.format("Parameter '%s' is missing", key));
@@ -52,29 +49,73 @@ public abstract class Request {
return value;
}
+ /**
+ * Returns value of a mandatory parameter
+ *
+ * @throws java.lang.IllegalArgumentException is value is null or blank
+ */
+ public boolean mandatoryParamAsBoolean(String key) {
+ String s = mandatoryParam(key);
+ return Boolean.parseBoolean(s);
+ }
+
+ /**
+ * Returns value of a mandatory parameter
+ *
+ * @throws java.lang.IllegalArgumentException is value is null or blank
+ */
+ public int mandatoryParamAsInt(String key) {
+ String s = mandatoryParam(key);
+ return Integer.parseInt(s);
+ }
+
+ /**
+ * Returns value of a mandatory parameter
+ *
+ * @throws java.lang.IllegalArgumentException is value is null or blank
+ */
+ public long mandatoryParamAsLong(String key) {
+ String s = mandatoryParam(key);
+ return Long.parseLong(s);
+ }
+
+ @CheckForNull
+ public abstract String param(String key);
+
@CheckForNull
public String param(String key, @CheckForNull String defaultValue) {
return StringUtils.defaultString(param(key), defaultValue);
}
@CheckForNull
- public Integer intParam(String key) {
+ public Integer paramAsInt(String key) {
String s = param(key);
return s == null ? null : Integer.parseInt(s);
}
- public int intParam(String key, int defaultValue) {
+ public int paramAsInt(String key, int defaultValue) {
String s = param(key);
return s == null ? defaultValue : Integer.parseInt(s);
}
@CheckForNull
- public Boolean booleanParam(String key) {
+ public Long paramAsLong(String key) {
+ String s = param(key);
+ return s == null ? null : Long.parseLong(s);
+ }
+
+ public long paramAsLong(String key, long defaultValue) {
+ String s = param(key);
+ return s == null ? defaultValue : Long.parseLong(s);
+ }
+
+ @CheckForNull
+ public Boolean paramAsBoolean(String key) {
String s = param(key);
return s == null ? null : Boolean.parseBoolean(s);
}
- public boolean booleanParam(String key, boolean defaultValue) {
+ public boolean paramAsBoolean(String key, boolean defaultValue) {
String s = param(key);
return s == null ? defaultValue : Boolean.parseBoolean(s);
}
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 944412644f5..279d4c34582 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
@@ -68,9 +68,9 @@ public class RequestTest {
SimpleRequest request = new SimpleRequest(mock(WebService.Action.class));
@Test
- public void required_param_is_missing() throws Exception {
+ public void mandatory_param_is_missing() throws Exception {
try {
- request.requiredParam("foo");
+ request.mandatoryParam("foo");
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Parameter 'foo' is missing");
@@ -78,9 +78,16 @@ public class RequestTest {
}
@Test
- public void required_param_is_set() throws Exception {
- String value = request.setParam("foo", "bar").requiredParam("foo");
- assertThat(value).isEqualTo("bar");
+ public void mandatory_param_is_set() throws Exception {
+ request.setParam("a_string", "foo");
+ request.setParam("a_long", "42");
+ request.setParam("a_int", "42");
+ request.setParam("a_boolean", "true");
+
+ assertThat(request.mandatoryParam("a_string")).isEqualTo("foo");
+ assertThat(request.mandatoryParamAsBoolean("a_boolean")).isTrue();
+ assertThat(request.mandatoryParamAsInt("a_int")).isEqualTo(42);
+ assertThat(request.mandatoryParamAsLong("a_long")).isEqualTo(42L);
}
@Test
@@ -90,28 +97,36 @@ public class RequestTest {
}
@Test
- public void string_param() throws Exception {
+ public void param_as_string() throws Exception {
String value = request.setParam("foo", "bar").param("foo", "default");
assertThat(value).isEqualTo("bar");
}
@Test
- public void int_param() throws Exception {
- assertThat(request.setParam("foo", "123").intParam("foo")).isEqualTo(123);
- assertThat(request.setParam("foo", "123").intParam("xxx")).isNull();
- assertThat(request.setParam("foo", "123").intParam("foo", 456)).isEqualTo(123);
- assertThat(request.setParam("foo", "123").intParam("xxx", 456)).isEqualTo(456);
+ public void param_as_int() throws Exception {
+ assertThat(request.setParam("foo", "123").paramAsInt("foo")).isEqualTo(123);
+ assertThat(request.setParam("foo", "123").paramAsInt("xxx")).isNull();
+ assertThat(request.setParam("foo", "123").paramAsInt("foo", 456)).isEqualTo(123);
+ assertThat(request.setParam("foo", "123").paramAsInt("xxx", 456)).isEqualTo(456);
+ }
+
+ @Test
+ public void param_as_long() throws Exception {
+ assertThat(request.setParam("foo", "123").paramAsLong("foo")).isEqualTo(123L);
+ assertThat(request.setParam("foo", "123").paramAsLong("xxx")).isNull();
+ assertThat(request.setParam("foo", "123").paramAsLong("foo", 456L)).isEqualTo(123L);
+ assertThat(request.setParam("foo", "123").paramAsLong("xxx", 456L)).isEqualTo(456L);
}
@Test
- public void boolean_param() throws Exception {
- assertThat(request.setParam("foo", "true").booleanParam("foo")).isTrue();
- assertThat(request.setParam("foo", "false").booleanParam("foo")).isFalse();
- assertThat(request.setParam("foo", "true").booleanParam("xxx")).isNull();
-
- assertThat(request.setParam("foo", "true").booleanParam("foo", true)).isTrue();
- assertThat(request.setParam("foo", "true").booleanParam("foo", false)).isTrue();
- assertThat(request.setParam("foo", "true").booleanParam("xxx", true)).isTrue();
- assertThat(request.setParam("foo", "true").booleanParam("xxx", false)).isFalse();
+ public void param_as_boolean() throws Exception {
+ assertThat(request.setParam("foo", "true").paramAsBoolean("foo")).isTrue();
+ assertThat(request.setParam("foo", "false").paramAsBoolean("foo")).isFalse();
+ assertThat(request.setParam("foo", "true").paramAsBoolean("xxx")).isNull();
+
+ assertThat(request.setParam("foo", "true").paramAsBoolean("foo", true)).isTrue();
+ assertThat(request.setParam("foo", "true").paramAsBoolean("foo", false)).isTrue();
+ assertThat(request.setParam("foo", "true").paramAsBoolean("xxx", true)).isTrue();
+ assertThat(request.setParam("foo", "true").paramAsBoolean("xxx", false)).isFalse();
}
}