From e1588798acce44a0fcb4e99a1104d62b0ae8d271 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 23 Nov 2017 22:53:45 +0100 Subject: [PATCH] Generate client for api/user_groups --- .../org/sonarqube/qa/util/GroupTester.java | 15 +- .../org/sonarqube/qa/util/UserTester.java | 14 +- .../sonarqube/ws/client/DefaultWsClient.java | 2 +- .../org/sonarqube/ws/client/WsClient.java | 2 +- .../ws/client/usergroup/AddUserWsRequest.java | 99 ------------ .../ws/client/usergroup/CreateWsRequest.java | 88 ----------- .../ws/client/usergroup/DeleteWsRequest.java | 86 ----------- .../client/usergroup/RemoveUserWsRequest.java | 99 ------------ .../ws/client/usergroup/SearchWsRequest.java | 108 ------------- .../ws/client/usergroup/UpdateWsRequest.java | 85 ----------- .../client/usergroup/UserGroupsService.java | 90 ----------- .../ws/client/usergroup/package-info.java | 26 ---- .../usergroup/UserGroupsServiceTest.java | 143 ------------------ tests/src/test/java/util/user/UserRule.java | 3 +- 14 files changed, 17 insertions(+), 843 deletions(-) delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/AddUserWsRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/CreateWsRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/DeleteWsRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/RemoveUserWsRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/SearchWsRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/UpdateWsRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/UserGroupsService.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/package-info.java delete mode 100644 sonar-ws/src/test/java/org/sonarqube/ws/client/usergroup/UserGroupsServiceTest.java diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/GroupTester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/GroupTester.java index 7a3bd5e8fca..29dfee6b234 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/GroupTester.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/GroupTester.java @@ -30,8 +30,8 @@ import org.sonarqube.ws.UserGroups; import org.sonarqube.ws.Users; import org.sonarqube.ws.Users.GroupsWsResponse.Group; import org.sonarqube.ws.client.user.GroupsRequest; -import org.sonarqube.ws.client.usergroup.AddUserWsRequest; -import org.sonarqube.ws.client.usergroup.CreateWsRequest; +import org.sonarqube.ws.client.usergroups.AddUserRequest; +import org.sonarqube.ws.client.usergroups.CreateRequest; import static java.util.Arrays.stream; import static org.assertj.core.api.Assertions.assertThat; @@ -47,14 +47,14 @@ public class GroupTester { } @SafeVarargs - public final UserGroups.Group generate(@Nullable Organizations.Organization organization, Consumer... populators) { + public final UserGroups.Group generate(@Nullable Organizations.Organization organization, Consumer... populators) { int id = ID_GENERATOR.getAndIncrement(); - CreateWsRequest.Builder request = CreateWsRequest.builder() + CreateRequest request = new CreateRequest() .setName("Group" + id) .setDescription("Description " + id) .setOrganization(organization != null ? organization.getKey() : null); stream(populators).forEach(p -> p.accept(request)); - return session.wsClient().userGroups().create(request.build()).getGroup(); + return session.wsClient().userGroups().create(request).getGroup(); } public List getGroupsOfUser(@Nullable Organizations.Organization organization, String userLogin) { @@ -68,11 +68,10 @@ public class GroupTester { public GroupTester addMemberToGroups(Organizations.Organization organization, String userLogin, String... groups) { for (String group : groups) { - AddUserWsRequest request = AddUserWsRequest.builder() + AddUserRequest request = new AddUserRequest() .setLogin(userLogin) .setOrganization(organization.getKey()) - .setName(group) - .build(); + .setName(group); session.wsClient().userGroups().addUser(request); } return this; diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/UserTester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/UserTester.java index 8b38ca267a2..d5546e5761a 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/UserTester.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/UserTester.java @@ -30,7 +30,7 @@ import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.user.CreateRequest; import org.sonarqube.ws.client.user.SearchRequest; import org.sonarqube.ws.client.user.UsersService; -import org.sonarqube.ws.client.usergroup.AddUserWsRequest; +import org.sonarqube.ws.client.usergroups.AddUserRequest; import static java.util.Arrays.stream; @@ -75,7 +75,7 @@ public class UserTester { public final User generateAdministrator(Consumer... populators) { User user = generate(populators); session.wsClient().permissions().addUser(new org.sonarqube.ws.client.permission.AddUserWsRequest().setLogin(user.getLogin()).setPermission("admin")); - session.wsClient().userGroups().addUser(AddUserWsRequest.builder().setLogin(user.getLogin()).setName("sonar-administrators").build()); + session.wsClient().userGroups().addUser(new AddUserRequest().setLogin(user.getLogin()).setName("sonar-administrators")); return user; } @@ -84,11 +84,10 @@ public class UserTester { String organizationKey = organization.getKey(); User user = generate(populators); session.wsClient().organizations().addMember(organizationKey, user.getLogin()); - session.wsClient().userGroups().addUser(AddUserWsRequest.builder() + session.wsClient().userGroups().addUser(new AddUserRequest() .setOrganization(organizationKey) .setLogin(user.getLogin()) - .setName("Owners") - .build()); + .setName("Owners")); return user; } @@ -96,11 +95,10 @@ public class UserTester { public final User generateAdministratorOnDefaultOrganization(Consumer... populators) { User user = generate(populators); session.wsClient().organizations().addMember(DEFAULT_ORGANIZATION_KEY, user.getLogin()); - session.wsClient().userGroups().addUser(AddUserWsRequest.builder() + session.wsClient().userGroups().addUser(new AddUserRequest() .setOrganization(DEFAULT_ORGANIZATION_KEY) .setLogin(user.getLogin()) - .setName("sonar-administrators") - .build()); + .setName("sonar-administrators")); return user; } 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 7c1445edcb2..7ae83705d7a 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 @@ -38,7 +38,7 @@ import org.sonarqube.ws.client.rules.RulesService; import org.sonarqube.ws.client.settings.SettingsService; import org.sonarqube.ws.client.system.SystemService; import org.sonarqube.ws.client.user.UsersService; -import org.sonarqube.ws.client.usergroup.UserGroupsService; +import org.sonarqube.ws.client.usergroups.UserGroupsService; import org.sonarqube.ws.client.usertokens.UserTokensService; import org.sonarqube.ws.client.webhooks.WebhooksService; 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 2854977c5df..96c20272caf 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 @@ -38,7 +38,7 @@ import org.sonarqube.ws.client.rules.RulesService; import org.sonarqube.ws.client.settings.SettingsService; import org.sonarqube.ws.client.system.SystemService; import org.sonarqube.ws.client.user.UsersService; -import org.sonarqube.ws.client.usergroup.UserGroupsService; +import org.sonarqube.ws.client.usergroups.UserGroupsService; import org.sonarqube.ws.client.usertokens.UserTokensService; import org.sonarqube.ws.client.webhooks.WebhooksService; diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/AddUserWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/AddUserWsRequest.java deleted file mode 100644 index b48108ca3f1..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/AddUserWsRequest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.usergroup; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -@Immutable -public class AddUserWsRequest { - - private final Long id; - private final String name; - private final String login; - private final String organization; - - private AddUserWsRequest(Builder builder) { - this.id = builder.id; - this.name = builder.name; - this.login = builder.login; - this.organization = builder.organization; - } - - @CheckForNull - public Long getId() { - return id; - } - - @CheckForNull - public String getName() { - return name; - } - - @CheckForNull - public String getLogin() { - return login; - } - - @CheckForNull - public String getOrganization() { - return organization; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Long id; - private String name; - private String login; - private String organization; - - private Builder() { - // enforce factory method use - } - - public Builder setId(@Nullable Long id) { - this.id = id; - return this; - } - - public Builder setName(@Nullable String name) { - this.name = name; - return this; - } - - public Builder setLogin(@Nullable String login) { - this.login = login; - return this; - } - - public Builder setOrganization(@Nullable String organization) { - this.organization = organization; - return this; - } - - public AddUserWsRequest build() { - return new AddUserWsRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/CreateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/CreateWsRequest.java deleted file mode 100644 index 3d146a4ed3b..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/CreateWsRequest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.usergroup; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Strings.isNullOrEmpty; - -@Immutable -public class CreateWsRequest { - - private final String name; - private final String description; - private final String organization; - - private CreateWsRequest(Builder builder) { - this.name = builder.name; - this.description = builder.description; - this.organization = builder.organization; - } - - public String getName() { - return name; - } - - @CheckForNull - public String getDescription() { - return description; - } - - public String getOrganization() { - return organization; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String name; - private String description; - private String organization; - - private Builder() { - // enforce factory method use - } - - public Builder setName(String name) { - this.name = name; - return this; - } - - public Builder setDescription(@Nullable String description) { - this.description = description; - return this; - } - - public Builder setOrganization(String organization) { - this.organization = organization; - return this; - } - - public CreateWsRequest build() { - checkArgument(!isNullOrEmpty(name), "Name is mandatory and must not be empty"); - return new CreateWsRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/DeleteWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/DeleteWsRequest.java deleted file mode 100644 index 31786ffe58e..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/DeleteWsRequest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.usergroup; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -@Immutable -public class DeleteWsRequest { - - private final Long id; - private final String name; - private final String organization; - - private DeleteWsRequest(Builder builder) { - this.id = builder.id; - this.name = builder.name; - this.organization = builder.organization; - } - - @CheckForNull - public Long getId() { - return id; - } - - @CheckForNull - public String getName() { - return name; - } - - @CheckForNull - public String getOrganization() { - return organization; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Long id; - private String name; - private String organization; - - private Builder() { - // enforce factory method use - } - - public Builder setId(@Nullable Long id) { - this.id = id; - return this; - } - - public Builder setName(@Nullable String name) { - this.name = name; - return this; - } - - public Builder setOrganization(@Nullable String organization) { - this.organization = organization; - return this; - } - - public DeleteWsRequest build() { - return new DeleteWsRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/RemoveUserWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/RemoveUserWsRequest.java deleted file mode 100644 index 0b498ec2b8f..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/RemoveUserWsRequest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.usergroup; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -@Immutable -public class RemoveUserWsRequest { - - private final Long id; - private final String name; - private final String login; - private final String organization; - - private RemoveUserWsRequest(Builder builder) { - this.id = builder.id; - this.name = builder.name; - this.login = builder.login; - this.organization = builder.organization; - } - - @CheckForNull - public Long getId() { - return id; - } - - @CheckForNull - public String getName() { - return name; - } - - @CheckForNull - public String getLogin() { - return login; - } - - @CheckForNull - public String getOrganization() { - return organization; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Long id; - private String name; - private String login; - private String organization; - - private Builder() { - // enforce factory method use - } - - public Builder setId(@Nullable Long id) { - this.id = id; - return this; - } - - public Builder setName(@Nullable String name) { - this.name = name; - return this; - } - - public Builder setLogin(@Nullable String login) { - this.login = login; - return this; - } - - public Builder setOrganization(@Nullable String organization) { - this.organization = organization; - return this; - } - - public RemoveUserWsRequest build() { - return new RemoveUserWsRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/SearchWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/SearchWsRequest.java deleted file mode 100644 index 4a0bcb9ba27..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/SearchWsRequest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.usergroup; - -import java.util.List; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -@Immutable -public class SearchWsRequest { - private final String query; - private final Integer page; - private final Integer pageSize; - private final String organization; - private final List fields; - - private SearchWsRequest(Builder builder) { - this.query = builder.query; - this.page = builder.page; - this.pageSize = builder.pageSize; - this.organization = builder.organization; - this.fields = builder.fields; - } - - @CheckForNull - public String getQuery() { - return query; - } - - @CheckForNull - public Integer getPageSize() { - return pageSize; - } - - @CheckForNull - public Integer getPage() { - return page; - } - - @CheckForNull - public String getOrganization() { - return organization; - } - - @CheckForNull - public List getFields() { - return fields; - } - - public static Builder builder() { - return new Builder(); - } - - public static final class Builder { - private String query; - private Integer page; - private Integer pageSize; - private String organization; - private List fields; - - public Builder setQuery(@Nullable String query) { - this.query = query; - return this; - } - - public Builder setPage(@Nullable Integer page) { - this.page = page; - return this; - } - - public Builder setPageSize(@Nullable Integer pageSize) { - this.pageSize = pageSize; - return this; - } - - public Builder setOrganization(@Nullable String organization) { - this.organization = organization; - return this; - } - - public Builder setFields(@Nullable List fields) { - this.fields = fields; - return this; - } - - public SearchWsRequest build() { - return new SearchWsRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/UpdateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/UpdateWsRequest.java deleted file mode 100644 index a670e3619b0..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/UpdateWsRequest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.usergroup; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -@Immutable -public class UpdateWsRequest { - - private final long id; - private final String name; - private final String description; - - private UpdateWsRequest(Builder builder) { - this.id = builder.id; - this.name = builder.name; - this.description = builder.description; - } - - public long getId() { - return id; - } - - @CheckForNull - public String getName() { - return name; - } - - @CheckForNull - public String getDescription() { - return description; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private long id; - private String name; - private String description; - - private Builder() { - // enforce factory method use - } - - public Builder setId(long id) { - this.id = id; - return this; - } - - public Builder setName(@Nullable String name) { - this.name = name; - return this; - } - - public Builder setDescription(@Nullable String description) { - this.description = description; - return this; - } - - public UpdateWsRequest build() { - return new UpdateWsRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/UserGroupsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/UserGroupsService.java deleted file mode 100644 index 9cd0a388db7..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/UserGroupsService.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.usergroup; - -import org.sonarqube.ws.client.BaseService; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.PostRequest; -import org.sonarqube.ws.client.WsConnector; - -import static org.sonar.api.server.ws.WebService.Param.FIELDS; -import static org.sonar.api.server.ws.WebService.Param.PAGE; -import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; -import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; -import static org.sonarqube.ws.UserGroups.CreateWsResponse; -import static org.sonarqube.ws.UserGroups.SearchWsResponse; -import static org.sonarqube.ws.UserGroups.UpdateWsResponse; - -public class UserGroupsService extends BaseService { - - public UserGroupsService(WsConnector wsConnector) { - super(wsConnector, "api/user_groups"); - } - - public CreateWsResponse create(CreateWsRequest request) { - return call(new PostRequest(path("create")) - .setParam("name", request.getName()) - .setParam("description", request.getDescription()) - .setParam("organization", request.getOrganization()), - CreateWsResponse.parser()); - } - - public UpdateWsResponse update(UpdateWsRequest request) { - return call(new PostRequest(path("update")) - .setParam("id", request.getId()) - .setParam("name", request.getName()) - .setParam("description", request.getDescription()), - UpdateWsResponse.parser()); - } - - public void delete(DeleteWsRequest request) { - call(new PostRequest(path("delete")) - .setParam("id", request.getId()) - .setParam("name", request.getName()) - .setParam("organization", request.getOrganization())); - } - - public void addUser(AddUserWsRequest request) { - call(new PostRequest(path("add_user")) - .setParam("id", request.getId()) - .setParam("name", request.getName()) - .setParam("login", request.getLogin()) - .setParam("organization", request.getOrganization())); - } - - public void removeUser(RemoveUserWsRequest request) { - call(new PostRequest(path("remove_user")) - .setParam("id", request.getId()) - .setParam("name", request.getName()) - .setParam("login", request.getLogin()) - .setParam("organization", request.getOrganization())); - } - - public SearchWsResponse search(SearchWsRequest request) { - return call(new GetRequest(path("search")) - .setParam(TEXT_QUERY, request.getQuery()) - .setParam(PAGE, request.getPage()) - .setParam(PAGE_SIZE, request.getPageSize()) - .setParam("organization", request.getOrganization()) - .setParam(FIELDS, inlineMultipleParamValue(request.getFields())), - SearchWsResponse.parser()); - } - -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/package-info.java deleted file mode 100644 index e3d282fc844..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/usergroup/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.usergroup; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/usergroup/UserGroupsServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/usergroup/UserGroupsServiceTest.java deleted file mode 100644 index d4bac214257..00000000000 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/usergroup/UserGroupsServiceTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.usergroup; - -import org.junit.Rule; -import org.junit.Test; -import org.sonarqube.ws.client.ServiceTester; -import org.sonarqube.ws.client.WsConnector; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.sonarqube.ws.UserGroups.CreateWsResponse; -import static org.sonarqube.ws.UserGroups.SearchWsResponse; -import static org.sonarqube.ws.UserGroups.UpdateWsResponse; - -public class UserGroupsServiceTest { - - @Rule - public ServiceTester serviceTester = new ServiceTester<>(new UserGroupsService(mock(WsConnector.class))); - - private UserGroupsService underTest = serviceTester.getInstanceUnderTest(); - - @Test - public void create() { - underTest.create(CreateWsRequest.builder() - .setName("sonar-users") - .setDescription("All users") - .setOrganization("org") - .build()); - - assertThat(serviceTester.getPostParser()).isSameAs(CreateWsResponse.parser()); - serviceTester.assertThat(serviceTester.getPostRequest()) - .hasParam("name", "sonar-users") - .hasParam("description", "All users") - .hasParam("organization", "org") - .andNoOtherParam(); - } - - @Test - public void update() { - underTest.update(UpdateWsRequest.builder() - .setId(10L) - .setName("sonar-users") - .setDescription("All users") - .build()); - - assertThat(serviceTester.getPostParser()).isSameAs(UpdateWsResponse.parser()); - serviceTester.assertThat(serviceTester.getPostRequest()) - .hasParam("id", "10") - .hasParam("name", "sonar-users") - .hasParam("description", "All users") - .andNoOtherParam(); - } - - @Test - public void delete() { - underTest.delete(DeleteWsRequest.builder() - .setId(10L) - .setName("sonar-users") - .setOrganization("orga") - .build()); - - serviceTester.assertThat(serviceTester.getPostRequest()) - .hasParam("id", "10") - .hasParam("name", "sonar-users") - .hasParam("organization", "orga") - .andNoOtherParam(); - } - - @Test - public void addUser() throws Exception { - underTest.addUser(AddUserWsRequest.builder() - .setId(10L) - .setName("sonar-users") - .setLogin("john") - .setOrganization("org") - .build()); - - serviceTester.assertThat(serviceTester.getPostRequest()) - .hasParam("id", "10") - .hasParam("name", "sonar-users") - .hasParam("login", "john") - .hasParam("organization", "org") - .andNoOtherParam(); - } - - @Test - public void removeUser() throws Exception { - underTest.removeUser(RemoveUserWsRequest.builder() - .setId(10L) - .setName("sonar-users") - .setLogin("john") - .setOrganization("org") - .build()); - - serviceTester.assertThat(serviceTester.getPostRequest()) - .hasParam("id", "10") - .hasParam("name", "sonar-users") - .hasParam("login", "john") - .hasParam("organization", "org") - .andNoOtherParam(); - } - - @Test - public void search() { - underTest.search(SearchWsRequest.builder() - .setQuery("sonar-users") - .setPage(10) - .setPageSize(50) - .setOrganization("orga") - .setFields(asList("name", "description")) - .build()); - - assertThat(serviceTester.getGetParser()).isSameAs(SearchWsResponse.parser()); - serviceTester.assertThat(serviceTester.getGetRequest()) - .hasParam("q", "sonar-users") - .hasParam("p", 10) - .hasParam("ps", 50) - .hasParam("organization", "orga") - .hasParam("f", "name,description") - .andNoOtherParam(); - } - -} diff --git a/tests/src/test/java/util/user/UserRule.java b/tests/src/test/java/util/user/UserRule.java index 65863a9629d..9e8cc191020 100644 --- a/tests/src/test/java/util/user/UserRule.java +++ b/tests/src/test/java/util/user/UserRule.java @@ -40,6 +40,7 @@ import org.sonarqube.ws.client.roots.SetRootRequest; import org.sonarqube.ws.client.user.CreateRequest; import org.sonarqube.ws.client.user.SearchRequest; import org.sonarqube.ws.client.user.UsersService; +import org.sonarqube.ws.client.usergroups.AddUserRequest; import util.selenium.Consumer; import static java.util.Arrays.asList; @@ -148,7 +149,7 @@ public class UserRule extends ExternalResource implements GroupManagement { public String createAdminUser(String login, String password) { createUser(login, password); adminWsClient.permissions().addUser(new AddUserWsRequest().setLogin(login).setPermission("admin")); - adminWsClient.userGroups().addUser(org.sonarqube.ws.client.usergroup.AddUserWsRequest.builder().setLogin(login).setName("sonar-administrators").build()); + adminWsClient.userGroups().addUser(new AddUserRequest().setLogin(login).setName("sonar-administrators")); return login; } -- 2.39.5