From cbd194df13134b0548d6ab476a78f0953c44da3d Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Mon, 4 Dec 2017 18:34:00 +0100 Subject: [PATCH] Remove legacy sonar-ws code for users --- .../org/sonarqube/qa/util/GroupTester.java | 7 +- .../sonarqube/qa/util/OrganizationTester.java | 9 +- .../org/sonarqube/qa/util/UserTester.java | 26 ++-- .../ws/client/user/CreateRequest.java | 130 ----------------- .../ws/client/user/GroupsRequest.java | 128 ---------------- .../ws/client/user/SearchRequest.java | 100 ------------- .../ws/client/user/UpdateRequest.java | 101 ------------- .../ws/client/user/UsersService.java | 113 -------------- .../ws/client/users/CreateRequest.java | 12 +- .../ws/client/users/UsersService.java | 6 +- .../ws/client/user/CreateRequestTest.java | 130 ----------------- .../ws/client/user/GroupsRequestTest.java | 85 ----------- .../ws/client/user/UpdateRequestTest.java | 71 --------- .../ws/client/user/UsersServiceTest.java | 138 ------------------ .../sonarqube/tests/issue/AutoAssignTest.java | 13 +- .../OrganizationMembershipTest.java | 3 +- .../tests/startup/StartupIndexationTest.java | 4 +- .../tests/user/BaseIdentityProviderTest.java | 7 +- .../tests/user/LocalAuthenticationTest.java | 10 +- .../user/OAuth2IdentityProviderTest.java | 7 +- .../sonarqube/tests/user/OnboardingTest.java | 3 +- .../tests/user/RealmAuthenticationTest.java | 7 +- .../tests/user/UserEsResilienceTest.java | 12 +- .../sonarqube/tests/user/UsersPageTest.java | 15 +- tests/src/test/java/util/user/UserRule.java | 18 +-- 25 files changed, 77 insertions(+), 1078 deletions(-) delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/user/CreateRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/user/GroupsRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/user/SearchRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/user/UpdateRequest.java delete mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java delete mode 100644 sonar-ws/src/test/java/org/sonarqube/ws/client/user/CreateRequestTest.java delete mode 100644 sonar-ws/src/test/java/org/sonarqube/ws/client/user/GroupsRequestTest.java delete mode 100644 sonar-ws/src/test/java/org/sonarqube/ws/client/user/UpdateRequestTest.java delete mode 100644 sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.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 29dfee6b234..3a901674e8a 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 @@ -29,9 +29,9 @@ import org.sonarqube.ws.Organizations; 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.usergroups.AddUserRequest; import org.sonarqube.ws.client.usergroups.CreateRequest; +import org.sonarqube.ws.client.users.GroupsRequest; import static java.util.Arrays.stream; import static org.assertj.core.api.Assertions.assertThat; @@ -58,10 +58,9 @@ public class GroupTester { } public List getGroupsOfUser(@Nullable Organizations.Organization organization, String userLogin) { - GroupsRequest request = GroupsRequest.builder() + GroupsRequest request = new GroupsRequest() .setOrganization(organization != null ? organization.getKey() : null) - .setLogin(userLogin) - .build(); + .setLogin(userLogin); Users.GroupsWsResponse response = session.users().service().groups(request); return response.getGroupsList(); } diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/OrganizationTester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/OrganizationTester.java index e6bdc24940b..acbcb940f3d 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/OrganizationTester.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/OrganizationTester.java @@ -35,7 +35,7 @@ import org.sonarqube.ws.client.organizations.DeleteRequest; import org.sonarqube.ws.client.organizations.OrganizationsService; import org.sonarqube.ws.client.organizations.SearchMembersRequest; import org.sonarqube.ws.client.organizations.SearchRequest; -import org.sonarqube.ws.client.user.GroupsRequest; +import org.sonarqube.ws.client.users.GroupsRequest; import static java.util.Arrays.stream; @@ -128,12 +128,11 @@ public class OrganizationTester { } private void verifyMembersGroupMembership(String userLogin, @Nullable Organizations.Organization organization, boolean isMember) { - List groups = session.wsClient().users().groups(GroupsRequest.builder() + List groups = session.wsClient().users().groups(new GroupsRequest() .setLogin(userLogin) .setOrganization(organization != null ? organization.getKey() : null) - .setQuery("Members") - .setSelected("selected") - .build()) + .setQ("Members") + .setSelected("selected")) .getGroupsList(); Assertions.assertThat(groups).hasSize(isMember ? 1 : 0); } 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 fca8bf4f1b8..c5309c3578e 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 @@ -28,10 +28,10 @@ import org.sonarqube.ws.Users; import org.sonarqube.ws.Users.CreateWsResponse.User; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.organizations.AddMemberRequest; -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 org.sonarqube.ws.client.users.CreateRequest; +import org.sonarqube.ws.client.users.SearchRequest; +import org.sonarqube.ws.client.users.UsersService; import static java.util.Arrays.stream; @@ -47,7 +47,7 @@ public class UserTester { } void deleteAll() { - session.wsClient().users().search(SearchRequest.builder().build()).getUsersList() + session.wsClient().users().search(new SearchRequest()).getUsersList() .stream() .filter(u -> !"admin".equals(u.getLogin())) .forEach(u -> { @@ -57,23 +57,23 @@ public class UserTester { } @SafeVarargs - public final User generate(Consumer... populators) { + public final User generate(Consumer... populators) { int id = ID_GENERATOR.getAndIncrement(); String login = "login" + id; - CreateRequest.Builder request = CreateRequest.builder() + CreateRequest request = new CreateRequest() .setLogin(login) .setPassword(login) .setName("name" + id) .setEmail(id + "@test.com"); stream(populators).forEach(p -> p.accept(request)); - return service().create(request.build()).getUser(); + return service().create(request).getUser(); } /** * For standalone mode only */ @SafeVarargs - public final User generateAdministrator(Consumer... populators) { + public final User generateAdministrator(Consumer... populators) { User user = generate(populators); session.wsClient().permissions().addUser(new org.sonarqube.ws.client.permissions.AddUserRequest().setLogin(user.getLogin()).setPermission("admin")); session.wsClient().userGroups().addUser(new AddUserRequest().setLogin(user.getLogin()).setName("sonar-administrators")); @@ -81,7 +81,7 @@ public class UserTester { } @SafeVarargs - public final User generateAdministrator(Organizations.Organization organization, Consumer... populators) { + public final User generateAdministrator(Organizations.Organization organization, Consumer... populators) { String organizationKey = organization.getKey(); User user = generate(populators); session.wsClient().organizations().addMember(new AddMemberRequest().setOrganization(organizationKey).setLogin(user.getLogin())); @@ -93,7 +93,7 @@ public class UserTester { } @SafeVarargs - public final User generateAdministratorOnDefaultOrganization(Consumer... populators) { + public final User generateAdministratorOnDefaultOrganization(Consumer... populators) { User user = generate(populators); session.wsClient().organizations().addMember(new AddMemberRequest().setOrganization(DEFAULT_ORGANIZATION_KEY).setLogin(user.getLogin())); session.wsClient().userGroups().addUser(new AddUserRequest() @@ -104,14 +104,14 @@ public class UserTester { } @SafeVarargs - public final User generateMember(Organizations.Organization organization, Consumer... populators) { + public final User generateMember(Organizations.Organization organization, Consumer... populators) { User user = generate(populators); session.wsClient().organizations().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(user.getLogin())); return user; } @SafeVarargs - public final User generateMemberOfDefaultOrganization(Consumer... populators) { + public final User generateMemberOfDefaultOrganization(Consumer... populators) { User user = generate(populators); session.wsClient().organizations().addMember(new AddMemberRequest().setOrganization(DEFAULT_ORGANIZATION_KEY).setLogin(user.getLogin())); return user; @@ -122,7 +122,7 @@ public class UserTester { } public Optional getByLogin(String login) { - List users = session.wsClient().users().search(SearchRequest.builder().setQuery(login).build()).getUsersList(); + List users = session.wsClient().users().search(new SearchRequest().setQ(login)).getUsersList(); if (users.size() == 1) { return Optional.of(users.get(0)); } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/CreateRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/CreateRequest.java deleted file mode 100644 index c2a71a4539a..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/CreateRequest.java +++ /dev/null @@ -1,130 +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.user; - -import java.util.List; -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; -import static java.util.Collections.emptyList; - -@Immutable -public class CreateRequest { - - private final String login; - private final String password; - private final String name; - private final String email; - private final List scmAccounts; - private final boolean local; - - private CreateRequest(Builder builder) { - this.login = builder.login; - this.password = builder.password; - this.name = builder.name; - this.email = builder.email; - this.scmAccounts = builder.scmAccounts; - this.local = builder.local; - } - - public String getLogin() { - return login; - } - - @CheckForNull - public String getPassword() { - return password; - } - - public String getName() { - return name; - } - - @CheckForNull - public String getEmail() { - return email; - } - - public List getScmAccounts() { - return scmAccounts; - } - - public boolean isLocal() { - return local; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String login; - private String password; - private String name; - private String email; - private List scmAccounts = emptyList(); - private boolean local = true; - - private Builder() { - // enforce factory method use - } - - public Builder setLogin(String login) { - this.login = login; - return this; - } - - public Builder setPassword(@Nullable String password) { - this.password = password; - return this; - } - - public Builder setName(String name) { - this.name = name; - return this; - } - - public Builder setEmail(@Nullable String email) { - this.email = email; - return this; - } - - public Builder setScmAccounts(List scmAccounts) { - this.scmAccounts = scmAccounts; - return this; - } - - public Builder setLocal(boolean local) { - this.local = local; - return this; - } - - public CreateRequest build() { - checkArgument(!isNullOrEmpty(login), "Login is mandatory and must not be empty"); - checkArgument(!isNullOrEmpty(name), "Name is mandatory and must not be empty"); - checkArgument(!local || !isNullOrEmpty(password), "Password is mandatory and must not be empty"); - checkArgument(local || isNullOrEmpty(password), "Password should only be set on local user"); - return new CreateRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/GroupsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/GroupsRequest.java deleted file mode 100644 index 161a388e385..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/GroupsRequest.java +++ /dev/null @@ -1,128 +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.user; - -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 GroupsRequest { - - private final String login; - private final String organization; - private final String query; - private final String selected; - private final Integer page; - private final Integer pageSize; - - private GroupsRequest(Builder builder) { - this.login = builder.login; - this.organization = builder.organization; - this.query = builder.query; - this.selected = builder.selected; - this.page = builder.page; - this.pageSize = builder.pageSize; - } - - public String getLogin() { - return login; - } - - @CheckForNull - public String getOrganization() { - return organization; - } - - @CheckForNull - public String getQuery() { - return query; - } - - @CheckForNull - public String getSelected() { - return selected; - } - - @CheckForNull - public Integer getPage() { - return page; - } - - @CheckForNull - public Integer getPageSize() { - return pageSize; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String login; - private String organization; - private String query; - private String selected; - private Integer page; - private Integer pageSize; - - private Builder() { - // enforce factory method use - } - - public Builder setLogin(String login) { - this.login = login; - return this; - } - - public Builder setOrganization(@Nullable String organization) { - this.organization = organization; - return this; - } - - public Builder setQuery(@Nullable String query) { - this.query = query; - return this; - } - - public Builder setSelected(@Nullable String selected) { - this.selected = selected; - 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 GroupsRequest build() { - checkArgument(!isNullOrEmpty(login), "Login is mandatory and must not be empty"); - return new GroupsRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/SearchRequest.java deleted file mode 100644 index 52e19f34607..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/SearchRequest.java +++ /dev/null @@ -1,100 +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.user; - -import java.util.ArrayList; -import java.util.List; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; - -@Immutable -public class SearchRequest { - - private final Integer page; - private final Integer pageSize; - private final String query; - private final List possibleFields; - - private SearchRequest(Builder builder) { - this.page = builder.page; - this.pageSize = builder.pageSize; - this.query = builder.query; - this.possibleFields = builder.additionalFields; - } - - @CheckForNull - public Integer getPage() { - return page; - } - - @CheckForNull - public Integer getPageSize() { - return pageSize; - } - - @CheckForNull - public String getQuery() { - return query; - } - - public List getPossibleFields() { - return possibleFields; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Integer page; - private Integer pageSize; - private String query; - private List additionalFields = new ArrayList<>(); - - private Builder() { - // enforce factory method use - } - - public Builder setPage(@Nullable Integer page) { - this.page = page; - return this; - } - - public Builder setPageSize(@Nullable Integer pageSize) { - this.pageSize = pageSize; - return this; - } - - public Builder setQuery(@Nullable String query) { - this.query = query; - return this; - } - - public Builder setPossibleFields(List possibleFields) { - this.additionalFields = possibleFields; - return this; - } - - public SearchRequest build() { - return new SearchRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UpdateRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UpdateRequest.java deleted file mode 100644 index 40d5fbd6455..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UpdateRequest.java +++ /dev/null @@ -1,101 +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.user; - -import java.util.List; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Strings.isNullOrEmpty; -import static java.util.Collections.emptyList; - -public class UpdateRequest { - - private final String login; - private final String name; - private final String email; - private final List scmAccounts; - - private UpdateRequest(Builder builder) { - this.login = builder.login; - this.name = builder.name; - this.email = builder.email; - this.scmAccounts = builder.scmAccounts; - } - - public String getLogin() { - return login; - } - - @CheckForNull - public String getName() { - return name; - } - - @CheckForNull - public String getEmail() { - return email; - } - - public List getScmAccounts() { - return scmAccounts; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String login; - private String name; - private String email; - private List scmAccounts = emptyList(); - - private Builder() { - // enforce factory method use - } - - public Builder setLogin(String login) { - this.login = login; - return this; - } - - public Builder setName(@Nullable String name) { - this.name = name; - return this; - } - - public Builder setEmail(@Nullable String email) { - this.email = email; - return this; - } - - public Builder setScmAccounts(List scmAccounts) { - this.scmAccounts = scmAccounts; - return this; - } - - public UpdateRequest build() { - checkArgument(!isNullOrEmpty(login), "Login is mandatory and must not be empty"); - return new UpdateRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java deleted file mode 100644 index 9f2cb3f06a0..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java +++ /dev/null @@ -1,113 +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.user; - -import java.util.List; -import org.sonarqube.ws.Users.CreateWsResponse; -import org.sonarqube.ws.Users.CurrentWsResponse; -import org.sonarqube.ws.Users.GroupsWsResponse; -import org.sonarqube.ws.Users.SearchWsResponse; -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 org.sonarqube.ws.client.WsResponse; - -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.client.user.UsersWsParameters.ACTION_CREATE; -import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_CURRENT; -import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_DEACTIVATE; -import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_GROUPS; -import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_SEARCH; -import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_SKIP_ONBOARDING_TUTORIAL; -import static org.sonarqube.ws.client.user.UsersWsParameters.ACTION_UPDATE; -import static org.sonarqube.ws.client.user.UsersWsParameters.CONTROLLER_USERS; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_EMAIL; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOCAL; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOGIN; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_NAME; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_ORGANIZATION; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_PASSWORD; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNT; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SELECTED; - -public class UsersService extends BaseService { - - public UsersService(WsConnector wsConnector) { - super(wsConnector, CONTROLLER_USERS); - } - - public SearchWsResponse search(SearchRequest request) { - List additionalFields = request.getPossibleFields(); - return call(new GetRequest(path(ACTION_SEARCH)) - .setParam(PAGE, request.getPage()) - .setParam(PAGE_SIZE, request.getPageSize()) - .setParam(TEXT_QUERY, request.getQuery()) - .setParam(FIELDS, !additionalFields.isEmpty() ? inlineMultipleParamValue(additionalFields) : null), - SearchWsResponse.parser()); - } - - public CreateWsResponse create(CreateRequest request) { - return call(new PostRequest(path(ACTION_CREATE)) - .setParam(PARAM_LOGIN, request.getLogin()) - .setParam(PARAM_PASSWORD, request.getPassword()) - .setParam(PARAM_NAME, request.getName()) - .setParam(PARAM_EMAIL, request.getEmail()) - .setParam(PARAM_SCM_ACCOUNT, request.getScmAccounts()) - .setParam(PARAM_LOCAL, request.isLocal()), - CreateWsResponse.parser()); - } - - public void update(UpdateRequest request) { - call(new PostRequest(path(ACTION_UPDATE)) - .setParam(PARAM_LOGIN, request.getLogin()) - .setParam(PARAM_NAME, request.getName()) - .setParam(PARAM_EMAIL, request.getEmail()) - .setParam(PARAM_SCM_ACCOUNT, request.getScmAccounts())); - } - - public GroupsWsResponse groups(GroupsRequest request) { - return call(new GetRequest(path(ACTION_GROUPS)) - .setParam(PARAM_LOGIN, request.getLogin()) - .setParam(PARAM_ORGANIZATION, request.getOrganization()) - .setParam(PARAM_SELECTED, request.getSelected()) - .setParam(TEXT_QUERY, request.getQuery()) - .setParam(PAGE, request.getPage()) - .setParam(PAGE_SIZE, request.getPageSize()), - GroupsWsResponse.parser()); - } - - public CurrentWsResponse current() { - return call(new GetRequest(path(ACTION_CURRENT)), CurrentWsResponse.parser()); - } - - public WsResponse skipOnboardingTutorial() { - return call(new PostRequest(path(ACTION_SKIP_ONBOARDING_TUTORIAL))); - } - - public void deactivate(String login) { - call(new PostRequest(path(ACTION_DEACTIVATE)) - .setParam(PARAM_LOGIN, login)); - } - -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/users/CreateRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/users/CreateRequest.java index 7852c6846c8..5fc4b9ece4b 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/users/CreateRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/users/CreateRequest.java @@ -36,8 +36,8 @@ public class CreateRequest { private String login; private String name; private String password; - private String scmAccount; - private String scmAccounts; + private List scmAccount; + private List scmAccounts; /** * Example value: "myname@email.com" @@ -110,12 +110,12 @@ public class CreateRequest { /** * Example value: "scmAccount=firstValue&scmAccount=secondValue&scmAccount=thirdValue" */ - public CreateRequest setScmAccount(String scmAccount) { + public CreateRequest setScmAccount(List scmAccount) { this.scmAccount = scmAccount; return this; } - public String getScmAccount() { + public List getScmAccount() { return scmAccount; } @@ -124,12 +124,12 @@ public class CreateRequest { * @deprecated since 6.1 */ @Deprecated - public CreateRequest setScmAccounts(String scmAccounts) { + public CreateRequest setScmAccounts(List scmAccounts) { this.scmAccounts = scmAccounts; return this; } - public String getScmAccounts() { + public List getScmAccounts() { return scmAccounts; } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/users/UsersService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/users/UsersService.java index f456762369b..b1ba17efd69 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/users/UsersService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/users/UsersService.java @@ -66,8 +66,8 @@ public class UsersService extends BaseService { * @see Further information about this action online (including a response example) * @since 3.7 */ - public void create(CreateRequest request) { - call( + public CreateWsResponse create(CreateRequest request) { + return call( new PostRequest(path("create")) .setParam("email", request.getEmail()) .setParam("local", request.getLocal()) @@ -75,7 +75,7 @@ public class UsersService extends BaseService { .setParam("name", request.getName()) .setParam("password", request.getPassword()) .setParam("scmAccount", request.getScmAccount()) - .setParam("scmAccounts", request.getScmAccounts()), + .setParam("scmAccounts", request.getScmAccounts() == null ? null : request.getScmAccounts().stream().collect(Collectors.joining(","))), CreateWsResponse.parser()); } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/CreateRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/user/CreateRequestTest.java deleted file mode 100644 index 91ec63a06bc..00000000000 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/CreateRequestTest.java +++ /dev/null @@ -1,130 +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.user; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; - -public class CreateRequestTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - CreateRequest.Builder underTest = CreateRequest.builder(); - - @Test - public void create_request() { - CreateRequest result = underTest - .setLogin("john") - .setPassword("123456") - .setName("John") - .setEmail("john@doo.com") - .setScmAccounts(asList("jo", "hn")) - .build(); - - assertThat(result.getLogin()).isEqualTo("john"); - assertThat(result.getPassword()).isEqualTo("123456"); - assertThat(result.getName()).isEqualTo("John"); - assertThat(result.getEmail()).isEqualTo("john@doo.com"); - assertThat(result.getScmAccounts()).containsOnly("jo", "hn"); - assertThat(result.isLocal()).isTrue(); - } - - @Test - public void create_request_for_local_user() { - CreateRequest result = underTest - .setLogin("john") - .setPassword("123456") - .setName("John") - .setLocal(true) - .build(); - - assertThat(result.isLocal()).isTrue(); - } - - @Test - public void create_request_for_none_local_user() { - CreateRequest result = underTest - .setLogin("john") - .setName("John") - .setLocal(false) - .build(); - - assertThat(result.isLocal()).isFalse(); - } - - @Test - public void scm_accounts_is_empty_by_default() throws Exception { - CreateRequest result = underTest - .setLogin("john") - .setPassword("123456") - .setName("John") - .setEmail("john@doo.com") - .build(); - - assertThat(result.getScmAccounts()).isEmpty(); - } - - @Test - public void fail_when_empty_login() { - expectedException.expect(IllegalArgumentException.class); - underTest - .setLogin("") - .setPassword("123456") - .setName("John") - .build(); - } - - @Test - public void fail_when_empty_password_on_local_user() { - expectedException.expect(IllegalArgumentException.class); - underTest - .setLogin("john") - .setPassword("") - .setName("John") - .build(); - } - - @Test - public void fail_when_empty_name() { - expectedException.expect(IllegalArgumentException.class); - underTest - .setLogin("john") - .setPassword("12345") - .setName("") - .build(); - } - - @Test - public void fail_when_password_is_set_on_none_local_user() { - expectedException.expect(IllegalArgumentException.class); - underTest - .setLogin("john") - .setPassword("12345") - .setName("12345") - .setLocal(false) - .build(); - } - -} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/GroupsRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/user/GroupsRequestTest.java deleted file mode 100644 index 58270e89608..00000000000 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/GroupsRequestTest.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.user; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GroupsRequestTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - GroupsRequest.Builder underTest = GroupsRequest.builder(); - - @Test - public void create_request() { - GroupsRequest result = underTest - .setLogin("john") - .setOrganization("orga-uuid") - .setSelected("all") - .setQuery("sonar-users") - .setPage(10) - .setPageSize(50) - .build(); - - assertThat(result.getLogin()).isEqualTo("john"); - assertThat(result.getOrganization()).isEqualTo("orga-uuid"); - assertThat(result.getSelected()).isEqualTo("all"); - assertThat(result.getQuery()).isEqualTo("sonar-users"); - assertThat(result.getPage()).isEqualTo(10); - assertThat(result.getPageSize()).isEqualTo(50); - } - - @Test - public void create_request_wih_minimal_fields() { - GroupsRequest result = underTest - .setLogin("john") - .build(); - - assertThat(result.getLogin()).isEqualTo("john"); - assertThat(result.getOrganization()).isNull(); - assertThat(result.getSelected()).isNull(); - assertThat(result.getQuery()).isNull(); - assertThat(result.getPage()).isNull(); - assertThat(result.getPageSize()).isNull(); - } - - @Test - public void fail_when_empty_login() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Login is mandatory and must not be empty"); - - underTest.setLogin("").build(); - } - - @Test - public void fail_when_null_login() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Login is mandatory and must not be empty"); - - underTest.build(); - } - -} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UpdateRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UpdateRequestTest.java deleted file mode 100644 index 3f21906d88a..00000000000 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UpdateRequestTest.java +++ /dev/null @@ -1,71 +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.user; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; - -public class UpdateRequestTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - UpdateRequest.Builder underTest = UpdateRequest.builder(); - - @Test - public void create_request() { - UpdateRequest result = underTest - .setLogin("john") - .setName("John") - .setEmail("john@doo.com") - .setScmAccounts(asList("jo", "hn")) - .build(); - - assertThat(result.getLogin()).isEqualTo("john"); - assertThat(result.getName()).isEqualTo("John"); - assertThat(result.getEmail()).isEqualTo("john@doo.com"); - assertThat(result.getScmAccounts()).containsOnly("jo", "hn"); - } - - @Test - public void scm_accounts_is_empty_by_default() throws Exception { - UpdateRequest result = underTest - .setLogin("john") - .setName("John") - .setEmail("john@doo.com") - .build(); - - assertThat(result.getScmAccounts()).isEmpty(); - } - - @Test - public void fail_when_empty_login() { - expectedException.expect(IllegalArgumentException.class); - underTest - .setLogin("") - .setName("John") - .build(); - } - -} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java deleted file mode 100644 index a0d870b3b90..00000000000 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java +++ /dev/null @@ -1,138 +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.user; - -import org.junit.Rule; -import org.junit.Test; -import org.sonarqube.ws.Users; -import org.sonarqube.ws.Users.CreateWsResponse; -import org.sonarqube.ws.Users.GroupsWsResponse; -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.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.client.user.UsersWsParameters.PARAM_EMAIL; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOCAL; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOGIN; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_NAME; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_ORGANIZATION; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_PASSWORD; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNT; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SELECTED; - -public class UsersServiceTest { - - @Rule - public ServiceTester serviceTester = new ServiceTester<>(new UsersService(mock(WsConnector.class))); - - private UsersService underTest = serviceTester.getInstanceUnderTest(); - - @Test - public void search() { - underTest.search(SearchRequest.builder() - .setQuery("john") - .setPage(10) - .setPageSize(50) - .setPossibleFields(asList("email", "name")) - .build()); - - assertThat(serviceTester.getGetParser()).isSameAs(Users.SearchWsResponse.parser()); - serviceTester.assertThat(serviceTester.getGetRequest()) - .hasParam(TEXT_QUERY, "john") - .hasParam(PAGE, 10) - .hasParam(PAGE_SIZE, 50) - .hasParam(FIELDS, "email,name") - .andNoOtherParam(); - } - - @Test - public void create() { - underTest.create(CreateRequest.builder() - .setLogin("john") - .setPassword("123456") - .setName("John") - .setEmail("john@doo.com") - .setScmAccounts(asList("jo", "hn")) - .setLocal(true) - .build()); - - assertThat(serviceTester.getPostParser()).isSameAs(CreateWsResponse.parser()); - serviceTester.assertThat(serviceTester.getPostRequest()) - .hasParam(PARAM_LOGIN, "john") - .hasParam(PARAM_PASSWORD, "123456") - .hasParam(PARAM_NAME, "John") - .hasParam(PARAM_EMAIL, "john@doo.com") - .hasParam(PARAM_SCM_ACCOUNT, asList("jo", "hn")) - .hasParam(PARAM_LOCAL, "true") - .andNoOtherParam(); - } - - @Test - public void update() { - underTest.update(UpdateRequest.builder() - .setLogin("john") - .setName("John") - .setEmail("john@doo.com") - .setScmAccounts(asList("jo", "hn")) - .build()); - - serviceTester.assertThat(serviceTester.getPostRequest()) - .hasParam(PARAM_LOGIN, "john") - .hasParam(PARAM_NAME, "John") - .hasParam(PARAM_EMAIL, "john@doo.com") - .hasParam(PARAM_SCM_ACCOUNT, asList("jo", "hn")) - .andNoOtherParam(); - } - - @Test - public void groups() { - underTest.groups(GroupsRequest.builder() - .setLogin("john") - .setOrganization("orga-uuid") - .setSelected("all") - .setQuery("sonar-users") - .setPage(10) - .setPageSize(50) - .build()); - - assertThat(serviceTester.getGetParser()).isSameAs(GroupsWsResponse.parser()); - serviceTester.assertThat(serviceTester.getGetRequest()) - .hasParam(PARAM_LOGIN, "john") - .hasParam(PARAM_ORGANIZATION, "orga-uuid") - .hasParam(PARAM_SELECTED, "all") - .hasParam(TEXT_QUERY, "sonar-users") - .hasParam(PAGE, 10) - .hasParam(PAGE_SIZE, 50) - .andNoOtherParam(); - } - - @Test - public void current() { - underTest.current(); - - assertThat(serviceTester.getGetParser()).isSameAs(Users.CurrentWsResponse.parser()); - } -} diff --git a/tests/src/test/java/org/sonarqube/tests/issue/AutoAssignTest.java b/tests/src/test/java/org/sonarqube/tests/issue/AutoAssignTest.java index 89d0628ca73..367351225af 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/AutoAssignTest.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/AutoAssignTest.java @@ -19,7 +19,6 @@ */ package org.sonarqube.tests.issue; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -33,11 +32,12 @@ import org.sonar.wsclient.issue.IssueQuery; import org.sonarqube.ws.Users; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsClient; -import org.sonarqube.ws.client.user.CreateRequest; -import org.sonarqube.ws.client.user.SearchRequest; +import org.sonarqube.ws.client.users.CreateRequest; +import org.sonarqube.ws.client.users.SearchRequest; import util.ProjectAnalysis; import util.ProjectAnalysisRule; +import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.groups.Tuple.tuple; import static util.ItUtils.newAdminWsClient; @@ -180,18 +180,17 @@ public class AutoAssignTest extends AbstractIssueTest { private static void createUser(String login, String name, String email, String... scmAccounts) { newAdminWsClient(ORCHESTRATOR).users().create( - CreateRequest.builder() + new CreateRequest() .setLogin(login) .setName(name) .setEmail(email) .setPassword("xxxxxxx") - .setScmAccounts(Arrays.asList(scmAccounts)) - .build()); + .setScmAccounts(asList(scmAccounts))); } private static void deleteAllUsers() { WsClient wsClient = newAdminWsClient(ORCHESTRATOR); - Users.SearchWsResponse searchResponse = wsClient.users().search(SearchRequest.builder().build()); + Users.SearchWsResponse searchResponse = wsClient.users().search(new SearchRequest()); searchResponse.getUsersList().forEach(user -> { wsClient.wsConnector().call(new PostRequest("api/users/deactivate").setParam("login", user.getLogin())); }); diff --git a/tests/src/test/java/org/sonarqube/tests/organization/OrganizationMembershipTest.java b/tests/src/test/java/org/sonarqube/tests/organization/OrganizationMembershipTest.java index d401be4a186..ff304fc8124 100644 --- a/tests/src/test/java/org/sonarqube/tests/organization/OrganizationMembershipTest.java +++ b/tests/src/test/java/org/sonarqube/tests/organization/OrganizationMembershipTest.java @@ -33,6 +33,7 @@ import org.sonarqube.ws.Users.CreateWsResponse.User; import org.sonarqube.ws.client.HttpException; import org.sonarqube.ws.client.organizations.RemoveMemberRequest; import org.sonarqube.ws.client.permissions.AddUserRequest; +import org.sonarqube.ws.client.users.DeactivateRequest; public class OrganizationMembershipTest { @@ -108,7 +109,7 @@ public class OrganizationMembershipTest { User user = tester.users().generate(); addMembership(organization, user); - tester.users().service().deactivate(user.getLogin()); + tester.users().service().deactivate(new DeactivateRequest().setLogin(user.getLogin())); tester.organizations().assertThatNotMemberOf(organization, user); } diff --git a/tests/src/test/java/org/sonarqube/tests/startup/StartupIndexationTest.java b/tests/src/test/java/org/sonarqube/tests/startup/StartupIndexationTest.java index 8032a439d3b..073bed971cc 100644 --- a/tests/src/test/java/org/sonarqube/tests/startup/StartupIndexationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/startup/StartupIndexationTest.java @@ -36,7 +36,7 @@ import org.junit.rules.Timeout; import org.sonarqube.qa.util.LogsTailer; import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.Users; -import org.sonarqube.ws.client.user.SearchRequest; +import org.sonarqube.ws.client.users.SearchRequest; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.pluginArtifact; @@ -64,7 +64,7 @@ public class StartupIndexationTest { LogsTailer.Watch sonarQubeIsUpWatcher = sonarQube.logsTailer.watch("SonarQube is up")) { sonarQube.resume(); sonarQubeIsUpWatcher.waitForLog(20, TimeUnit.SECONDS); - SearchRequest searchRequest = SearchRequest.builder().setQuery("admin").build(); + SearchRequest searchRequest = new SearchRequest().setQ("admin"); Users.SearchWsResponse searchWsResponse = sonarQube.tester.wsClient().users().search(searchRequest); assertThat(searchWsResponse.getUsersCount()).isEqualTo(1); assertThat(searchWsResponse.getUsers(0).getName()).isEqualTo("Administrator"); diff --git a/tests/src/test/java/org/sonarqube/tests/user/BaseIdentityProviderTest.java b/tests/src/test/java/org/sonarqube/tests/user/BaseIdentityProviderTest.java index db5b754b000..cf1951f1194 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/BaseIdentityProviderTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/BaseIdentityProviderTest.java @@ -34,7 +34,7 @@ import org.sonarqube.qa.util.pageobjects.Navigation; import org.sonarqube.tests.Category4Suite; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsClient; -import org.sonarqube.ws.client.user.CreateRequest; +import org.sonarqube.ws.client.users.CreateRequest; import util.user.UserRule; import util.user.Users; @@ -284,12 +284,11 @@ public class BaseIdentityProviderTest { setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL); // Provision none local user in database - newAdminWsClient(ORCHESTRATOR).users().create(CreateRequest.builder() + newAdminWsClient(ORCHESTRATOR).users().create(new CreateRequest() .setLogin(USER_LOGIN) .setName(USER_NAME) .setEmail(USER_EMAIL) - .setLocal(false) - .build()); + .setLocal("false")); assertThat(userRule.getUserByLogin(USER_LOGIN).get()) .extracting(Users.User::isLocal, Users.User::getExternalIdentity, Users.User::getExternalProvider) .containsOnly(false, USER_LOGIN, "sonarqube"); diff --git a/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java b/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java index 1955c1c2f62..15916189fbc 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java @@ -39,7 +39,8 @@ import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.WsClientFactories; import org.sonarqube.ws.client.WsResponse; -import org.sonarqube.ws.client.user.CreateRequest; +import org.sonarqube.ws.client.users.CreateRequest; +import org.sonarqube.ws.client.users.DeactivateRequest; import org.sonarqube.ws.client.usertokens.GenerateRequest; import org.sonarqube.ws.client.usertokens.RevokeRequest; import org.sonarqube.ws.client.usertokens.SearchRequest; @@ -235,15 +236,14 @@ public class LocalAuthenticationTest { @Test public void authenticate_on_user_that_was_disabled() { User user = tester.users().generate(u -> u.setLogin("test").setPassword("password")); - tester.users().service().deactivate(user.getLogin()); + tester.users().service().deactivate(new DeactivateRequest().setLogin(user.getLogin())); - tester.users().service().create(CreateRequest.builder() + tester.users().service().create(new CreateRequest() .setLogin("test") .setName("Test") .setEmail("test@email.com") .setScmAccounts(asList("test1", "test2")) - .setPassword("password") - .build()); + .setPassword("password")); assertThat(checkAuthenticationWithAuthenticateWebService("test", "password")).isTrue(); assertThat(tester.users().getByLogin("test").get()) diff --git a/tests/src/test/java/org/sonarqube/tests/user/OAuth2IdentityProviderTest.java b/tests/src/test/java/org/sonarqube/tests/user/OAuth2IdentityProviderTest.java index 9052ad8b32c..56b79bfc3c3 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/OAuth2IdentityProviderTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/OAuth2IdentityProviderTest.java @@ -39,7 +39,7 @@ import org.sonarqube.ws.Users.SearchWsResponse.User; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsResponse; import org.sonarqube.ws.client.permissions.AddUserRequest; -import org.sonarqube.ws.client.user.CreateRequest; +import org.sonarqube.ws.client.users.CreateRequest; import util.selenium.Selenese; import static com.codeborne.selenide.Condition.visible; @@ -197,12 +197,11 @@ public class OAuth2IdentityProviderTest { enablePlugin(); // Provision none local user in database - tester.wsClient().users().create(CreateRequest.builder() + tester.wsClient().users().create(new CreateRequest() .setLogin(USER_LOGIN) .setName(USER_NAME) .setEmail(USER_EMAIL) - .setLocal(false) - .build()); + .setLocal("false")); User user = tester.users().getByLogin(USER_LOGIN).get(); assertThat(user.getLocal()).isFalse(); assertThat(user.getExternalIdentity()).isEqualTo(USER_LOGIN); diff --git a/tests/src/test/java/org/sonarqube/tests/user/OnboardingTest.java b/tests/src/test/java/org/sonarqube/tests/user/OnboardingTest.java index b3638e6019b..fd40d9e894b 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/OnboardingTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/OnboardingTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.Users.CreateWsResponse.User; import org.sonarqube.ws.client.WsClient; +import org.sonarqube.ws.client.users.DeactivateRequest; import util.ItUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -125,7 +126,7 @@ public class OnboardingTest { tester.as(user.getLogin()).wsClient().users().skipOnboardingTutorial(); verifyTutorial(user, false); - tester.wsClient().users().deactivate(user.getLogin()); + tester.wsClient().users().deactivate(new DeactivateRequest().setLogin(user.getLogin())); User reactivatedUser = tester.users().generate(u -> u.setLogin(user.getLogin()).setName(user.getName()).setPassword(user.getLogin())); verifyTutorial(reactivatedUser, true); diff --git a/tests/src/test/java/org/sonarqube/tests/user/RealmAuthenticationTest.java b/tests/src/test/java/org/sonarqube/tests/user/RealmAuthenticationTest.java index a99d247263c..bdee1e4f5db 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/RealmAuthenticationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/RealmAuthenticationTest.java @@ -43,7 +43,7 @@ import org.sonarqube.qa.util.pageobjects.SystemInfoPage; import org.sonarqube.qa.util.pageobjects.UsersManagementPage; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsResponse; -import org.sonarqube.ws.client.user.CreateRequest; +import org.sonarqube.ws.client.users.CreateRequest; import util.user.UserRule; import util.user.Users; @@ -324,12 +324,11 @@ public class RealmAuthenticationTest { @Test public void provision_user_before_authentication() { - tester.wsClient().users().create(CreateRequest.builder() + tester.wsClient().users().create(new CreateRequest() .setLogin(USER_LOGIN) .setName("Tester Testerovich") .setEmail("tester@example.org") - .setLocal(false) - .build()); + .setLocal("false")); // The user is created in SonarQube but doesn't exist yet in external authentication system verifyAuthenticationIsNotOk(USER_LOGIN, "123"); diff --git a/tests/src/test/java/org/sonarqube/tests/user/UserEsResilienceTest.java b/tests/src/test/java/org/sonarqube/tests/user/UserEsResilienceTest.java index f73b1fab03d..fdf1448a1de 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/UserEsResilienceTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/UserEsResilienceTest.java @@ -29,11 +29,11 @@ import org.junit.Test; import org.junit.rules.DisableOnDebug; import org.junit.rules.TestRule; import org.junit.rules.Timeout; -import org.sonarqube.tests.Byteman; import org.sonarqube.qa.util.Tester; +import org.sonarqube.tests.Byteman; import org.sonarqube.ws.Users.CreateWsResponse.User; -import org.sonarqube.ws.client.user.SearchRequest; -import org.sonarqube.ws.client.user.UpdateRequest; +import org.sonarqube.ws.client.users.SearchRequest; +import org.sonarqube.ws.client.users.UpdateRequest; import util.ItUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -98,7 +98,7 @@ public class UserEsResilienceTest { // Renaming is not propagated to index as long as recovery does not // run. String newName = "renamed"; - tester.users().service().update(UpdateRequest.builder().setLogin(login).setName(newName).build()); + tester.users().service().update(new UpdateRequest().setLogin(login).setName(newName)); assertThat(isReturnedInSearch(newName)).isFalse(); while (!isReturnedInSearch(newName)) { @@ -129,7 +129,7 @@ public class UserEsResilienceTest { // Renaming is not propagated to index as long as recovery does not // run. String newName = "renamed"; - expectHttpError(500, () -> tester.users().service().update(UpdateRequest.builder().setLogin(login).setName(newName).build())); + expectHttpError(500, () -> tester.users().service().update(new UpdateRequest().setLogin(login).setName(newName))); assertThat(isReturnedInSearch(newName)).isFalse(); while (!isReturnedInSearch(newName)) { @@ -139,7 +139,7 @@ public class UserEsResilienceTest { } private boolean isReturnedInSearch(String name) { - return tester.users().service().search(SearchRequest.builder().setQuery(name).build()).getUsersCount() == 1L; + return tester.users().service().search(new SearchRequest().setQ(name)).getUsersCount() == 1L; } } diff --git a/tests/src/test/java/org/sonarqube/tests/user/UsersPageTest.java b/tests/src/test/java/org/sonarqube/tests/user/UsersPageTest.java index 2aa83ffae74..143b9aa168c 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/UsersPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/UsersPageTest.java @@ -20,21 +20,20 @@ package org.sonarqube.tests.user; import com.sonar.orchestrator.Orchestrator; -import org.junit.After; -import org.sonarqube.ws.Users.CreateWsResponse.User; -import org.sonarqube.qa.util.Tester; -import org.sonarqube.qa.util.pageobjects.UsersManagementPage; -import org.sonarqube.tests.Category1Suite; import java.util.List; +import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.qa.util.pageobjects.UsersManagementPage; +import org.sonarqube.tests.Category1Suite; import org.sonarqube.ws.Users; -import org.sonarqube.ws.client.user.GroupsRequest; +import org.sonarqube.ws.Users.CreateWsResponse.User; +import org.sonarqube.ws.client.users.GroupsRequest; import util.user.UserRule; - import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; @@ -95,7 +94,7 @@ public class UsersPageTest { tester.groups().generate(null, g -> g.setName(group)); tester.groups().addMemberToGroups(tester.organizations().getDefaultOrganization(), login, group); - List result = tester.as(adminUser.getLogin()).wsClient().users().groups(GroupsRequest.builder().setLogin(login).build()).getGroupsList(); + List result = tester.as(adminUser.getLogin()).wsClient().users().groups(new GroupsRequest().setLogin(login)).getGroupsList(); assertThat(result).extracting(Users.GroupsWsResponse.Group::getName).contains(group); } } diff --git a/tests/src/test/java/util/user/UserRule.java b/tests/src/test/java/util/user/UserRule.java index 77c8562bfea..06cee60d42a 100644 --- a/tests/src/test/java/util/user/UserRule.java +++ b/tests/src/test/java/util/user/UserRule.java @@ -37,9 +37,9 @@ import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.WsResponse; import org.sonarqube.ws.client.permissions.AddUserRequest; 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.users.CreateRequest; +import org.sonarqube.ws.client.users.SearchRequest; +import org.sonarqube.ws.client.users.UsersService; import util.selenium.Consumer; import static java.util.Arrays.asList; @@ -109,28 +109,28 @@ public class UserRule extends ExternalResource implements GroupManagement { } public Users.CreateWsResponse.User createUser(String login, String name, @Nullable String email, String password) { - CreateRequest.Builder request = CreateRequest.builder() + CreateRequest request = new CreateRequest() .setLogin(login) .setName(name) .setEmail(email) .setPassword(password); - return adminWsClient().users().create(request.build()).getUser(); + return adminWsClient().users().create(request).getUser(); } /** * Create user with randomly generated values. By default password is the login. */ @SafeVarargs - public final org.sonarqube.ws.Users.CreateWsResponse.User generate(Consumer... populators) { + public final org.sonarqube.ws.Users.CreateWsResponse.User generate(Consumer... populators) { int id = ID_GENERATOR.getAndIncrement(); String login = "login" + id; - CreateRequest.Builder request = CreateRequest.builder() + CreateRequest request = new CreateRequest() .setLogin(login) .setName("name" + id) .setEmail(id + "@test.com") .setPassword(login); stream(populators).forEach(p -> p.accept(request)); - return adminWsClient().users().create(request.build()).getUser(); + return adminWsClient().users().create(request).getUser(); } public void createUser(String login, String password) { @@ -181,7 +181,7 @@ public class UserRule extends ExternalResource implements GroupManagement { public void deactivateAllUsers() { UsersService service = newAdminWsClient(orchestrator).users(); - List logins = service.search(SearchRequest.builder().build()).getUsersList() + List logins = service.search(new SearchRequest()).getUsersList() .stream() .filter(u -> !u.getLogin().equals("admin")) .map(u -> u.getLogin()) -- 2.39.5