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 | |
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')
13 files changed, 434 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/base/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/base/package-info.java new file mode 100644 index 00000000000..a577a12003f --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/base/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.wsclient.base;
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/component/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/component/package-info.java new file mode 100644 index 00000000000..20aea5e6db8 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/component/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.wsclient.component;
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/package-info.java new file mode 100644 index 00000000000..c549291bacf --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.wsclient.connectors;
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/package-info.java new file mode 100644 index 00000000000..f0f8becc0fe --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.wsclient;
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/DefaultPermissionClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/DefaultPermissionClient.java new file mode 100644 index 00000000000..9bb4a6fcaa2 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/DefaultPermissionClient.java @@ -0,0 +1,49 @@ +/* + * 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.sonar.wsclient.internal.HttpRequestFactory; + +public class DefaultPermissionClient implements PermissionClient { + + private static final String BASE_URL = "/api/permissions/"; + private static final String ADD_URL = BASE_URL + "add"; + private static final String REMOVE_URL = BASE_URL + "remove"; + + private final HttpRequestFactory requestFactory; + + /** + * For internal use. Use {@link org.sonar.wsclient.SonarClient} to get an instance. + */ + public DefaultPermissionClient(HttpRequestFactory requestFactory) { + this.requestFactory = requestFactory; + } + + @Override + public void addPermission(PermissionParameters permissionParameters) { + requestFactory.post(ADD_URL, permissionParameters.urlParams()); + } + + @Override + public void removePermission(PermissionParameters permissionParameters) { + requestFactory.post(REMOVE_URL, permissionParameters.urlParams()); + } +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/PermissionClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/PermissionClient.java new file mode 100644 index 00000000000..939217f2d71 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/PermissionClient.java @@ -0,0 +1,38 @@ +/* + * 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; + + +/** + * @since 3.7 + */ +public interface PermissionClient { + + /** + * @since 3.7 + */ + void addPermission(PermissionParameters permissionParameters); + + /** + * @since 3.7 + */ + void removePermission(PermissionParameters permissionParameters); +} 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 new file mode 100644 index 00000000000..1cdd4dc4240 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/PermissionParameters.java @@ -0,0 +1,56 @@ +/* + * 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 java.util.HashMap; +import java.util.Map; + +public class PermissionParameters { + + private final Map<String, Object> params; + + private PermissionParameters(){ + params = new HashMap<String, Object>(); + } + + public static PermissionParameters create() { + return new PermissionParameters(); + } + + public PermissionParameters user(String user) { + params.put("user", user); + return this; + } + + public PermissionParameters group(String group) { + params.put("group", group); + return this; + } + + public PermissionParameters permission(String permission) { + params.put("permission", permission); + return this; + } + + public Map<String, Object> urlParams() { + return params; + } +} diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/package-info.java new file mode 100644 index 00000000000..816576f5b4f --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/permissions/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.wsclient.permissions;
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/package-info.java new file mode 100644 index 00000000000..162f2fc4ede --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.wsclient.rule;
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/package-info.java new file mode 100644 index 00000000000..2bf10c60fb3 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.wsclient.services;
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/package-info.java new file mode 100644 index 00000000000..7bd201ee550 --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.wsclient.unmarshallers;
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/user/package-info.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/user/package-info.java new file mode 100644 index 00000000000..d4506c5f9ff --- /dev/null +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/user/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.wsclient.user;
\ No newline at end of file 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); + } +} |