diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-08-25 10:05:09 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 11:34:53 +0200 |
commit | 0cf6dd627a9949749ce1400a82193e33632491b8 (patch) | |
tree | aa353592d01d1f7f042d253b5295e9a8df61258e /sonar-ws | |
parent | b56de575ec830f18533a61d0ccd8523c0766a240 (diff) | |
download | sonarqube-0cf6dd627a9949749ce1400a82193e33632491b8.tar.gz sonarqube-0cf6dd627a9949749ce1400a82193e33632491b8.zip |
SONAR-9616 Handle branch in api/settings/values
Diffstat (limited to 'sonar-ws')
4 files changed, 43 insertions, 17 deletions
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 230dbd992a5..3348fdb48c5 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 @@ -53,7 +53,8 @@ public class SettingsService extends BaseService { public ValuesWsResponse values(ValuesRequest request) { GetRequest getRequest = new GetRequest(path(ACTION_VALUES)) .setParam(PARAM_KEYS, inlineMultipleParamValue(request.getKeys())) - .setParam(PARAM_COMPONENT, request.getComponent()); + .setParam(PARAM_COMPONENT, request.getComponent()) + .setParam(PARAM_BRANCH, request.getBranch()); return call(getRequest, ValuesWsResponse.parser()); } @@ -64,16 +65,14 @@ public class SettingsService extends BaseService { .setParam(PARAM_VALUES, request.getValues()) .setParam(PARAM_FIELD_VALUES, request.getFieldValues()) .setParam(PARAM_COMPONENT, request.getComponent()) - .setParam(PARAM_BRANCH, request.getBranch()) - ); + .setParam(PARAM_BRANCH, request.getBranch())); } public void reset(ResetRequest request) { call(new PostRequest(path(ACTION_RESET)) .setParam(PARAM_KEYS, inlineMultipleParamValue(request.getKeys())) .setParam(PARAM_COMPONENT, request.getComponent()) - .setParam(PARAM_BRANCH, request.getBranch()) - ); + .setParam(PARAM_BRANCH, request.getBranch())); } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ValuesRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ValuesRequest.java index 6352e845fe8..f45d8d015d6 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ValuesRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ValuesRequest.java @@ -29,12 +29,18 @@ import static java.util.Objects.requireNonNull; public class ValuesRequest { - private final String component; private final List<String> keys; + private final String component; + private final String branch; private ValuesRequest(Builder builder) { - this.component = builder.component; this.keys = builder.keys; + this.component = builder.component; + this.branch = builder.branch; + } + + public List<String> getKeys() { + return keys; } @CheckForNull @@ -42,8 +48,9 @@ public class ValuesRequest { return component; } - public List<String> getKeys() { - return keys; + @CheckForNull + public String getBranch() { + return branch; } public static Builder builder() { @@ -51,18 +58,14 @@ public class ValuesRequest { } public static class Builder { - private String component; private List<String> keys = new ArrayList<>(); + private String component; + private String branch; private Builder() { // enforce factory method use } - public Builder setComponent(@Nullable String component) { - this.component = component; - return this; - } - public Builder setKeys(List<String> keys) { this.keys = requireNonNull(keys); return this; @@ -72,6 +75,16 @@ public class ValuesRequest { return setKeys(asList(keys)); } + public Builder setComponent(@Nullable String component) { + this.component = component; + return this; + } + + public Builder setBranch(@Nullable String branch) { + this.branch = branch; + return this; + } + public ValuesRequest build() { return new ValuesRequest(this); } 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 c3c1f9c051e..247acd0247f 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 @@ -63,6 +63,7 @@ public class SettingsServiceTest { underTest.values(ValuesRequest.builder() .setKeys("sonar.debt,sonar.issue") .setComponent("KEY") + .setBranch("BRANCH") .build()); GetRequest getRequest = serviceTester.getGetRequest(); @@ -70,6 +71,7 @@ public class SettingsServiceTest { serviceTester.assertThat(getRequest) .hasParam(PARAM_KEYS, "sonar.debt,sonar.issue") .hasParam(PARAM_COMPONENT, "KEY") + .hasParam(PARAM_BRANCH, "BRANCH") .andNoOtherParam(); } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java index fc0537d2014..fa6bdf94074 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java @@ -36,24 +36,36 @@ public class ValuesRequestTest { public void create_request_with_no_component() { ValuesRequest result = underTest.setKeys("sonar.debt").build(); - assertThat(result.getComponent()).isNull(); assertThat(result.getKeys()).containsOnly("sonar.debt"); + assertThat(result.getComponent()).isNull(); + assertThat(result.getBranch()).isNull(); } @Test public void create_request_with_no_keys() { ValuesRequest result = underTest.build(); - assertThat(result.getComponent()).isNull(); assertThat(result.getKeys()).isEmpty(); + assertThat(result.getComponent()).isNull(); + assertThat(result.getBranch()).isNull(); } @Test public void create_request_with_component() { ValuesRequest result = underTest.setKeys("sonar.debt").setComponent("projectKey").build(); + assertThat(result.getKeys()).containsOnly("sonar.debt"); assertThat(result.getComponent()).isEqualTo("projectKey"); + assertThat(result.getBranch()).isNull(); + } + + @Test + public void create_request_with_component_and_branch() { + ValuesRequest result = underTest.setKeys("sonar.debt").setComponent("projectKey").setBranch("branch").build(); + assertThat(result.getKeys()).containsOnly("sonar.debt"); + assertThat(result.getComponent()).isEqualTo("projectKey"); + assertThat(result.getBranch()).isEqualTo("branch"); } } |