From ac946d0b0e7633eb9ac9c98cf6b1adcb932abf35 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Fri, 26 Aug 2016 13:43:08 +0200 Subject: SONAR-8003 WS settings/set handles multi value settings --- .../org/sonarqube/ws/client/setting/SetRequest.java | 21 ++++++++++++++++++--- .../ws/client/setting/SettingsWsParameters.java | 1 + .../sonarqube/ws/client/setting/SetRequestTest.java | 11 +++++------ 3 files changed, 24 insertions(+), 9 deletions(-) (limited to 'sonar-ws') diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SetRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SetRequest.java index ee19ef6fc1d..ab5c1bd340e 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SetRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SetRequest.java @@ -20,20 +20,24 @@ package org.sonarqube.ws.client.setting; +import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Collections.emptyList; public class SetRequest { private final String key; private final String value; + private final List values; private final String componentId; private final String componentKey; public SetRequest(Builder builder) { this.key = builder.key; this.value = builder.value; + this.values = builder.values; this.componentId = builder.componentId; this.componentKey = builder.componentKey; } @@ -42,10 +46,15 @@ public class SetRequest { return key; } + @CheckForNull public String getValue() { return value; } + public List getValues() { + return values; + } + @CheckForNull public String getComponentId() { return componentId; @@ -63,6 +72,7 @@ public class SetRequest { public static class Builder { private String key; private String value; + private List values = emptyList(); private String componentId; private String componentKey; @@ -75,11 +85,16 @@ public class SetRequest { return this; } - public Builder setValue(String value) { + public Builder setValue(@Nullable String value) { this.value = value; return this; } + public Builder setValues(List values) { + this.values = values; + return this; + } + public Builder setComponentId(@Nullable String componentId) { this.componentId = componentId; return this; @@ -91,8 +106,8 @@ public class SetRequest { } public SetRequest build() { - checkArgument(key != null && !key.isEmpty(), "Setting key is mandatory and must not be empty."); - checkArgument(value != null && !value.isEmpty(), "Setting value is mandatory and must not be empty."); + checkArgument(key != null && !key.isEmpty(), "Setting key is mandatory and must not be empty"); + checkArgument(values != null, "Setting values must not be null"); return new SetRequest(this); } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsWsParameters.java index 74daf45d569..5c6e35d243d 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsWsParameters.java @@ -33,6 +33,7 @@ public class SettingsWsParameters { public static final String PARAM_KEYS = "keys"; public static final String PARAM_KEY = "key"; public static final String PARAM_VALUE = "value"; + public static final String PARAM_VALUES = "values"; private SettingsWsParameters() { // Only static stuff diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SetRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SetRequestTest.java index b1e48020a30..461daa1d29f 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SetRequestTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SetRequestTest.java @@ -39,6 +39,7 @@ public class SetRequestTest { assertThat(result.getKey()).isEqualTo("my.key"); assertThat(result.getValue()).isEqualTo("my value"); + assertThat(result.getValues()).isNotNull().isEmpty(); assertThat(result.getComponentKey()).isNull(); assertThat(result.getComponentId()).isNull(); } @@ -66,6 +67,7 @@ public class SetRequestTest { @Test public void fail_when_empty_key() { expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Setting key is mandatory and must not be empty"); underTest .setKey("") @@ -74,13 +76,10 @@ public class SetRequestTest { } @Test - public void fail_when_empty_value() { + public void fail_when_values_is_null() { expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Setting values must not be null"); - underTest - .setKey("key") - .setValue(null) - .build(); + underTest.setKey("my.key").setValues(null).build(); } - } -- cgit v1.2.3