diff options
Diffstat (limited to 'server')
14 files changed, 633 insertions, 8 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java new file mode 100644 index 00000000000..7251b36acde --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java @@ -0,0 +1,62 @@ +/* + * 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.sonar.server.qualityprofile.ws; + +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; + +import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; +import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ADD_GROUP; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_GROUP; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE; + +public class AddGroupAction implements QProfileWsAction { + + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context + .createAction(ACTION_ADD_GROUP) + .setDescription("Allow a group to edit a Quality Profile.<br>" + + "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.") + .setHandler(this) + .setPost(true) + .setInternal(true) + .setSince("6.6"); + + action.createParam(PARAM_PROFILE) + .setDescription("Quality Profile key.") + .setRequired(true) + .setExampleValue(UUID_EXAMPLE_01); + + action.createParam(PARAM_GROUP) + .setDescription("Group name") + .setRequired(true) + .setExampleValue("sonar-administrators"); + + createOrganizationParam(action); + } + + @Override + public void handle(Request request, Response response) throws Exception { + // TODO + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddUserAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddUserAction.java new file mode 100644 index 00000000000..ca0ed070ecd --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddUserAction.java @@ -0,0 +1,78 @@ +/* + * 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.sonar.server.qualityprofile.ws; + +import java.util.Arrays; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Languages; +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; + +import static org.sonar.core.util.stream.MoreCollectors.toSet; +import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ADD_USER; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LOGIN; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE; + +public class AddUserAction implements QProfileWsAction { + + private final Languages languages; + + public AddUserAction(Languages languages) { + this.languages = languages; + } + + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context + .createAction(ACTION_ADD_USER) + .setDescription("Allow a user to edit a Quality Profile.<br>" + + "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.") + .setHandler(this) + .setPost(true) + .setInternal(true) + .setSince("6.6"); + + action.createParam(PARAM_QUALITY_PROFILE) + .setDescription("Quality Profile name") + .setRequired(true) + .setExampleValue("Recommended quality profile"); + + action + .createParam(PARAM_LANGUAGE) + .setDescription("Quality profile language") + .setRequired(true) + .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(toSet())); + + action.createParam(PARAM_LOGIN) + .setDescription("User login") + .setRequired(true) + .setExampleValue("john.doe"); + + createOrganizationParam(action); + } + + @Override + public void handle(Request request, Response response) throws Exception { + // TODO + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java index f3362d94a61..6f5aa204f81 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java @@ -25,8 +25,9 @@ public class QProfilesWsModule extends Module { @Override protected void configureModule() { add( - QProfileWsSupport.class, AddProjectAction.class, + AddGroupAction.class, + AddUserAction.class, BackupAction.class, ActivateRulesAction.class, DeactivateRulesAction.class, @@ -42,16 +43,21 @@ public class QProfilesWsModule extends Module { ImportersAction.class, InheritanceAction.class, QProfilesWs.class, + QProfileWsSupport.class, ProjectsAction.class, RenameAction.class, RemoveProjectAction.class, + RemoveGroupAction.class, + RemoveUserAction.class, RestoreAction.class, RestoreBuiltInAction.class, ActivateRuleAction.class, DeactivateRuleAction.class, SearchAction.class, + SearchGroupsAction.class, + SearchUsersAction.class, SetDefaultAction.class, ShowAction.class - ); + ); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveGroupAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveGroupAction.java new file mode 100644 index 00000000000..2df9637a2db --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveGroupAction.java @@ -0,0 +1,62 @@ +/* + * 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.sonar.server.qualityprofile.ws; + +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; + +import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; +import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_REMOVE_GROUP; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_GROUP; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE; + +public class RemoveGroupAction implements QProfileWsAction { + + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context + .createAction(ACTION_REMOVE_GROUP) + .setDescription("Remove the ability from a group to edit a Quality Profile.<br>" + + "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.") + .setHandler(this) + .setPost(true) + .setInternal(true) + .setSince("6.6"); + + action.createParam(PARAM_PROFILE) + .setDescription("Quality Profile key.") + .setRequired(true) + .setExampleValue(UUID_EXAMPLE_01); + + action.createParam(PARAM_GROUP) + .setDescription("Group name") + .setRequired(true) + .setExampleValue("sonar-administrators"); + + createOrganizationParam(action); + } + + @Override + public void handle(Request request, Response response) throws Exception { + // TODO + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveUserAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveUserAction.java new file mode 100644 index 00000000000..4efdccaf9c8 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveUserAction.java @@ -0,0 +1,78 @@ +/* + * 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.sonar.server.qualityprofile.ws; + +import java.util.Arrays; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Languages; +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; + +import static org.sonar.core.util.stream.MoreCollectors.toSet; +import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_REMOVE_USER; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LOGIN; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE; + +public class RemoveUserAction implements QProfileWsAction { + + private final Languages languages; + + public RemoveUserAction(Languages languages) { + this.languages = languages; + } + + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context + .createAction(ACTION_REMOVE_USER) + .setDescription("Remove the ability from a user to edit a Quality Profile.<br>" + + "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.") + .setHandler(this) + .setPost(true) + .setInternal(true) + .setSince("6.6"); + + action.createParam(PARAM_QUALITY_PROFILE) + .setDescription("Quality Profile name") + .setRequired(true) + .setExampleValue("Recommended quality profile"); + + action + .createParam(PARAM_LANGUAGE) + .setDescription("Quality profile language") + .setRequired(true) + .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(toSet())); + + action.createParam(PARAM_LOGIN) + .setDescription("User login") + .setRequired(true) + .setExampleValue("john.doe"); + + createOrganizationParam(action); + } + + @Override + public void handle(Request request, Response response) throws Exception { + // TODO + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java index b192a68d883..6d4a594d26f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java @@ -238,6 +238,7 @@ public class SearchAction implements QProfileWsAction { Map<String, QProfileDto> profilesByKey = profiles.stream().collect(Collectors.toMap(QProfileDto::getKee, identity())); SearchWsResponse.Builder response = SearchWsResponse.newBuilder(); + response.setActions(SearchWsResponse.Actions.newBuilder().setCreate(true)); for (QProfileDto profile : profiles) { QualityProfile.Builder profileBuilder = response.addProfilesBuilder(); @@ -261,6 +262,11 @@ public class SearchAction implements QProfileWsAction { writeParentFields(profileBuilder, profile, profilesByKey); profileBuilder.setIsInherited(profile.getParentKee() != null); profileBuilder.setIsBuiltIn(profile.isBuiltIn()); + + profileBuilder.setActions(SearchWsResponse.Actions.newBuilder() + .setEdit(true) + .setSetAsDefault(false) + .setCopy(false)); } return response.build(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java new file mode 100644 index 00000000000..0803b39e2b8 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java @@ -0,0 +1,76 @@ +/* + * 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.sonar.server.qualityprofile.ws; + +import java.util.Arrays; +import org.apache.commons.io.IOUtils; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Languages; +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; + +import static org.sonar.core.util.stream.MoreCollectors.toSet; +import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH_GROUPS; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE; + +public class SearchGroupsAction implements QProfileWsAction { + + private final Languages languages; + + public SearchGroupsAction(Languages languages) { + this.languages = languages; + } + + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context + .createAction(ACTION_SEARCH_GROUPS) + .setDescription("List the groups that are allowed to edit a Quality Profile.<br>" + + "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.") + .setHandler(this) + .setInternal(true) + .addSelectionModeParam() + .addSearchQuery("sonar", "group names") + .addPagingParams(25) + .setResponseExample(getClass().getResource("search_groups-example.json")) + .setSince("6.6"); + + action.createParam(PARAM_QUALITY_PROFILE) + .setDescription("Quality Profile name") + .setRequired(true) + .setExampleValue("Recommended quality profile"); + + action + .createParam(PARAM_LANGUAGE) + .setDescription("Quality profile language") + .setRequired(true) + .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(toSet())); + + createOrganizationParam(action); + } + + @Override + public void handle(Request request, Response response) throws Exception { + IOUtils.write(IOUtils.toString(getClass().getResource("search_groups-example.json")), response.stream().output()); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java new file mode 100644 index 00000000000..4accbeb4091 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java @@ -0,0 +1,76 @@ +/* + * 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.sonar.server.qualityprofile.ws; + +import java.util.Arrays; +import org.apache.commons.io.IOUtils; +import org.sonar.api.resources.Language; +import org.sonar.api.resources.Languages; +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; + +import static org.sonar.core.util.stream.MoreCollectors.toSet; +import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH_USERS; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE; + +public class SearchUsersAction implements QProfileWsAction { + + private final Languages languages; + + public SearchUsersAction(Languages languages) { + this.languages = languages; + } + + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context + .createAction(ACTION_SEARCH_USERS) + .setDescription("List the users that are allowed to edit a Quality Profile.<br>" + + "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.") + .setHandler(this) + .setInternal(true) + .addSearchQuery("freddy", "names", "logins") + .addSelectionModeParam() + .addPagingParams(25) + .setResponseExample(getClass().getResource("search_users-example.json")) + .setSince("6.6"); + + action.createParam(PARAM_QUALITY_PROFILE) + .setDescription("Quality Profile name") + .setRequired(true) + .setExampleValue("Recommended quality profile"); + + action + .createParam(PARAM_LANGUAGE) + .setDescription("Quality profile language") + .setRequired(true) + .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(toSet())); + + createOrganizationParam(action); + } + + @Override + public void handle(Request request, Response response) throws Exception { + IOUtils.write(IOUtils.toString(getClass().getResource("search_users-example.json")), response.stream().output()); + } +} diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search-example.json index 07ff1f2b8aa..70698410621 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search-example.json @@ -11,7 +11,12 @@ "activeDeprecatedRuleCount": 0, "isDefault": true, "ruleUpdatedAt": "2016-12-22T19:10:03+0100", - "lastUsed": "2016-12-01T19:10:03+0100" + "lastUsed": "2016-12-01T19:10:03+0100", + "actions": { + "edit": true, + "setAsDefault": false, + "copy": false + } }, { "key": "AU-TpxcA-iU5OvuD2FL1", @@ -28,7 +33,12 @@ "projectCount": 7, "ruleUpdatedAt": "2016-12-20T19:10:03+0100", "lastUsed": "2016-12-21T16:10:03+0100", - "userUpdatedAt": "2016-06-28T21:57:01+0200" + "userUpdatedAt": "2016-06-28T21:57:01+0200", + "actions": { + "edit": true, + "setAsDefault": false, + "copy": false + } }, { "key": "iU5OvuD2FLz", @@ -41,7 +51,12 @@ "activeRuleCount": 9, "activeDeprecatedRuleCount": 2, "ruleUpdatedAt": "2016-12-22T19:10:03+0100", - "userUpdatedAt": "2016-06-29T21:57:01+0200" + "userUpdatedAt": "2016-06-29T21:57:01+0200", + "actions": { + "edit": true, + "setAsDefault": false, + "copy": false + } }, { "key": "AU-TpxcB-iU5OvuD2FL7", @@ -53,7 +68,15 @@ "activeRuleCount": 2, "activeDeprecatedRuleCount": 0, "isDefault": true, - "ruleUpdatedAt": "2014-12-22T19:10:03+0100" + "ruleUpdatedAt": "2014-12-22T19:10:03+0100", + "actions": { + "edit": true, + "setAsDefault": false, + "copy": false + } } - ] + ], + "actions": { + "create": true + } } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_groups-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_groups-example.json new file mode 100644 index 00000000000..084dfd4bb4e --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_groups-example.json @@ -0,0 +1,19 @@ +{ + "groups": [ + { + "name": "users", + "description": "Users", + "selected": true + }, + { + "name": "administrators", + "description": "Administrators", + "selected": false + } + ], + "paging": { + "pageSize": 100, + "total": 2, + "pageIndex": 1 + } +} diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_users-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_users-example.json new file mode 100644 index 00000000000..2eb7a636830 --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_users-example.json @@ -0,0 +1,19 @@ +{ + "users": [ + { + "login": "admin", + "name": "Administrator", + "selected": true + }, + { + "login": "george.orwell", + "name": "George Orwell", + "selected": false + } + ], + "paging": { + "pageSize": 100, + "total": 2, + "pageIndex": 1 + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java index 1764e6cafcc..d16a500bae3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java @@ -29,6 +29,6 @@ public class QProfilesWsModuleTest { public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new QProfilesWsModule().configure(container); - assertThat(container.size()).isEqualTo(27 + 2); + assertThat(container.size()).isEqualTo(33 + 2); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchGroupsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchGroupsActionTest.java new file mode 100644 index 00000000000..fa2dfe68bc7 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchGroupsActionTest.java @@ -0,0 +1,60 @@ +/* + * 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.sonar.server.qualityprofile.ws; + +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.resources.Languages; +import org.sonar.api.server.ws.WebService; +import org.sonar.server.language.LanguageTesting; +import org.sonar.server.tester.UserSessionRule; +import org.sonar.server.ws.WsActionTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.test.JsonAssert.assertJson; +import static org.sonarqube.ws.MediaTypes.JSON; + +public class SearchGroupsActionTest { + + private static final String XOO = "xoo"; + private static final Languages LANGUAGES = LanguageTesting.newLanguages(XOO); + + @Rule + public UserSessionRule userSession = UserSessionRule.standalone(); + + private WsActionTester ws = new WsActionTester(new SearchGroupsAction(LANGUAGES)); + + @Test + public void test_definition() { + WebService.Action def = ws.getDef(); + assertThat(def.key()).isEqualTo("search_groups"); + assertThat(def.isPost()).isFalse(); + assertThat(def.isInternal()).isTrue(); + assertThat(def.params()).extracting(WebService.Param::key) + .containsExactlyInAnyOrder("organization", "qualityProfile", "language", "selected", "q", "p", "ps"); + } + + @Test + public void test_example() { + String result = ws.newRequest().setMediaType(JSON).execute().getInput(); + + assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(result); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchUsersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchUsersActionTest.java new file mode 100644 index 00000000000..7b28d74bdf6 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchUsersActionTest.java @@ -0,0 +1,60 @@ +/* + * 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.sonar.server.qualityprofile.ws; + +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.resources.Languages; +import org.sonar.api.server.ws.WebService; +import org.sonar.server.language.LanguageTesting; +import org.sonar.server.tester.UserSessionRule; +import org.sonar.server.ws.WsActionTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.test.JsonAssert.assertJson; +import static org.sonarqube.ws.MediaTypes.JSON; + +public class SearchUsersActionTest { + + private static final String XOO = "xoo"; + private static final Languages LANGUAGES = LanguageTesting.newLanguages(XOO); + + @Rule + public UserSessionRule userSession = UserSessionRule.standalone(); + + private WsActionTester ws = new WsActionTester(new SearchUsersAction(LANGUAGES)); + + @Test + public void test_definition() { + WebService.Action def = ws.getDef(); + assertThat(def.key()).isEqualTo("search_users"); + assertThat(def.isPost()).isFalse(); + assertThat(def.isInternal()).isTrue(); + assertThat(def.params()).extracting(WebService.Param::key) + .containsExactlyInAnyOrder("organization", "qualityProfile", "language", "selected", "q", "p", "ps"); + } + + @Test + public void test_example() { + String result = ws.newRequest().setMediaType(JSON).execute().getInput(); + + assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(result); + } +} |