aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-06-09 17:12:01 +0200
committerEric Hartmann <hartmann.eric@gmail.com>2017-06-14 15:43:13 +0200
commitdd5713279b5b6beccdb5cc65681dbde25898f035 (patch)
tree916d99177aefa54a1da27afd9b317a7e182a53b6 /sonar-ws
parent7a163414fe1eeb2be1754d87c9969c4a68105b5e (diff)
downloadsonarqube-dd5713279b5b6beccdb5cc65681dbde25898f035.tar.gz
sonarqube-dd5713279b5b6beccdb5cc65681dbde25898f035.zip
SONAR-9304 add integration tests
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/ChangeParentRequest.java104
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java3
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java21
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java13
4 files changed, 141 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/ChangeParentRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/ChangeParentRequest.java
new file mode 100644
index 00000000000..4ad8ec57ea5
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/ChangeParentRequest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.qualityprofile;
+
+import javax.annotation.Nullable;
+
+public class ChangeParentRequest {
+ private final String language;
+ private final String parentKey;
+ private final String parentName;
+ private final String profileKey;
+ private final String profileName;
+
+ public ChangeParentRequest(Builder builder) {
+ this.language = builder.language;
+ this.parentKey = builder.parentKey;
+ this.parentName = builder.parentName;
+ this.profileKey = builder.profileKey;
+ this.profileName = builder.profileName;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public String getParentKey() {
+ return parentKey;
+ }
+
+ public String getParentName() {
+ return parentName;
+ }
+
+ public String getProfileKey() {
+ return profileKey;
+ }
+
+ public String getProfileName() {
+ return profileName;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String language;
+ private String parentKey;
+ private String parentName;
+ private String profileKey;
+ private String profileName;
+
+ private Builder() {
+ // enforce factory method use
+ }
+
+ public Builder setLanguage(@Nullable String language) {
+ this.language = language;
+ return this;
+ }
+
+ public Builder setProfileName(@Nullable String profileName) {
+ this.profileName = profileName;
+ return this;
+ }
+
+ public Builder setProfileKey(@Nullable String profileKey) {
+ this.profileKey = profileKey;
+ return this;
+ }
+
+ public Builder setParentKey(@Nullable String parentKey) {
+ this.parentKey = parentKey;
+ return this;
+ }
+
+ public Builder setParentName(@Nullable String parentName) {
+ this.parentName = parentName;
+ return this;
+ }
+
+ public ChangeParentRequest build() {
+ return new ChangeParentRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java
index c054f13eecc..7c3f36cd380 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java
@@ -43,6 +43,7 @@ public class QualityProfileWsParameters {
public static final String ACTION_REMOVE_PROJECT = "remove_project";
public static final String ACTION_CREATE = "create";
public static final String ACTION_COPY = "copy";
+ public static final String ACTION_CHANGE_PARENT = "change_parent";
public static final String ACTION_SET_DEFAULT = "set_default";
public static final String ACTION_DELETE = "delete";
@@ -55,6 +56,8 @@ public class QualityProfileWsParameters {
public static final String PARAM_PROJECT_UUID = "projectUuid";
public static final String PARAM_FROM_KEY = "fromKey";
public static final String PARAM_TO_NAME = "toName";
+ public static final String PARAM_PARENT_NAME = "parentName";
+ public static final String PARAM_PARENT_KEY = "parentKey";
private QualityProfileWsParameters() {
// Only static stuff
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java
index 5fe3a705b16..e885f51f101 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java
@@ -30,8 +30,10 @@ import org.sonarqube.ws.client.WsConnector;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ACTIVATE_RULE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ADD_PROJECT;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_CHANGE_PARENT;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_COPY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_CREATE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_DEACTIVATE_RULE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_DELETE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_REMOVE_PROJECT;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_RESTORE;
@@ -43,6 +45,8 @@ import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_FROM_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_ORGANIZATION;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARENT_KEY;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PARENT_NAME;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_KEY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_NAME;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY;
@@ -67,6 +71,13 @@ public class QualityProfilesService extends BaseService {
call(httpRequest);
}
+ public void deactivateRule(String profileKey, String ruleKey) {
+ PostRequest httpRequest = new PostRequest(path(ACTION_DEACTIVATE_RULE));
+ httpRequest.setParam(ActivateActionParameters.PARAM_PROFILE_KEY, profileKey);
+ httpRequest.setParam(ActivateActionParameters.PARAM_RULE_KEY, ruleKey);
+ call(httpRequest);
+ }
+
public void restoreProfile(RestoreWsRequest request) {
PostRequest httpRequest = new PostRequest(path(ACTION_RESTORE));
httpRequest.setParam(PARAM_ORGANIZATION, request.getOrganization().orElse(null));
@@ -106,6 +117,7 @@ public class QualityProfilesService extends BaseService {
public CreateWsResponse create(CreateRequest request) {
PostRequest postRequest = new PostRequest(path(ACTION_CREATE))
+ .setParam(PARAM_ORGANIZATION, request.getOrganizationKey())
.setParam(PARAM_LANGUAGE, request.getLanguage())
.setParam(PARAM_PROFILE_NAME, request.getProfileName());
return call(postRequest, CreateWsResponse.parser());
@@ -119,6 +131,15 @@ public class QualityProfilesService extends BaseService {
return call(postRequest, CopyWsResponse.parser());
}
+ public void changeParent(ChangeParentRequest request) {
+ call(new PostRequest(path(ACTION_CHANGE_PARENT))
+ .setParam(PARAM_LANGUAGE, request.getLanguage())
+ .setParam(PARAM_PARENT_KEY, request.getParentKey())
+ .setParam(PARAM_PARENT_NAME, request.getParentName())
+ .setParam(PARAM_PROFILE_KEY, request.getProfileKey())
+ .setParam(PARAM_PROFILE_NAME, request.getProfileName()));
+ }
+
public void setDefault(SetDefaultRequest request) {
PostRequest postRequest = new PostRequest(path(ACTION_SET_DEFAULT))
.setParam(PARAM_PROFILE_KEY, request.getProfileKey());
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java
index 411d4662779..ae1d3c9c0f3 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java
@@ -23,6 +23,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.ws.QualityProfiles;
import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.ServiceTester;
import org.sonarqube.ws.client.WsConnector;
@@ -138,4 +139,16 @@ public class QualityProfilesServiceTest {
.hasParam(PARAM_PROFILE_KEY, "sample")
.andNoOtherParam();
}
+
+ @Test
+ public void deactivate_rule() {
+ underTest.deactivateRule("P1", "R1");
+ PostRequest request = serviceTester.getPostRequest();
+
+ serviceTester.assertThat(request)
+ .hasPath("deactivate_rule")
+ .hasParam(QualityProfileWsParameters.ActivateActionParameters.PARAM_PROFILE_KEY, "P1")
+ .hasParam(QualityProfileWsParameters.ActivateActionParameters.PARAM_RULE_KEY, "R1")
+ .andNoOtherParam();
+ }
}