diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-02 16:36:17 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-03 11:59:06 +0100 |
commit | c77b4f1eb2cd650846fe59784039480b3cdf77ac (patch) | |
tree | a2b04b5ebdb5774d7aaad4858a3f38d3cbe2cfa7 /sonar-ws | |
parent | ab0fd108dae208ae9c176b572d678066b66894d3 (diff) | |
download | sonarqube-c77b4f1eb2cd650846fe59784039480b3cdf77ac.tar.gz sonarqube-c77b4f1eb2cd650846fe59784039480b3cdf77ac.zip |
SONAR-8715 Handle api/users/create response as protobuf
Diffstat (limited to 'sonar-ws')
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java | 8 | ||||
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java | 3 | ||||
-rw-r--r-- | sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java (renamed from sonar-ws/src/main/java/org/sonarqube/ws/client/user/UserService.java) | 12 | ||||
-rw-r--r-- | sonar-ws/src/main/protobuf/ws-users.proto | 13 | ||||
-rw-r--r-- | sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java (renamed from sonar-ws/src/test/java/org/sonarqube/ws/client/user/UserServiceTest.java) | 9 |
5 files changed, 37 insertions, 8 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java index f8ab3a2abf1..f17c7f759ba 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java @@ -34,6 +34,7 @@ import org.sonarqube.ws.client.root.RootsService; import org.sonarqube.ws.client.rule.RulesService; import org.sonarqube.ws.client.setting.SettingsService; import org.sonarqube.ws.client.system.SystemService; +import org.sonarqube.ws.client.user.UsersService; import org.sonarqube.ws.client.usertoken.UserTokensService; import org.sonarqube.ws.client.webhook.WebhooksService; @@ -52,6 +53,7 @@ class DefaultWsClient implements WsClient { private final FavoritesService favoritesService; private final QualityProfilesService qualityProfilesService; private final IssuesService issuesService; + private final UsersService usersService; private final UserTokensService userTokensService; private final QualityGatesService qualityGatesService; private final MeasuresService measuresService; @@ -72,6 +74,7 @@ class DefaultWsClient implements WsClient { this.favoritesService = new FavoritesService(wsConnector); this.qualityProfilesService = new QualityProfilesService(wsConnector); this.issuesService = new IssuesService(wsConnector); + this.usersService = new UsersService(wsConnector); this.userTokensService = new UserTokensService(wsConnector); this.qualityGatesService = new QualityGatesService(wsConnector); this.measuresService = new MeasuresService(wsConnector); @@ -121,6 +124,11 @@ class DefaultWsClient implements WsClient { } @Override + public UsersService users() { + return usersService; + } + + @Override public UserTokensService userTokens() { return userTokensService; } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java index a14da6696e9..8e81e1d3dc7 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java @@ -34,6 +34,7 @@ import org.sonarqube.ws.client.root.RootsService; import org.sonarqube.ws.client.rule.RulesService; import org.sonarqube.ws.client.setting.SettingsService; import org.sonarqube.ws.client.system.SystemService; +import org.sonarqube.ws.client.user.UsersService; import org.sonarqube.ws.client.usertoken.UserTokensService; import org.sonarqube.ws.client.webhook.WebhooksService; @@ -68,6 +69,8 @@ public interface WsClient { QualityProfilesService qualityProfiles(); + UsersService users(); + UserTokensService userTokens(); QualityGatesService qualityGates(); diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UserService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java index df9c73ffd8f..3393adb5c07 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UserService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersService.java @@ -20,6 +20,7 @@ package org.sonarqube.ws.client.user; +import org.sonarqube.ws.WsUsers.CreateWsResponse; import org.sonarqube.ws.client.BaseService; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsConnector; @@ -33,19 +34,20 @@ import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_NAME; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_PASSWORD; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNT; -public class UserService extends BaseService { +public class UsersService extends BaseService { - public UserService(WsConnector wsConnector) { + public UsersService(WsConnector wsConnector) { super(wsConnector, CONTROLLER_USERS); } - public void create(CreateRequest request) { - call(new PostRequest(path(ACTION_CREATE)) + 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_SCM_ACCOUNT, request.getScmAccounts()), + CreateWsResponse.parser()); } public void update(UpdateRequest request) { diff --git a/sonar-ws/src/main/protobuf/ws-users.proto b/sonar-ws/src/main/protobuf/ws-users.proto index 46d7ac92660..0587640916c 100644 --- a/sonar-ws/src/main/protobuf/ws-users.proto +++ b/sonar-ws/src/main/protobuf/ws-users.proto @@ -35,3 +35,16 @@ message IdentityProvider { optional string iconPath = 3; optional string backgroundColor = 4; } + +message CreateWsResponse { + optional User user = 1; + + message User { + optional string login = 1; + optional string name = 2; + optional string email = 3; + repeated string scmAccounts = 4; + optional bool active = 5; + optional bool local = 6; + } +} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UserServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java index 675894bf53c..b652dc30869 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UserServiceTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/user/UsersServiceTest.java @@ -22,10 +22,12 @@ package org.sonarqube.ws.client.user; import org.junit.Rule; import org.junit.Test; +import org.sonarqube.ws.WsUsers.CreateWsResponse; import org.sonarqube.ws.client.ServiceTester; import org.sonarqube.ws.client.WsConnector; import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_EMAIL; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOGIN; @@ -33,12 +35,12 @@ import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_NAME; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_PASSWORD; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNT; -public class UserServiceTest { +public class UsersServiceTest { @Rule - public ServiceTester<UserService> serviceTester = new ServiceTester<>(new UserService(mock(WsConnector.class))); + public ServiceTester<UsersService> serviceTester = new ServiceTester<>(new UsersService(mock(WsConnector.class))); - private UserService underTest = serviceTester.getInstanceUnderTest(); + private UsersService underTest = serviceTester.getInstanceUnderTest(); @Test public void create() { @@ -50,6 +52,7 @@ public class UserServiceTest { .setScmAccounts(asList("jo", "hn")) .build()); + assertThat(serviceTester.getPostParser()).isSameAs(CreateWsResponse.parser()); serviceTester.assertThat(serviceTester.getPostRequest()) .hasParam(PARAM_LOGIN, "john") .hasParam(PARAM_PASSWORD, "123456") |