aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-08-03 15:36:53 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-08-05 14:31:15 +0200
commit645d874eda971f79a0927aa6370adb9489f148b7 (patch)
tree242f65e73652307ae524312427d00722555735a2 /sonar-ws
parent982927e716d5e6a0659c7a7157c3793bef761e76 (diff)
downloadsonarqube-645d874eda971f79a0927aa6370adb9489f148b7.tar.gz
sonarqube-645d874eda971f79a0927aa6370adb9489f148b7.zip
SONAR-7928 SONAR-4770 Create WS api/components/update_key
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java11
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java14
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/UpdateWsRequest.java86
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/component/UpdateWsRequestTest.java49
4 files changed, 154 insertions, 6 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java
index 24154b93a2e..ffcbe8715ed 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java
@@ -25,6 +25,7 @@ import org.sonarqube.ws.WsComponents.ShowWsResponse;
import org.sonarqube.ws.WsComponents.TreeWsResponse;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SHOW;
@@ -33,6 +34,7 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BAS
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_KEY;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_KEY;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_NEW_KEY;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY;
@@ -70,4 +72,13 @@ public class ComponentsService extends BaseService {
.setParam(PARAM_KEY, request.getKey());
return call(get, ShowWsResponse.parser());
}
+
+ public void updateKey(UpdateWsRequest request) {
+ PostRequest post = new PostRequest(path("update_key"))
+ .setParam(PARAM_ID, request.getId())
+ .setParam(PARAM_KEY, request.getKey())
+ .setParam(PARAM_NEW_KEY, request.getNewKey());
+
+ call(post);
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
index b85fea13bbd..456b46985a4 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
@@ -20,20 +20,22 @@
package org.sonarqube.ws.client.component;
public class ComponentsWsParameters {
- private ComponentsWsParameters() {
- // static utility class
- }
-
- //actions
+ // actions
public static final String ACTION_TREE = "tree";
- public static final String ACTION_SHOW = "show";
+ public static final String ACTION_SHOW = "show";
// parameters
public static final String PARAM_QUALIFIERS = "qualifiers";
+
public static final String PARAM_LANGUAGE = "language";
public static final String PARAM_BASE_COMPONENT_ID = "baseComponentId";
public static final String PARAM_BASE_COMPONENT_KEY = "baseComponentKey";
public static final String PARAM_STRATEGY = "strategy";
public static final String PARAM_ID = "id";
public static final String PARAM_KEY = "key";
+ public static final String PARAM_NEW_KEY = "newKey";
+
+ private ComponentsWsParameters() {
+ // static utility class
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/UpdateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/UpdateWsRequest.java
new file mode 100644
index 00000000000..b93d4892c93
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/UpdateWsRequest.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.component;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class UpdateWsRequest {
+ private final String id;
+ private final String key;
+ private final String newKey;
+
+ public UpdateWsRequest(Builder builder) {
+ this.id = builder.id;
+ this.key = builder.key;
+ this.newKey = builder.newKey;
+ }
+
+ @CheckForNull
+ public String getId() {
+ return id;
+ }
+
+ @CheckForNull
+ public String getKey() {
+ return key;
+ }
+
+ public String getNewKey() {
+ return newKey;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String id;
+ private String key;
+ private String newKey;
+
+ private Builder() {
+ // enforce method constructor
+ }
+
+ public Builder setId(@Nullable String id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder setKey(@Nullable String key) {
+ this.key = key;
+ return this;
+ }
+
+ public Builder setNewKey(String newKey) {
+ this.newKey = newKey;
+ return this;
+ }
+
+ public UpdateWsRequest build() {
+ checkArgument(newKey != null && !newKey.isEmpty(), "The new key must not be empty");
+ return new UpdateWsRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/component/UpdateWsRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/UpdateWsRequestTest.java
new file mode 100644
index 00000000000..76d0a307c2f
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/UpdateWsRequestTest.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.component;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class UpdateWsRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ UpdateWsRequest.Builder underTest = UpdateWsRequest.builder();
+
+ @Test
+ public void fail_if_new_key_is_null() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("The new key must not be empty");
+
+ underTest.setNewKey(null).build();
+ }
+
+ @Test
+ public void fail_if_new_key_is_empty() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("The new key must not be empty");
+
+ underTest.setNewKey("").build();
+ }
+}