diff options
author | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-06-27 17:45:15 +0200 |
---|---|---|
committer | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-06-27 17:45:15 +0200 |
commit | c2db902b57064a05bfc07522162dc8b6607518e3 (patch) | |
tree | a4c5edc789d61a59d0c9cd0123c1dc8aea163ca2 /sonar-ws-client/src/test/java/org/sonar/wsclient | |
parent | b2a6ff98776eeeca3474ba969b7771c37e29a0ea (diff) | |
download | sonarqube-c2db902b57064a05bfc07522162dc8b6607518e3.tar.gz sonarqube-c2db902b57064a05bfc07522162dc8b6607518e3.zip |
SONAR-4412 Added WS client helper classes for roles management operations
Diffstat (limited to 'sonar-ws-client/src/test/java/org/sonar/wsclient')
-rw-r--r-- | sonar-ws-client/src/test/java/org/sonar/wsclient/permissions/DefaultPermissionClientTest.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/permissions/DefaultPermissionClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/permissions/DefaultPermissionClientTest.java new file mode 100644 index 00000000000..c850665b145 --- /dev/null +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/permissions/DefaultPermissionClientTest.java @@ -0,0 +1,93 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.sonar.wsclient.permissions; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.wsclient.MockHttpServerInterceptor; +import org.sonar.wsclient.internal.HttpRequestFactory; + +import java.util.Arrays; +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; + +public class DefaultPermissionClientTest { + + private HttpRequestFactory requestFactory; + private DefaultPermissionClient client; + + @Rule + public MockHttpServerInterceptor httpServer = new MockHttpServerInterceptor(); + + @Before + public void setUp() { + requestFactory = new HttpRequestFactory(httpServer.url()); + client = new DefaultPermissionClient(requestFactory); + } + + @Test + public void should_add_user_permission() { + httpServer.stubStatusCode(200); + + PermissionParameters params = PermissionParameters.create().user("daveloper").permission("admin"); + client.addPermission(params); + + assertThatRequestUrlContains("/api/permissions/add?", "user=daveloper", "permission=admin"); + } + + @Test + public void should_add_group_permission() { + httpServer.stubStatusCode(200); + + PermissionParameters params = PermissionParameters.create().group("my_group").permission("admin"); + client.addPermission(params); + + assertThatRequestUrlContains("/api/permissions/add?", "group=my_group", "permission=admin"); + } + + @Test + public void should_remove_user_permission() { + httpServer.stubStatusCode(200); + + PermissionParameters params = PermissionParameters.create().user("daveloper").permission("admin"); + client.removePermission(params); + + assertThatRequestUrlContains("/api/permissions/remove?", "user=daveloper", "permission=admin"); + } + + @Test + public void should_remove_group_permission() { + httpServer.stubStatusCode(200); + + PermissionParameters params = PermissionParameters.create().group("my_group").permission("admin"); + client.removePermission(params); + + assertThatRequestUrlContains("/api/permissions/remove?", "group=my_group", "permission=admin"); + } + + private void assertThatRequestUrlContains(String baseUrl, String... parameters) { + assertThat(httpServer.requestedPath()).startsWith(baseUrl); + List<String> requestParameters = Arrays.asList(httpServer.requestedPath().substring(baseUrl.length()).split("&")); + assertThat(requestParameters).containsOnly(parameters); + } +} |