aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-07-06 14:21:05 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-07-11 08:58:34 +0200
commit75e926deef21688a74904b1feae2a687309a6ab3 (patch)
tree75f551cccf3900744b6a84dfd967b21cfc654822 /sonar-ws
parent6f107dcbe90b0fea564e1ecaa96643bfc539329a (diff)
downloadsonarqube-75e926deef21688a74904b1feae2a687309a6ab3.tar.gz
sonarqube-75e926deef21688a74904b1feae2a687309a6ab3.zip
SONAR-9480 fix support of multiple docs to recover with same id
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/rule/CreateWsRequest.java131
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesService.java14
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/rule/RulesServiceTest.java28
3 files changed, 173 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/CreateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/CreateWsRequest.java
new file mode 100644
index 00000000000..9f6c2956d4a
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/CreateWsRequest.java
@@ -0,0 +1,131 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info 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.rule;
+
+public class CreateWsRequest {
+
+ private String customKey;
+ private String markdownDescription;
+ private String name;
+ private String params;
+ private Boolean preventReactivation;
+ private String severity;
+ private String status;
+ private String templateKey;
+
+ private CreateWsRequest(Builder builder) {
+ this.customKey = builder.customKey;
+ this.markdownDescription = builder.markdownDescription;
+ this.name = builder.name;
+ this.params = builder.params;
+ this.preventReactivation = builder.preventReactivation;
+ this.severity = builder.severity;
+ this.status = builder.status;
+ this.templateKey = builder.templateKey;
+ }
+
+ public String getCustomKey() {
+ return customKey;
+ }
+
+ public String getMarkdownDescription() {
+ return markdownDescription;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getParams() {
+ return params;
+ }
+
+ public Boolean getPreventReactivation() {
+ return preventReactivation;
+ }
+
+ public String getSeverity() {
+ return severity;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public String getTemplateKey() {
+ return templateKey;
+ }
+
+ public static class Builder {
+ private String customKey;
+ private String markdownDescription;
+ private String name;
+ private String params;
+ private Boolean preventReactivation;
+ private String severity;
+ private String status;
+ private String templateKey;
+
+ public Builder setCustomKey(String customKey) {
+ this.customKey = customKey;
+ return this;
+ }
+
+ public Builder setMarkdownDescription(String markdownDescription) {
+ this.markdownDescription = markdownDescription;
+ return this;
+ }
+
+ public Builder setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder setParams(String params) {
+ this.params = params;
+ return this;
+ }
+
+ public Builder setPreventReactivation(Boolean preventReactivation) {
+ this.preventReactivation = preventReactivation;
+ return this;
+ }
+
+ public Builder setSeverity(String severity) {
+ this.severity = severity;
+ return this;
+ }
+
+ public Builder setStatus(String status) {
+ this.status = status;
+ return this;
+ }
+
+ public Builder setTemplateKey(String templateKey) {
+ this.templateKey = templateKey;
+ return this;
+ }
+
+ public CreateWsRequest build() {
+ return new CreateWsRequest(this);
+ }
+ }
+
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesService.java
index 870fd294660..e744ff84ea5 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/rule/RulesService.java
@@ -24,6 +24,7 @@ import org.sonarqube.ws.Rules;
import org.sonarqube.ws.Rules.SearchResponse;
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.rule.RulesWsParameters.PARAM_ACTIVATION;
@@ -82,4 +83,17 @@ public class RulesService extends BaseService {
.setParam("key", key);
return call(request, Rules.ShowResponse.parser());
}
+
+ public void create(CreateWsRequest request) {
+ PostRequest httpRequest = new PostRequest(path("create"));
+ httpRequest.setParam("custom_key", request.getCustomKey());
+ httpRequest.setParam("markdown_description", request.getMarkdownDescription());
+ httpRequest.setParam("name", request.getName());
+ httpRequest.setParam("params", request.getParams());
+ httpRequest.setParam("prevent_reactivation", request.getPreventReactivation());
+ httpRequest.setParam("severity", request.getSeverity());
+ httpRequest.setParam("status", request.getStatus());
+ httpRequest.setParam("template_key", request.getTemplateKey());
+ call(httpRequest);
+ }
}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/rule/RulesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/rule/RulesServiceTest.java
index ae38a45e491..45248faa16b 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/rule/RulesServiceTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/rule/RulesServiceTest.java
@@ -26,6 +26,7 @@ import org.junit.Test;
import org.sonarqube.ws.Rules;
import org.sonarqube.ws.Rules.SearchResponse;
import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.ServiceTester;
import org.sonarqube.ws.client.WsConnector;
@@ -153,4 +154,31 @@ public class RulesServiceTest {
.hasParam("key", "the-rule/key")
.andNoOtherParam();
}
+
+ @Test
+ public void test_create() {
+ underTest.create(new CreateWsRequest.Builder()
+ .setTemplateKey("the-template-key")
+ .setCustomKey("the-custom-key")
+ .setSeverity("BLOCKER")
+ .setParams("the-params")
+ .setPreventReactivation(true)
+ .setMarkdownDescription("the-desc")
+ .setStatus("BETA")
+ .setName("the-name")
+ .build());
+
+ PostRequest postRequest = serviceTester.getPostRequest();
+ serviceTester.assertThat(postRequest)
+ .hasPath("create")
+ .hasParam("template_key", "the-template-key")
+ .hasParam("custom_key", "the-custom-key")
+ .hasParam("severity", "BLOCKER")
+ .hasParam("params", "the-params")
+ .hasParam("prevent_reactivation", "true")
+ .hasParam("markdown_description", "the-desc")
+ .hasParam("status", "BETA")
+ .hasParam("name", "the-name")
+ .andNoOtherParam();
+ }
}