diff options
Diffstat (limited to 'sonar-ws-client')
2 files changed, 69 insertions, 4 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/PermissionParameters.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/PermissionParameters.java index 1cdd4dc4240..422235e8545 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/PermissionParameters.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/PermissionParameters.java @@ -45,6 +45,11 @@ public class PermissionParameters { return this; } + public PermissionParameters component(String component) { + params.put("component", component); + return this; + } + public PermissionParameters permission(String permission) { params.put("permission", permission); return this; 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 index cfff8516dde..83d429e8b73 100644 --- 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 @@ -45,7 +45,7 @@ public class DefaultPermissionClientTest { } @Test - public void should_add_user_permission() { + public void should_add_global_user_permission() { httpServer.stubStatusCode(200); PermissionParameters params = PermissionParameters.create().user("daveloper").permission("admin"); @@ -59,7 +59,22 @@ public class DefaultPermissionClientTest { } @Test - public void should_add_group_permission() { + public void should_add_component_user_permission() { + httpServer.stubStatusCode(200); + + PermissionParameters params = PermissionParameters.create().user("daveloper").component("org.sample.Sample").permission("admin"); + client.addPermission(params); + + assertThat(httpServer.requestedPath()).isEqualTo("/api/permissions/add"); + assertThat(httpServer.requestParams()).includes( + entry("user", "daveloper"), + entry("component", "org.sample.Sample"), + entry("permission", "admin") + ); + } + + @Test + public void should_add_global_group_permission() { httpServer.stubStatusCode(200); PermissionParameters params = PermissionParameters.create().group("my_group").permission("admin"); @@ -73,7 +88,22 @@ public class DefaultPermissionClientTest { } @Test - public void should_remove_user_permission() { + public void should_add_component_group_permission() { + httpServer.stubStatusCode(200); + + PermissionParameters params = PermissionParameters.create().group("my_group").component("org.sample.Sample").permission("admin"); + client.addPermission(params); + + assertThat(httpServer.requestedPath()).isEqualTo("/api/permissions/add"); + assertThat(httpServer.requestParams()).includes( + entry("group", "my_group"), + entry("component", "org.sample.Sample"), + entry("permission", "admin") + ); + } + + @Test + public void should_remove_global_user_permission() { httpServer.stubStatusCode(200); PermissionParameters params = PermissionParameters.create().user("daveloper").permission("admin"); @@ -87,7 +117,22 @@ public class DefaultPermissionClientTest { } @Test - public void should_remove_group_permission() { + public void should_remove_component_user_permission() { + httpServer.stubStatusCode(200); + + PermissionParameters params = PermissionParameters.create().user("daveloper").component("org.sample.Sample").permission("admin"); + client.removePermission(params); + + assertThat(httpServer.requestedPath()).isEqualTo("/api/permissions/remove"); + assertThat(httpServer.requestParams()).includes( + entry("user", "daveloper"), + entry("component", "org.sample.Sample"), + entry("permission", "admin") + ); + } + + @Test + public void should_remove_global_group_permission() { httpServer.stubStatusCode(200); PermissionParameters params = PermissionParameters.create().group("my_group").permission("admin"); @@ -99,4 +144,19 @@ public class DefaultPermissionClientTest { entry("permission", "admin") ); } + + @Test + public void should_remove_component_group_permission() { + httpServer.stubStatusCode(200); + + PermissionParameters params = PermissionParameters.create().group("my_group").component("org.sample.Sample").permission("admin"); + client.removePermission(params); + + assertThat(httpServer.requestedPath()).isEqualTo("/api/permissions/remove"); + assertThat(httpServer.requestParams()).includes( + entry("group", "my_group"), + entry("component", "org.sample.Sample"), + entry("permission", "admin") + ); + } } |