aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-24 17:10:21 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-26 11:32:00 +0200
commit699fb2c4afbd4954fbc597a9a8bb6abaf6e2e113 (patch)
tree359ab1339ba5731fde3eb7e810f03bec79f84750 /sonar-ws
parent71696ce1a2a5c77fa8b59a7517d7900ee1b2f6f8 (diff)
downloadsonarqube-699fb2c4afbd4954fbc597a9a8bb6abaf6e2e113.tar.gz
sonarqube-699fb2c4afbd4954fbc597a9a8bb6abaf6e2e113.zip
SONAR-7986 Create /api/settings/reset WS to remove the value of a setting
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ResetRequest.java86
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsService.java8
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsWsParameters.java1
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ResetRequestTest.java49
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java17
5 files changed, 158 insertions, 3 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ResetRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ResetRequest.java
new file mode 100644
index 00000000000..184d9fb9731
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ResetRequest.java
@@ -0,0 +1,86 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.sonarqube.ws.client.setting;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class ResetRequest {
+ private final String key;
+ private final String componentId;
+ private final String componentKey;
+
+ public ResetRequest(Builder builder) {
+ this.key = builder.key;
+ this.componentId = builder.componentId;
+ this.componentKey = builder.componentKey;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ @CheckForNull
+ public String getComponentId() {
+ return componentId;
+ }
+
+ @CheckForNull
+ public String getComponentKey() {
+ return componentKey;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String key;
+ private String componentId;
+ private String componentKey;
+
+ private Builder() {
+ // enforce factory method use
+ }
+
+ public Builder setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public Builder setComponentId(@Nullable String componentId) {
+ this.componentId = componentId;
+ return this;
+ }
+
+ public Builder setComponentKey(@Nullable String componentKey) {
+ this.componentKey = componentKey;
+ return this;
+ }
+
+ public ResetRequest build() {
+ checkArgument(key != null && !key.isEmpty(), "Setting key is mandatory and must not be empty.");
+ return new ResetRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsService.java
index c30b418495e..f55de07baca 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsService.java
@@ -29,6 +29,7 @@ import org.sonarqube.ws.client.WsConnector;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_KEY;
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_LIST_DEFINITIONS;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_RESET;
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_SET;
import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_VALUES;
import static org.sonarqube.ws.client.setting.SettingsWsParameters.CONTROLLER_SETTINGS;
@@ -64,4 +65,11 @@ public class SettingsService extends BaseService {
.setParam(PARAM_COMPONENT_KEY, request.getComponentKey()));
}
+ public void reset(ResetRequest request) {
+ call(new PostRequest(path(ACTION_RESET))
+ .setParam(PARAM_KEY, request.getKey())
+ .setParam(PARAM_COMPONENT_ID, request.getComponentId())
+ .setParam(PARAM_COMPONENT_KEY, request.getComponentKey()));
+ }
+
}
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 04f8fe24a65..74daf45d569 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
@@ -26,6 +26,7 @@ public class SettingsWsParameters {
public static final String ACTION_LIST_DEFINITIONS = "list_definitions";
public static final String ACTION_VALUES = "values";
public static final String ACTION_SET = "set";
+ public static final String ACTION_RESET = "reset";
public static final String PARAM_COMPONENT_ID = "componentId";
public static final String PARAM_COMPONENT_KEY = "componentKey";
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ResetRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ResetRequestTest.java
new file mode 100644
index 00000000000..edf7c333885
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ResetRequestTest.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.sonarqube.ws.client.setting;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ResetRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ ResetRequest.Builder underTest = ResetRequest.builder();
+
+ @Test
+ public void create_set_request() {
+ ResetRequest result = underTest.setKey("my.key").build();
+
+ assertThat(result.getKey()).isEqualTo("my.key");
+ }
+
+ @Test
+ public void fail_when_empty_key() {
+ expectedException.expect(IllegalArgumentException.class);
+ underTest.setKey("").build();
+ }
+
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java
index 1c34102cf5a..41b403e82c8 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java
@@ -25,7 +25,6 @@ import org.junit.Test;
import org.sonarqube.ws.Settings.ListDefinitionsWsResponse;
import org.sonarqube.ws.Settings.ValuesWsResponse;
import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.ServiceTester;
import org.sonarqube.ws.client.WsConnector;
@@ -78,13 +77,25 @@ public class SettingsServiceTest {
.setValue("8h")
.setComponentKey("KEY")
.build());
- PostRequest request = serviceTester.getPostRequest();
- serviceTester.assertThat(request)
+ serviceTester.assertThat(serviceTester.getPostRequest())
.hasParam(PARAM_KEY, "sonar.debt")
.hasParam(PARAM_VALUE, "8h")
.hasParam(PARAM_COMPONENT_KEY, "KEY")
.andNoOtherParam();
}
+ @Test
+ public void reset() {
+ underTest.reset(ResetRequest.builder()
+ .setKey("sonar.debt")
+ .setComponentKey("KEY")
+ .build());
+
+ serviceTester.assertThat(serviceTester.getPostRequest())
+ .hasParam(PARAM_KEY, "sonar.debt")
+ .hasParam(PARAM_COMPONENT_KEY, "KEY")
+ .andNoOtherParam();
+ }
+
}