*/
package org.sonarqube.qa.util;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import org.sonarqube.ws.Users;
import org.sonarqube.ws.client.HttpException;
import org.sonarqube.ws.client.PostRequest;
-import org.sonarqube.ws.client.organization.CreateRequest;
-import org.sonarqube.ws.client.organization.OrganizationService;
-import org.sonarqube.ws.client.organization.SearchMembersRequest;
-import org.sonarqube.ws.client.organization.SearchRequest;
+import org.sonarqube.ws.client.organizations.AddMemberRequest;
+import org.sonarqube.ws.client.organizations.CreateRequest;
+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 static java.util.Arrays.stream;
}
void deleteNonGuardedOrganizations() {
- service().search(SearchRequest.builder().build()).getOrganizationsList()
+ service().search(new SearchRequest()).getOrganizationsList()
.stream()
.filter(o -> !o.getKey().equals("default-organization"))
- .forEach(organization -> service().delete(organization.getKey()));
+ .forEach(organization -> service().delete(new DeleteRequest().setOrganization(organization.getKey())));
}
@SafeVarargs
- public final Organizations.Organization generate(Consumer<CreateRequest.Builder>... populators) {
+ public final Organizations.Organization generate(Consumer<CreateRequest>... populators) {
int id = ID_GENERATOR.getAndIncrement();
- CreateRequest.Builder request = new CreateRequest.Builder()
+ CreateRequest request = new CreateRequest()
.setKey("org" + id)
.setName("Org " + id)
.setDescription("Description " + id)
.setUrl("http://test" + id);
stream(populators).forEach(p -> p.accept(request));
- return service().create(request.build()).getOrganization();
+ return service().create(request).getOrganization();
}
public OrganizationTester addMember(Organizations.Organization organization, Users.CreateWsResponse.User user) {
- service().addMember(organization.getKey(), user.getLogin());
+ service().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(user.getLogin()));
return this;
}
public Organizations.Organization getDefaultOrganization() {
- return service().search(SearchRequest.builder().build()).getOrganizationsList()
+ return service().search(new SearchRequest()).getOrganizationsList()
.stream()
.filter(o -> o.getKey().equals("default-organization"))
.findFirst().orElseThrow(() -> new IllegalStateException("Can't find default organization"));
}
public OrganizationTester assertThatOrganizationDoesNotExist(String organizationKey) {
- SearchRequest request = new SearchRequest.Builder().setOrganizations(organizationKey).build();
+ SearchRequest request = new SearchRequest().setOrganizations(Collections.singletonList(organizationKey));
Organizations.SearchWsResponse searchWsResponse = service().search(request);
Assertions.assertThat(searchWsResponse.getOrganizationsList()).isEmpty();
return this;
private void verifyOrganizationMembership(@Nullable Organizations.Organization organization, String userLogin, boolean isMember) {
List<Organizations.User> users = service().searchMembers(new SearchMembersRequest()
- .setQuery(userLogin)
+ .setQ(userLogin)
.setSelected("selected")
.setOrganization(organization != null ? organization.getKey() : null))
.getUsersList();
Assertions.assertThat(groups).hasSize(isMember ? 1 : 0);
}
- public OrganizationService service() {
- return session.wsClient().organizationsOld();
+ public OrganizationsService service() {
+ return session.wsClient().organizations();
}
}
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;
@SafeVarargs
public final User generateAdministrator(Consumer<CreateRequest.Builder>... populators) {
User user = generate(populators);
- session.wsClient().permissionsOld().addUser(new org.sonarqube.ws.client.permission.AddUserRequest().setLogin(user.getLogin()).setPermission("admin"));
+ 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"));
return user;
}
public final User generateAdministrator(Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
String organizationKey = organization.getKey();
User user = generate(populators);
- session.wsClient().organizationsOld().addMember(organizationKey, user.getLogin());
+ session.wsClient().organizations().addMember(new AddMemberRequest().setOrganization(organizationKey).setLogin(user.getLogin()));
session.wsClient().userGroups().addUser(new AddUserRequest()
.setOrganization(organizationKey)
.setLogin(user.getLogin())
@SafeVarargs
public final User generateAdministratorOnDefaultOrganization(Consumer<CreateRequest.Builder>... populators) {
User user = generate(populators);
- session.wsClient().organizationsOld().addMember(DEFAULT_ORGANIZATION_KEY, user.getLogin());
+ session.wsClient().organizations().addMember(new AddMemberRequest().setOrganization(DEFAULT_ORGANIZATION_KEY).setLogin(user.getLogin()));
session.wsClient().userGroups().addUser(new AddUserRequest()
.setOrganization(DEFAULT_ORGANIZATION_KEY)
.setLogin(user.getLogin())
@SafeVarargs
public final User generateMember(Organizations.Organization organization, Consumer<CreateRequest.Builder>... populators) {
User user = generate(populators);
- session.wsClient().organizationsOld().addMember(organization.getKey(), user.getLogin());
+ session.wsClient().organizations().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(user.getLogin()));
return user;
}
@SafeVarargs
public final User generateMemberOfDefaultOrganization(Consumer<CreateRequest.Builder>... populators) {
User user = generate(populators);
- session.wsClient().organizationsOld().addMember(DEFAULT_ORGANIZATION_KEY, user.getLogin());
+ session.wsClient().organizations().addMember(new AddMemberRequest().setOrganization(DEFAULT_ORGANIZATION_KEY).setLogin(user.getLogin()));
return user;
}
import org.sonarqube.ws.client.issues.IssuesService;
import org.sonarqube.ws.client.measures.MeasuresService;
import org.sonarqube.ws.client.notifications.NotificationsService;
-import org.sonarqube.ws.client.organization.OrganizationService;
import org.sonarqube.ws.client.organizations.OrganizationsService;
import org.sonarqube.ws.client.permissions.PermissionsService;
import org.sonarqube.ws.client.project.ProjectsService;
class DefaultWsClient implements WsClient {
private final WsConnector wsConnector;
- private final OrganizationService organizationsOld;
private final OrganizationsService organizations;
private final org.sonarqube.ws.client.permission.PermissionsService permissionsOld;
private final PermissionsService permissions;
DefaultWsClient(WsConnector wsConnector) {
this.wsConnector = wsConnector;
- this.organizationsOld = new OrganizationService(wsConnector);
this.organizations = new OrganizationsService(wsConnector);
this.permissionsOld = new org.sonarqube.ws.client.permission.PermissionsService(wsConnector);
this.permissions = new PermissionsService(wsConnector);
return wsConnector;
}
- @Override
- public OrganizationService organizationsOld() {
- return organizationsOld;
- }
-
@Override
public OrganizationsService organizations() {
return organizations;
import org.sonarqube.ws.client.issues.IssuesService;
import org.sonarqube.ws.client.measures.MeasuresService;
import org.sonarqube.ws.client.notifications.NotificationsService;
-import org.sonarqube.ws.client.organization.OrganizationService;
import org.sonarqube.ws.client.organizations.OrganizationsService;
import org.sonarqube.ws.client.permissions.PermissionsService;
import org.sonarqube.ws.client.project.ProjectsService;
*/
public interface WsClient {
- /**
- * @deprecated since 7.0 use {@link #organizations()} instead
- */
- @Deprecated
- OrganizationService organizationsOld();
-
OrganizationsService organizations();
/**
+++ /dev/null
-/*
- * 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.organization;
-
-import javax.annotation.concurrent.Immutable;
-
-@Immutable
-public class CreateRequest {
- private final String name;
- private final String key;
- private final String description;
- private final String url;
- private final String avatar;
-
- private CreateRequest(Builder builder) {
- this.name = builder.name;
- this.key = builder.key;
- this.description = builder.description;
- this.url = builder.url;
- this.avatar = builder.avatar;
- }
-
- public String getName() {
- return name;
- }
-
- public String getKey() {
- return key;
- }
-
- public String getDescription() {
- return description;
- }
-
- public String getUrl() {
- return url;
- }
-
- public String getAvatar() {
- return avatar;
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
- private String name;
- private String key;
- private String description;
- private String url;
- private String avatar;
-
- public Builder setName(String name) {
- this.name = name;
- return this;
- }
-
- public Builder setKey(String key) {
- this.key = key;
- return this;
- }
-
- public Builder setDescription(String description) {
- this.description = description;
- return this;
- }
-
- public Builder setUrl(String url) {
- this.url = url;
- return this;
- }
-
- public Builder setAvatar(String avatar) {
- this.avatar = avatar;
- return this;
- }
-
- public CreateRequest build() {
- return new CreateRequest(this);
- }
- }
-}
+++ /dev/null
-/*
- * 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.organization;
-
-import org.sonarqube.ws.Organizations.AddMemberWsResponse;
-import org.sonarqube.ws.Organizations.SearchMembersWsResponse;
-import org.sonarqube.ws.Organizations.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 static java.util.Objects.requireNonNull;
-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.Organizations.CreateWsResponse;
-import static org.sonarqube.ws.Organizations.UpdateWsResponse;
-
-/**
- * @deprecated since 7.0, use {@link org.sonarqube.ws.client.organizations.OrganizationsService} instead
- */
-@Deprecated
-public class OrganizationService extends BaseService {
-
- public OrganizationService(WsConnector wsConnector) {
- super(wsConnector, "api/organizations");
- }
-
- public SearchWsResponse search(SearchRequest request) {
- GetRequest get = new GetRequest(path("search"))
- .setParam("organizations", inlineMultipleParamValue(request.getOrganizations()))
- .setParam(PAGE, request.getPage())
- .setParam(PAGE_SIZE, request.getPageSize());
-
- return call(get, SearchWsResponse.parser());
- }
-
- public CreateWsResponse create(CreateRequest request) {
- PostRequest post = new PostRequest(path("create"))
- .setParam("name", request.getName())
- .setParam("key", request.getKey())
- .setParam("description", request.getDescription())
- .setParam("url", request.getUrl())
- .setParam("avatar", request.getAvatar());
-
- return call(post, CreateWsResponse.parser());
- }
-
- public UpdateWsResponse update(UpdateRequest request) {
- PostRequest post = new PostRequest(path("update"))
- .setParam("key", request.getKey())
- .setParam("name", request.getName())
- .setParam("description", request.getDescription())
- .setParam("url", request.getUrl())
- .setParam("avatar", request.getAvatar());
-
- return call(post, UpdateWsResponse.parser());
- }
-
- public void delete(String key) {
- PostRequest post = new PostRequest(path("delete"))
- .setParam("organization", key);
-
- call(post).failIfNotSuccessful();
- }
-
- public SearchMembersWsResponse searchMembers(SearchMembersRequest request) {
- GetRequest get = new GetRequest(path("search_members"))
- .setParam("organization", request.getOrganization())
- .setParam("selected", request.getSelected())
- .setParam(TEXT_QUERY, request.getQuery())
- .setParam(PAGE, request.getPage())
- .setParam(PAGE_SIZE, request.getPageSize());
-
- return call(get, SearchMembersWsResponse.parser());
- }
-
- public AddMemberWsResponse addMember(String organizationKey, String login) {
- PostRequest post = new PostRequest(path("add_member"))
- .setParam("organization", requireNonNull(organizationKey))
- .setParam("login", requireNonNull(login));
-
- return call(post, AddMemberWsResponse.parser());
- }
-
- public void removeMember(String organizationKey, String login) {
- PostRequest post = new PostRequest(path("remove_member"))
- .setParam("organization", requireNonNull(organizationKey))
- .setParam("login", requireNonNull(login));
-
- call(post);
- }
-
- public void updateProjectVisibility(UpdateProjectVisibilityRequest request) {
- PostRequest post = new PostRequest(path("update_project_visibility"))
- .setParam("organization", request.getOrganization())
- .setParam("projectVisibility", request.getProjectVisibility());
- call(post, UpdateWsResponse.parser());
- }
-}
+++ /dev/null
-/*
- * 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.organization;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-public class SearchMembersRequest {
- private String organization;
- private String selected;
- private String query;
- private Integer page;
- private Integer pageSize;
-
- @CheckForNull
- public String getOrganization() {
- return organization;
- }
-
- public SearchMembersRequest setOrganization(@Nullable String organization) {
- this.organization = organization;
- return this;
- }
-
- @CheckForNull
- public String getSelected() {
- return selected;
- }
-
- public SearchMembersRequest setSelected(@Nullable String selected) {
- this.selected = selected;
- return this;
- }
-
- @CheckForNull
- public String getQuery() {
- return query;
- }
-
- public SearchMembersRequest setQuery(@Nullable String query) {
- this.query = query;
- return this;
- }
-
- @CheckForNull
- public Integer getPage() {
- return page;
- }
-
- public SearchMembersRequest setPage(@Nullable Integer page) {
- this.page = page;
- return this;
- }
-
- @CheckForNull
- public Integer getPageSize() {
- return pageSize;
- }
-
- public SearchMembersRequest setPageSize(@Nullable Integer pageSize) {
- this.pageSize = pageSize;
- return this;
- }
-}
+++ /dev/null
-/*
- * 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.organization;
-
-import java.util.List;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.Immutable;
-
-import static java.util.Arrays.asList;
-
-@Immutable
-public class SearchRequest {
- private final Integer page;
- private final Integer pageSize;
- private final List<String> organizations;
-
- private SearchRequest(Builder builder) {
- this.page = builder.page;
- this.pageSize = builder.pageSize;
- this.organizations = builder.organizations;
- }
-
- @CheckForNull
- public Integer getPageSize() {
- return pageSize;
- }
-
- @CheckForNull
- public Integer getPage() {
- return page;
- }
-
- @CheckForNull
- public List<String> getOrganizations() {
- return organizations;
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static final class Builder {
- private Integer page;
- private Integer pageSize;
- private List<String> organizations;
-
- public Builder setPage(@Nullable Integer page) {
- this.page = page;
- return this;
- }
-
- public Builder setPageSize(@Nullable Integer pageSize) {
- this.pageSize = pageSize;
- return this;
- }
-
- public Builder setOrganizations(String... organizations) {
- this.organizations = asList(organizations);
- return this;
- }
-
- public SearchRequest build() {
- return new SearchRequest(this);
- }
- }
-}
+++ /dev/null
-/*
- * 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.organization;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.Immutable;
-
-@Immutable
-public class UpdateProjectVisibilityRequest {
- private final String organization;
- private final String projectVisibility;
-
- private UpdateProjectVisibilityRequest(Builder builder) {
- this.organization = builder.organization;
- this.projectVisibility = builder.projectVisibility;
- }
-
- @CheckForNull
- public String getOrganization() {
- return organization;
- }
-
- @CheckForNull
- public String getProjectVisibility() {
- return projectVisibility;
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
- private String organization;
- private String projectVisibility;
-
- public Builder setOrganization(@Nullable String organization) {
- this.organization = organization;
- return this;
- }
-
- public Builder setProjectVisibility(@Nullable String projectVisibility) {
- this.projectVisibility = projectVisibility;
- return this;
- }
-
- public UpdateProjectVisibilityRequest build() {
- return new UpdateProjectVisibilityRequest(this);
- }
- }
-}
+++ /dev/null
-/*
- * 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.organization;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.Immutable;
-
-@Immutable
-public class UpdateRequest {
- private final String key;
- private final String name;
- private final String description;
- private final String url;
- private final String avatar;
-
- private UpdateRequest(Builder builder) {
- this.name = builder.name;
- this.key = builder.key;
- this.description = builder.description;
- this.url = builder.url;
- this.avatar = builder.avatar;
- }
-
- @CheckForNull
- public String getName() {
- return name;
- }
-
- @CheckForNull
- public String getKey() {
- return key;
- }
-
- @CheckForNull
- public String getDescription() {
- return description;
- }
-
- @CheckForNull
- public String getUrl() {
- return url;
- }
-
- @CheckForNull
- public String getAvatar() {
- return avatar;
- }
-
- public static class Builder {
- private String key;
- private String name;
- private String description;
- private String url;
- private String avatar;
-
- public Builder setKey(@Nullable String key) {
- this.key = key;
- 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 Builder setUrl(@Nullable String url) {
- this.url = url;
- return this;
- }
-
- public Builder setAvatar(@Nullable String avatar) {
- this.avatar = avatar;
- return this;
- }
-
- public UpdateRequest build() {
- return new UpdateRequest(this);
- }
- }
-}
+++ /dev/null
-/*
- * 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.organization;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
+++ /dev/null
-/*
- * 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.organization;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonarqube.ws.Organizations;
-import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.ServiceTester;
-import org.sonarqube.ws.client.WsConnector;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class OrganizationServiceTest {
-
- @Rule
- public ServiceTester<OrganizationService> serviceTester = new ServiceTester<>(new OrganizationService(mock(WsConnector.class)));
-
- private OrganizationService underTest = serviceTester.getInstanceUnderTest();
-
- @Test
- public void search() {
- underTest.search(SearchRequest.builder()
- .setOrganizations("orga1", "orga2")
- .setPage(2)
- .setPageSize(10)
- .build());
- GetRequest getRequest = serviceTester.getGetRequest();
-
- assertThat(serviceTester.getGetParser()).isSameAs(Organizations.SearchWsResponse.parser());
- serviceTester.assertThat(getRequest)
- .hasParam("organizations", "orga1,orga2")
- .hasParam("p", 2)
- .hasParam("ps", 10)
- .andNoOtherParam();
- }
-
- @Test
- public void search_members() {
- underTest.searchMembers(new SearchMembersRequest()
- .setOrganization("orga")
- .setSelected("selected")
- .setQuery("john")
- .setPage(2)
- .setPageSize(10));
- GetRequest getRequest = serviceTester.getGetRequest();
-
- assertThat(serviceTester.getGetParser()).isSameAs(Organizations.SearchMembersWsResponse.parser());
- serviceTester.assertThat(getRequest)
- .hasParam("organization", "orga")
- .hasParam("selected", "selected")
- .hasParam("q", "john")
- .hasParam("p", 2)
- .hasParam("ps", 10)
- .andNoOtherParam();
- }
-
- @Test
- public void add_member() {
- underTest.addMember("O1", "login-1");
-
- assertThat(serviceTester.getPostParser()).isSameAs(Organizations.AddMemberWsResponse.parser());
- serviceTester.assertThat(serviceTester.getPostRequest())
- .hasPath("add_member")
- .hasParam("organization", "O1")
- .hasParam("login", "login-1")
- .andNoOtherParam();
- }
-
- @Test
- public void remove_member() {
- underTest.removeMember("O1", "login-1");
-
- serviceTester.assertThat(serviceTester.getPostRequest())
- .hasPath("remove_member")
- .hasParam("organization", "O1")
- .hasParam("login", "login-1")
- .andNoOtherParam();
- }
-
- @Test
- public void update_project_visibility() {
- underTest.updateProjectVisibility(UpdateProjectVisibilityRequest.builder()
- .setOrganization("O1")
- .setProjectVisibility("private")
- .build());
-
- serviceTester.assertThat(serviceTester.getPostRequest())
- .hasPath("update_project_visibility")
- .hasParam("organization", "O1")
- .hasParam("projectVisibility", "private")
- .andNoOtherParam();
- }
-}
import org.sonarqube.ws.Projects.CreateWsResponse;
import org.sonarqube.ws.Users.CreateWsResponse.User;
import org.sonarqube.ws.client.issue.SearchRequest;
+import org.sonarqube.ws.client.organizations.AddMemberRequest;
import org.sonarqube.ws.client.permission.AddUserRequest;
import org.sonarqube.ws.client.project.CreateRequest;
import util.ItUtils;
}
private void addMemberToOrganization(User member) {
- tester.organizations().service().addMember(organization.getKey(), member.getLogin());
+ tester.organizations().service().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(member.getLogin()));
}
private void grantUserPermission(String projectKey, User member) {
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.WsResponse;
import org.sonarqube.ws.client.ce.TaskRequest;
-import org.sonarqube.ws.client.organization.UpdateProjectVisibilityRequest;
+import org.sonarqube.ws.client.organizations.UpdateProjectVisibilityRequest;
import org.sonarqube.ws.client.project.CreateRequest;
import org.sonarqube.ws.client.project.UpdateVisibilityRequest;
import util.ItUtils;
public void does_not_fail_to_update_default_projects_visibility_to_private() {
tester.settings().setGlobalSettings("sonar.billing.preventUpdatingProjectsVisibilityToPrivate", "false");
- tester.wsClient().organizationsOld().updateProjectVisibility(UpdateProjectVisibilityRequest.builder()
+ tester.wsClient().organizations().updateProjectVisibility(new UpdateProjectVisibilityRequest()
.setOrganization(organization.getKey())
- .setProjectVisibility("private")
- .build());
+ .setProjectVisibility("private"));
assertWsResponseAsAdmin(new GetRequest("api/navigation/organization").setParam("organization", organization.getKey()),
"\"projectVisibility\":\"private\"");
expectHttpError(400,
format("Organization %s cannot use private project", organization.getKey()),
- () -> tester.wsClient().organizationsOld()
- .updateProjectVisibility(UpdateProjectVisibilityRequest.builder().setOrganization(organization.getKey()).setProjectVisibility("private").build()));
+ () -> tester.wsClient().organizations()
+ .updateProjectVisibility(new UpdateProjectVisibilityRequest().setOrganization(organization.getKey()).setProjectVisibility("private")));
}
@Test
import org.sonarqube.ws.Organizations.Organization;
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.permission.AddUserRequest;
public class OrganizationMembershipTest {
tester.wsClient().permissionsOld().addUser(new AddUserRequest().setLogin(user.getLogin()).setPermission("admin").setOrganization(organization.getKey()));
tester.organizations().assertThatMemberOf(organization, user);
// Admin is the creator of the organization so he was granted with admin permission
- tester.wsClient().organizationsOld().removeMember(organization.getKey(), "admin");
+ tester.wsClient().organizations().removeMember(new RemoveMemberRequest().setOrganization(organization.getKey()).setLogin("admin"));
expectedException.expect(HttpException.class);
expectedException.expectMessage("The last administrator member cannot be removed");
}
private void removeMembership(Organization organization, User user) {
- tester.wsClient().organizationsOld().removeMember(organization.getKey(), user.getLogin());
+ tester.wsClient().organizations().removeMember(new RemoveMemberRequest().setOrganization(organization.getKey()).setLogin(user.getLogin()));
}
}
import org.sonarqube.ws.Users;
import org.sonarqube.ws.Users.CreateWsResponse.User;
import org.sonarqube.ws.client.component.ComponentsService;
-import org.sonarqube.ws.client.organization.CreateRequest;
-import org.sonarqube.ws.client.organization.OrganizationService;
-import org.sonarqube.ws.client.organization.SearchRequest;
-import org.sonarqube.ws.client.organization.UpdateRequest;
+import org.sonarqube.ws.client.organizations.AddMemberRequest;
+import org.sonarqube.ws.client.organizations.CreateRequest;
+import org.sonarqube.ws.client.organizations.DeleteRequest;
+import org.sonarqube.ws.client.organizations.OrganizationsService;
+import org.sonarqube.ws.client.organizations.SearchRequest;
+import org.sonarqube.ws.client.organizations.UpdateRequest;
import org.sonarqube.ws.client.permission.AddUserRequest;
import org.sonarqube.ws.client.permission.PermissionsService;
import org.sonarqube.ws.client.roots.SetRootRequest;
@Test
public void default_organization_should_exist() {
- Organization defaultOrg = tester.organizations().service().search(SearchRequest.builder().build())
+ Organization defaultOrg = tester.organizations().service().search(new SearchRequest())
.getOrganizationsList()
.stream()
.filter(Organization::getGuarded)
@Test
public void default_organization_can_not_be_deleted() {
- expectBadRequestError(() -> tester.organizations().service().delete(DEFAULT_ORGANIZATION_KEY));
+ expectBadRequestError(() -> tester.organizations().service().delete(new DeleteRequest().setOrganization(DEFAULT_ORGANIZATION_KEY)));
}
@Test
public void create_update_and_delete_organizations() {
- OrganizationService service = tester.organizations().service();
+ OrganizationsService service = tester.organizations().service();
Organization org = tester.organizations().generate(o -> o
.setName(NAME)
.setDescription(DESCRIPTION)
.setUrl(URL)
- .setAvatar(AVATAR_URL)
- .build());
+ .setAvatar(AVATAR_URL));
assertThat(org.getName()).isEqualTo(NAME);
assertThat(org.getDescription()).isEqualTo(DESCRIPTION);
assertThat(org.getUrl()).isEqualTo(URL);
assertThatBuiltInQualityProfilesExist(org);
// update by key
- service.update(new UpdateRequest.Builder()
+ service.update(new UpdateRequest()
.setKey(org.getKey())
.setName("new name")
.setDescription("new description")
.setUrl("new url")
- .setAvatar("new avatar url")
- .build());
+ .setAvatar("new avatar url"));
verifyOrganization(org, "new name", "new description", "new url", "new avatar url");
// remove optional fields
- service.update(new UpdateRequest.Builder()
+ service.update(new UpdateRequest()
.setKey(org.getKey())
.setName("new name 2")
.setDescription("")
.setUrl("")
- .setAvatar("")
- .build());
+ .setAvatar(""));
verifyOrganization(org, "new name 2", null, null, null);
// delete organization
- service.delete(org.getKey());
+ service.delete(new DeleteRequest().setOrganization(org.getKey()));
assertThatOrganizationDoesNotExit(org);
assertThatQualityProfilesDoNotExist(org);
// create again
- service.create(new CreateRequest.Builder()
+ service.create(new CreateRequest()
.setName(NAME)
- .setKey(org.getKey())
- .build())
+ .setKey(org.getKey()))
.getOrganization();
verifyOrganization(org, NAME, null, null, null);
}
// create organization without key
String name = "Foo Company to keyize";
String expectedKey = "foo-company-to-keyize";
- Organization createdOrganization = tester.organizations().service().create(new CreateRequest.Builder()
- .setName(name)
- .build())
+ Organization createdOrganization = tester.organizations().service().create(new CreateRequest()
+ .setName(name))
.getOrganization();
assertThat(createdOrganization.getKey()).isEqualTo(expectedKey);
verifyOrganization(createdOrganization, name, null, null, null);
OrganizationTester anonymousTester = tester.asAnonymous().organizations();
expectForbiddenError(() -> anonymousTester.generate());
- expectUnauthorizedError(() -> anonymousTester.service().update(new UpdateRequest.Builder().setKey(org.getKey()).setName("new name").build()));
- expectUnauthorizedError(() -> anonymousTester.service().delete(org.getKey()));
+ expectUnauthorizedError(() -> anonymousTester.service().update(new UpdateRequest().setKey(org.getKey()).setName("new name")));
+ expectUnauthorizedError(() -> anonymousTester.service().delete(new DeleteRequest().setOrganization(org.getKey())));
}
@Test
OrganizationTester userTester = tester.as(user.getLogin()).organizations();
expectForbiddenError(() -> userTester.generate());
- expectForbiddenError(() -> userTester.service().update(new UpdateRequest.Builder().setKey(org.getKey()).setName("new name").build()));
- expectForbiddenError(() -> userTester.service().delete(org.getKey()));
+ expectForbiddenError(() -> userTester.service().update(new UpdateRequest().setKey(org.getKey()).setName("new name")));
+ expectForbiddenError(() -> userTester.service().delete(new DeleteRequest().setOrganization(org.getKey())));
}
@Test
Organization org = asUser.generate();
// delete org, attempt recreate when no root anymore and ensure it can't anymore
- asUser.service().delete(org.getKey());
+ asUser.service().delete(new DeleteRequest().setOrganization(org.getKey()));
tester.wsClient().roots().unsetRoot(new UnsetRootRequest().setLogin(user.getLogin()));
expectForbiddenError(() -> asUser.generate());
User user = tester.users().generate();
Group group = tester.groups().generate(organization);
// users.removeGroups("sonar-users");
- tester.organizations().service().addMember(organization.getKey(), user.getLogin());
+ tester.organizations().service().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(user.getLogin()));
addPermissionsToUser(organization.getKey(), user.getLogin(), "provisioning", "scan");
runProjectAnalysis(orchestrator, "shared/xoo-sample",
ComponentsService componentsService = tester.wsClient().componentsOld();
assertThat(searchSampleProject(organization.getKey(), componentsService).getComponentsList()).hasSize(1);
- tester.organizations().service().delete(organization.getKey());
+ tester.organizations().service().delete(new DeleteRequest().setOrganization(organization.getKey()));
expectNotFoundError(() -> searchSampleProject(organization.getKey(), componentsService));
assertThatOrganizationDoesNotExit(organization);
public void return_groups_belonging_to_a_user_on_an_organization() throws Exception {
Organization organization = tester.organizations().generate();
User user = tester.users().generate();
- tester.organizations().service().addMember(organization.getKey(), user.getLogin());
+ tester.organizations().service().addMember(new AddMemberRequest().setOrganization(organization.getKey()).setLogin(user.getLogin()));
Group group = tester.groups().generate(organization);
tester.groups().addMemberToGroups(organization, user.getLogin(), group.getName());
assertThat(organization.getKey()).isNotEmpty();
assertThat(organization.getGuarded()).isFalse();
- List<Organization> reloadedOrgs = tester.organizations().service().search(SearchRequest.builder().build()).getOrganizationsList();
+ List<Organization> reloadedOrgs = tester.organizations().service().search(new SearchRequest()).getOrganizationsList();
assertThat(reloadedOrgs)
.filteredOn(o -> o.getKey().equals(organization.getKey()))
.hasSize(1);
}
private void assertThatOrganizationDoesNotExit(Organization org) {
- SearchRequest request = new SearchRequest.Builder().setOrganizations(org.getKey()).build();
+ SearchRequest request = new SearchRequest().setOrganizations(singletonList(org.getKey()));
assertThat(tester.organizations().service().search(request).getOrganizationsList()).isEmpty();
}
private void verifyOrganization(Organization createdOrganization, String name, String description, String url,
String avatarUrl) {
- SearchRequest request = new SearchRequest.Builder().setOrganizations(createdOrganization.getKey()).build();
+ SearchRequest request = new SearchRequest().setOrganizations(singletonList(createdOrganization.getKey()));
List<Organization> result = tester.organizations().service().search(request).getOrganizationsList();
assertThat(result).hasSize(1);
Organization searchedOrganization = result.get(0);
import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.Users;
-import org.sonarqube.ws.client.organization.SearchRequest;
+import org.sonarqube.ws.client.organizations.SearchRequest;
import static org.assertj.core.api.Assertions.assertThat;
public void personal_organizations_are_created_for_new_users() {
Users.CreateWsResponse.User user = tester.users().generate();
- List<Organizations.Organization> existing = tester.wsClient().organizationsOld().search(SearchRequest.builder().build()).getOrganizationsList();
+ List<Organizations.Organization> existing = tester.wsClient().organizations().search(new SearchRequest()).getOrganizationsList();
assertThat(existing)
.filteredOn(Organizations.Organization::getGuarded)
.filteredOn(o -> o.getKey().equals(user.getLogin()))
import org.sonarqube.ws.Users.CreateWsResponse.User;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.organizations.DeleteRequest;
import org.sonarqube.ws.client.qualityprofile.AddProjectRequest;
import org.sonarqube.ws.client.qualityprofile.ChangeParentRequest;
import org.sonarqube.ws.client.qualityprofile.CopyRequest;
adminSession.service().changeParent(
ChangeParentRequest.builder().setParentKey(builtInProfile.getKey()).setProfileKey(inheritedProfile2.getKey()).build());
- tester.organizations().service().delete(org.getKey());
+ tester.organizations().service().delete(new DeleteRequest().setOrganization(org.getKey()));
expectMissingError(() -> tester.qProfiles().service().search(new SearchRequest()
.setOrganizationKey(org.getKey())));
import org.sonarqube.ws.UserGroups.Group;
import org.sonarqube.ws.Users.CreateWsResponse.User;
import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.organizations.AddMemberRequest;
public class OrganizationIdentityProviderTest {
Group group = tester.groups().generate(null);
User user = tester.users().generate();
// Add user as member of default organization
- tester.wsClient().organizationsOld().addMember("default-organization", user.getLogin());
+ tester.wsClient().organizations().addMember(new AddMemberRequest().setOrganization("default-organization").setLogin(user.getLogin()));
tester.groups().assertThatUserIsMemberOf(null, user.getLogin(), "Members");
enableUserCreationByAuthPlugin(user.getLogin());
// No group is returned by the plugin