aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-12-16 11:05:21 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-12-19 10:12:50 +0100
commit3a3bf3073419bc6c21a67965a9f8259dbb164fc6 (patch)
tree70c9e66145034921e5e8003f7bad21b352912719 /sonar-ws
parent7f7ebdb0510b26cf861b6eae66d11b63d98bfcd1 (diff)
downloadsonarqube-3a3bf3073419bc6c21a67965a9f8259dbb164fc6.tar.gz
sonarqube-3a3bf3073419bc6c21a67965a9f8259dbb164fc6.zip
SONAR-7287 Create WS api/favorites/add
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java8
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java3
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesService.java41
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesWsParameters.java33
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/package-info.java25
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/FavoritesServiceTest.java46
6 files changed, 156 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
index e75239fd506..f8ab3a2abf1 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
@@ -21,6 +21,7 @@ package org.sonarqube.ws.client;
import org.sonarqube.ws.client.ce.CeService;
import org.sonarqube.ws.client.component.ComponentsService;
+import org.sonarqube.ws.client.favorite.FavoritesService;
import org.sonarqube.ws.client.issue.IssuesService;
import org.sonarqube.ws.client.measure.MeasuresService;
import org.sonarqube.ws.client.organization.OrganizationService;
@@ -48,6 +49,7 @@ class DefaultWsClient implements WsClient {
private final OrganizationService organizations;
private final PermissionsService permissionsService;
private final ComponentsService componentsService;
+ private final FavoritesService favoritesService;
private final QualityProfilesService qualityProfilesService;
private final IssuesService issuesService;
private final UserTokensService userTokensService;
@@ -67,6 +69,7 @@ class DefaultWsClient implements WsClient {
this.organizations = new OrganizationService(wsConnector);
this.permissionsService = new PermissionsService(wsConnector);
this.componentsService = new ComponentsService(wsConnector);
+ this.favoritesService = new FavoritesService(wsConnector);
this.qualityProfilesService = new QualityProfilesService(wsConnector);
this.issuesService = new IssuesService(wsConnector);
this.userTokensService = new UserTokensService(wsConnector);
@@ -103,6 +106,11 @@ class DefaultWsClient implements WsClient {
}
@Override
+ public FavoritesService favorites() {
+ return favoritesService;
+ }
+
+ @Override
public QualityProfilesService qualityProfiles() {
return qualityProfilesService;
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
index d2317c16270..a14da6696e9 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
@@ -21,6 +21,7 @@ package org.sonarqube.ws.client;
import org.sonarqube.ws.client.ce.CeService;
import org.sonarqube.ws.client.component.ComponentsService;
+import org.sonarqube.ws.client.favorite.FavoritesService;
import org.sonarqube.ws.client.issue.IssuesService;
import org.sonarqube.ws.client.measure.MeasuresService;
import org.sonarqube.ws.client.organization.OrganizationService;
@@ -59,6 +60,8 @@ public interface WsClient {
ComponentsService components();
+ FavoritesService favorites();
+
IssuesService issues();
PermissionsService permissions();
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesService.java
new file mode 100644
index 00000000000..dab17b13317
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesService.java
@@ -0,0 +1,41 @@
+/*
+ * 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.favorite;
+
+import org.sonarqube.ws.client.BaseService;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.sonarqube.ws.client.favorite.FavoritesWsParameters.ACTION_ADD;
+import static org.sonarqube.ws.client.favorite.FavoritesWsParameters.CONTROLLER_FAVORITES;
+import static org.sonarqube.ws.client.favorite.FavoritesWsParameters.PARAM_COMPONENT;
+
+public class FavoritesService extends BaseService{
+ public FavoritesService(WsConnector wsConnector) {
+ super(wsConnector, CONTROLLER_FAVORITES);
+ }
+
+ public void add(String component) {
+ PostRequest post = new PostRequest(path(ACTION_ADD)).setParam(PARAM_COMPONENT, component);
+
+ call(post);
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesWsParameters.java
new file mode 100644
index 00000000000..5349f5fcf34
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesWsParameters.java
@@ -0,0 +1,33 @@
+/*
+ * 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.favorite;
+
+public class FavoritesWsParameters {
+ public static final String CONTROLLER_FAVORITES = "api/favorites";
+
+ public static final String ACTION_ADD = "add";
+
+ public static final String PARAM_COMPONENT = "component";
+
+ private FavoritesWsParameters() {
+ // prevent instantiation
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/package-info.java
new file mode 100644
index 00000000000..d918104fa2e
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonarqube.ws.client.favorite;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/FavoritesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/FavoritesServiceTest.java
new file mode 100644
index 00000000000..4b6c8a40feb
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/FavoritesServiceTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.favorite;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.client.ServiceTester;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.mockito.Mockito.mock;
+import static org.sonarqube.ws.client.favorite.FavoritesWsParameters.PARAM_COMPONENT;
+
+public class FavoritesServiceTest {
+ @Rule
+ public ServiceTester<FavoritesService> serviceTester = new ServiceTester<>(new FavoritesService(mock(WsConnector.class)));
+
+ private FavoritesService underTest = serviceTester.getInstanceUnderTest();
+
+ @Test
+ public void add() {
+ underTest.add("my_project");
+
+ serviceTester.assertThat(serviceTester.getPostRequest())
+ .hasPath("add")
+ .hasParam(PARAM_COMPONENT, "my_project")
+ .andNoOtherParam();
+ }
+}