aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-23 17:50:44 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-25 11:29:41 +0200
commit7d3c46217fc528ab36b53db9c0c431d7365e8c4e (patch)
treef40327cc3a3c3ee9235d7bacaadccbcaa6378773 /sonar-ws/src/test
parent4beb2af88d3e1378d19bbaec1859c4c59acb6252 (diff)
downloadsonarqube-7d3c46217fc528ab36b53db9c0c431d7365e8c4e.tar.gz
sonarqube-7d3c46217fc528ab36b53db9c0c431d7365e8c4e.zip
SONAR-7969 Create client for values WS
Diffstat (limited to 'sonar-ws/src/test')
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java25
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java81
2 files changed, 101 insertions, 5 deletions
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 e8578b56990..57607b16704 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
@@ -22,7 +22,8 @@ package org.sonarqube.ws.client.setting;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarqube.ws.Settings;
+import org.sonarqube.ws.Settings.ListDefinitionsWsResponse;
+import org.sonarqube.ws.Settings.ValuesWsResponse;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.ServiceTester;
import org.sonarqube.ws.client.WsConnector;
@@ -30,6 +31,7 @@ import org.sonarqube.ws.client.WsConnector;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_KEY;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEYS;
public class SettingsServiceTest {
@@ -40,15 +42,28 @@ public class SettingsServiceTest {
@Test
public void list_definitions() {
- ListDefinitionsRequest request = ListDefinitionsRequest.builder()
+ underTest.listDefinitions(ListDefinitionsRequest.builder()
.setComponentKey("KEY")
- .build();
+ .build());
+ GetRequest getRequest = serviceTester.getGetRequest();
+
+ assertThat(serviceTester.getGetParser()).isSameAs(ListDefinitionsWsResponse.parser());
+ serviceTester.assertThat(getRequest)
+ .hasParam(PARAM_COMPONENT_KEY, "KEY")
+ .andNoOtherParam();
+ }
- underTest.listDefinitions(request);
+ @Test
+ public void values() {
+ underTest.values(ValuesRequest.builder()
+ .setKeys("sonar.debt,sonar.issue")
+ .setComponentKey("KEY")
+ .build());
GetRequest getRequest = serviceTester.getGetRequest();
- assertThat(serviceTester.getGetParser()).isSameAs(Settings.ListDefinitionsWsResponse.parser());
+ assertThat(serviceTester.getGetParser()).isSameAs(ValuesWsResponse.parser());
serviceTester.assertThat(getRequest)
+ .hasParam(PARAM_KEYS, "sonar.debt,sonar.issue")
.hasParam(PARAM_COMPONENT_KEY, "KEY")
.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
new file mode 100644
index 00000000000..1ee0d1763bd
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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 java.util.List;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ValuesRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ ValuesRequest.Builder underTest = ValuesRequest.builder();
+
+ @Test
+ public void create_request_with_no_component() {
+ ValuesRequest result = underTest.setKeys("sonar.debt").build();
+
+ assertThat(result.getComponentId()).isNull();
+ assertThat(result.getComponentKey()).isNull();
+ assertThat(result.getKeys()).containsOnly("sonar.debt");
+ }
+
+ @Test
+ public void create_request_with_component_id() {
+ ValuesRequest result = underTest.setKeys("sonar.debt").setComponentId("projectId").build();
+
+ assertThat(result.getComponentId()).isEqualTo("projectId");
+ assertThat(result.getComponentKey()).isNull();
+ assertThat(result.getKeys()).containsOnly("sonar.debt");
+ }
+
+ @Test
+ public void create_request_with_component_key() {
+ ValuesRequest result = underTest.setKeys("sonar.debt").setComponentKey("projectKey").build();
+
+ assertThat(result.getComponentId()).isNull();
+ assertThat(result.getComponentKey()).isEqualTo("projectKey");
+ assertThat(result.getKeys()).containsOnly("sonar.debt");
+ }
+
+ @Test
+ public void fail_when_keys_is_null() throws Exception {
+ expectedException.expect(NullPointerException.class);
+ underTest
+ .setKeys((List<String>) null)
+ .setComponentId("projectId")
+ .build();
+ }
+
+ @Test
+ public void fail_when_keys_is_empty() throws Exception {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("'keys' cannot be empty");
+
+ underTest.setComponentId("projectId").build();
+ }
+
+}