import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.ServerException;
-import org.sonar.server.ws.WsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
-import static org.sonar.server.permission.ws.AddGroupAction.ACTION;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION_KEY;
expectedException.expect(ServerException.class);
- wsTester.newGetRequest(CONTROLLER, ACTION)
+ newRequest()
+ .setMethod("GET")
.setParam(PARAM_GROUP_NAME, "sonar-administrators")
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.execute();
assertThat(db.users().selectGroupPermissions(group, project)).containsOnly(ISSUE_ADMIN);
}
+
@Test
public void set_root_flag_to_true_on_all_users_in_group_when_admin_permission_to_group_of_default_organization_without_org_param() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization());
.execute();
}
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, ACTION);
- }
}
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.ServerException;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
-import static org.sonar.server.permission.ws.AddUserAction.ACTION;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION_KEY;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
@Test
public void add_permission_to_user() throws Exception {
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.execute();
ComponentDto project = db.components().insertProject();
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, project.uuid())
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
ComponentDto project = db.components().insertProject();
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_KEY, project.getKey())
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
ComponentDto view = db.components().insertComponent(newView("view-uuid").setKey("view-key"));
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, view.uuid())
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
expectedException.expect(NotFoundException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, "unknown-project-uuid")
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
expectedException.expect(BadRequestException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, UserRole.ISSUE_ADMIN)
.execute();
expectedException.expect(BadRequestException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, "file-uuid")
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
expectedException.expect(ServerException.class);
- wsTester.newGetRequest(CONTROLLER, ACTION)
+ newRequest()
+ .setMethod("GET")
.setParam(PARAM_USER_LOGIN, "george.orwell")
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.execute();
expectedException.expect(IllegalArgumentException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.execute();
}
expectedException.expect(NotFoundException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, "jrr.tolkien")
.execute();
}
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Project id or project key can be provided, not both.");
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, "project-uuid")
expectedException.expect(ForbiddenException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.execute();
expectedException.expect(ForbiddenException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.setParam(PARAM_PROJECT_KEY, project.getKey())
userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_KEY, project.getKey())
.setParam(PARAM_PERMISSION, UserRole.ISSUE_ADMIN)
}
private void executeRequest(UserDto userDto, String permission, @Nullable OrganizationDto organizationDto) throws Exception {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, ACTION)
+ TestRequest request = newRequest()
.setParam(PARAM_USER_LOGIN, userDto.getLogin())
.setParam(PARAM_PERMISSION, permission);
if (organizationDto != null) {
import org.sonar.server.permission.index.PermissionIndexer;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.usergroups.ws.GroupWsSupport;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.WsActionTester;
import static org.mockito.Mockito.mock;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
protected UserSessionRule userSession = UserSessionRule.standalone();
- protected WsTester wsTester;
+ protected WsActionTester wsTester;
@Before
public void initWsTester() {
- wsTester = new WsTester(new PermissionsWs(buildWsAction()));
+ wsTester = new WsActionTester(buildWsAction());
}
protected abstract A buildWsAction();
new GroupPermissionChanger(db.getDbClient(), defaultOrganizationProvider));
}
+ protected TestRequest newRequest() {
+ return wsTester.newRequest().setMethod("POST");
+ }
+
protected PermissionTemplateDto insertTemplate() {
PermissionTemplateDto dto = PermissionTemplateTesting.newPermissionTemplateDto()
.setOrganizationUuid(db.getDefaultOrganization().getUuid());
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.ws.WsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.server.ws.WebService.Param.PAGE;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
+import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
@Test
public void search_for_groups_with_one_permission() throws Exception {
loginAsAdminOnDefaultOrganization();
- newRequest()
+
+ String json = newRequest()
.setParam(PARAM_PERMISSION, SCAN_EXECUTION)
.execute()
- .assertJson("{\n" +
+ .getInput();
+ assertJson(json).isSimilarTo("{\n" +
" \"paging\": {\n" +
" \"pageIndex\": 1,\n" +
" \"pageSize\": 20,\n" +
String result = newRequest()
.setParam(PARAM_PERMISSION, SCAN_EXECUTION)
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).containsSequence(DefaultGroups.ANYONE, "group-1", "group-2");
}
.setParam(PAGE_SIZE, "1")
.setParam(PAGE, "3")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains("group-2")
.doesNotContain("group-1")
.setParam(PARAM_PERMISSION, SCAN_EXECUTION)
.setParam(TEXT_QUERY, "group-")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result)
.contains("group-1", "group-2")
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_ID, "project-uuid")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains(group.getName())
.doesNotContain(anotherGroup.getName())
.setParam(PARAM_PROJECT_ID, "project-uuid")
.setParam(TEXT_QUERY, "group-with")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains(group.getName())
.doesNotContain(groupWithoutPermission.getName())
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_ID, project.uuid())
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains(group.getName())
.doesNotContain(groupWithoutPermission.getName());
.setParam(PARAM_PROJECT_ID, project.uuid())
.setParam(TEXT_QUERY, "nyo")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains("Anyone");
}
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_ID, "view-uuid")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains("project-group-name")
.doesNotContain("group-1")
.execute();
}
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, "groups");
- }
}
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.exceptions.ServerException;
-import org.sonar.server.ws.WsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
-import static org.sonar.server.permission.ws.RemoveGroupAction.ACTION;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION_KEY;
.execute();
}
- @Test
- public void fail_when_get_request() throws Exception {
- loginAsAdminOnDefaultOrganization();
-
- expectedException.expect(ServerException.class);
- expectedException.expectMessage("HTTP method POST is required");
-
- wsTester.newGetRequest(CONTROLLER, ACTION)
- .setParam(PARAM_GROUP_NAME, aGroup.getName())
- .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
- .execute();
- }
-
@Test
public void fail_when_group_name_is_missing() throws Exception {
loginAsAdminOnDefaultOrganization();
assertThat(db.users().selectGroupPermissions(aGroup, project)).containsOnly(CODEVIEWER);
}
-
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, ACTION);
- }
}
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
-import static org.sonar.server.permission.ws.RemoveUserAction.ACTION;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION_KEY;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
db.users().insertPermissionOnUser(user, QUALITY_GATE_ADMIN);
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, QUALITY_GATE_ADMIN)
.execute();
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Last user with permission 'admin'. Permission cannot be removed.");
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, ADMIN)
.execute();
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, project.uuid())
.setParam(PARAM_PERMISSION, CODEVIEWER)
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project);
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_KEY, project.getKey())
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, view);
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_KEY, view.getKey())
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
expectedException.expect(NotFoundException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, "unknown-project-uuid")
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
expectedException.expect(BadRequestException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.execute();
expectedException.expect(BadRequestException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, "file-uuid")
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
expectedException.expect(ServerException.class);
- wsTester.newGetRequest(CONTROLLER, ACTION)
+ newRequest()
+ .setMethod("GET")
.setParam(PARAM_USER_LOGIN, "george.orwell")
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.execute();
expectedException.expect(IllegalArgumentException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.execute();
}
expectedException.expect(IllegalArgumentException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.execute();
}
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Project id or project key can be provided, not both.");
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, project.uuid())
}
private void executeRequest(UserDto userDto, OrganizationDto organizationDto, String permission) throws Exception {
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, userDto.getLogin())
.setParam(PARAM_PERMISSION, permission)
.setParam(PARAM_ORGANIZATION_KEY, organizationDto.getKey())
}
private void executeRequest(UserDto userDto, String permission) throws Exception {
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, userDto.getLogin())
.setParam(PARAM_PERMISSION, permission)
.execute();
expectedException.expect(ForbiddenException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, PROVISIONING)
.execute();
expectedException.expect(ForbiddenException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_KEY, project.key())
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PROJECT_ID, project.uuid())
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
-import static org.sonar.server.permission.ws.SearchGlobalPermissionsAction.ACTION;
import static org.sonar.test.JsonAssert.assertJson;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
public class SearchGlobalPermissionsActionTest extends BasePermissionWsTest<SearchGlobalPermissionsAction> {
// to be excluded, permission on another organization (the default one)
db.users().insertPermissionOnUser(db.getDefaultOrganization(), adminUser, QUALITY_GATE_ADMIN);
- String result = wsTester.newPostRequest(CONTROLLER, ACTION)
+ String result = newRequest()
.setParam("organization", org.getKey())
.execute()
- .outputAsString();
+ .getInput();
assertJson(result).isSimilarTo(getClass().getResource("search_global_permissions-example.json"));
}
db.users().insertPermissionOnUser(org, user, QUALITY_GATE_ADMIN);
WsPermissions.WsSearchGlobalPermissionsResponse result = WsPermissions.WsSearchGlobalPermissionsResponse.parseFrom(
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setMediaType(MediaTypes.PROTOBUF)
.execute()
- .output());
+ .getInputStream());
assertThat(result.getPermissionsCount()).isEqualTo(GlobalPermissions.ALL.size());
for (WsPermissions.Permission permission : result.getPermissionsList()) {
loginAsAdminOnDefaultOrganization();
WsPermissions.WsSearchGlobalPermissionsResponse result = WsPermissions.WsSearchGlobalPermissionsResponse.parseFrom(
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setMediaType(MediaTypes.PROTOBUF)
.execute()
- .output());
+ .getInputStream());
assertThat(result).isNotNull();
}
expectedException.expect(ForbiddenException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.execute();
}
expectedException.expect(ForbiddenException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam("organization", org.getKey())
.execute();
}
expectedException.expect(UnauthorizedException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION).execute();
+ newRequest().execute();
}
@Test
public void fail_if_organization_does_not_exist() throws Exception {
expectedException.expect(NotFoundException.class);
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam("organization", "does_not_exist")
.execute();
}
*/
package org.sonar.server.permission.ws;
+import java.io.InputStream;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.resources.Qualifiers;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.i18n.I18nRule;
-import org.sonar.server.ws.WsTester;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.WsPermissions;
import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonar.db.user.GroupTesting.newGroupDto;
import static org.sonar.test.JsonAssert.assertJson;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER;
db.commit();
- String result = newRequest().execute().outputAsString();
+ String result = newRequest().execute().getInput();
assertJson(result)
.ignoreFields("permissions")
@Test
public void empty_result() throws Exception {
- String result = newRequest().execute().outputAsString();
+ String result = newRequest().execute().getInput();
assertJson(result)
.ignoreFields("permissions")
String result = newRequest()
.setParam(PARAM_PROJECT_ID, "project-uuid")
- .execute().outputAsString();
+ .execute().getInput();
assertThat(result).contains("project-uuid");
}
String result = newRequest()
.setParam(PAGE, "1")
.setParam(PAGE_SIZE, "3")
- .execute().outputAsString();
+ .execute().getInput();
assertThat(result)
.contains("project-name-1", "project-name-2", "project-name-3")
String result = newRequest()
.setParam(TEXT_QUERY, "project")
- .execute().outputAsString();
+ .execute().getInput();
assertThat(result).contains("project-name")
.doesNotContain("another-name");
String result = newRequest()
.setParam(TEXT_QUERY, "project-key")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains("project-key")
.doesNotContain("another-key");
.setParam(TEXT_QUERY, "project")
.setParam(PAGE_SIZE, "1001")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains("project-uuid-1", "project-uuid-999", "project-uuid-1001");
}
db.components().insertComponent(newDeveloper("developer-name"));
db.components().insertComponent(newProjectDto("project-uuid"));
- byte[] wsResponse = newRequest()
+ InputStream wsResponse = newRequest()
.setMediaType(MediaTypes.PROTOBUF)
.setParam(PARAM_QUALIFIER, Qualifiers.PROJECT)
.execute()
- .output();
+ .getInputStream();
WsPermissions.SearchProjectPermissionsWsResponse result = WsPermissions.SearchProjectPermissionsWsResponse.parseFrom(wsResponse);
assertThat(result.getProjectsList())
@Test
public void display_all_project_permissions() throws Exception {
- String result = newRequest().execute().outputAsString();
+ String result = newRequest().execute().getInput();
assertJson(result)
.ignoreFields("permissions")
.setKey("net.java.openjdk:jdk7")
.setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a"));
}
-
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, "search_project_permissions");
- }
}
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.ws.WsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.user.UserTesting.newUserDto;
import static org.sonar.test.JsonAssert.assertJson;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
db.users().insertPermissionOnUser(user2, SCAN_EXECUTION);
loginAsAdminOnDefaultOrganization();
- String result = newRequest().execute().outputAsString();
+ String result = newRequest().execute().getInput();
assertJson(result).withStrictArrayOrder().isSimilarTo(getClass().getResource("users-example.json"));
}
insertUsersHavingGlobalPermissions();
loginAsAdminOnDefaultOrganization();
- String result = newRequest().setParam("permission", "scan").execute().outputAsString();
+ String result = newRequest().setParam("permission", "scan").execute().getInput();
assertJson(result).withStrictArrayOrder().isSimilarTo(getClass().getResource("UsersActionTest/users.json"));
}
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_ID, project.uuid())
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains(user.getLogin())
.doesNotContain(userHavePermissionOnAnotherProject.getLogin())
String result = newRequest()
.setParam(PARAM_PROJECT_ID, project.uuid())
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains(user.getLogin())
.doesNotContain(withoutPermission.getLogin());
.setParam(PARAM_PROJECT_ID, project.uuid())
.setParam(TEXT_QUERY, "with")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result)
.contains(user.getLogin())
.setParam("permission", "scan")
.setParam(TEXT_QUERY, "ame-1")
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains("login-1")
.doesNotContain("login-2")
loginAsAdminOnDefaultOrganization();
String result = newRequest()
.execute()
- .outputAsString();
+ .getInput();
assertThat(result).contains("login-1", "login-2", "login-3");
}
db.users().insertPermissionOnUser(user3, SYSTEM_ADMIN);
}
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, "users");
- }
}
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.security.DefaultGroups.ANYONE;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
}
private void newRequest(@Nullable String groupName, @Nullable String templateKey, @Nullable String permission) throws Exception {
- WsTester.TestRequest request = newRequest();
+ TestRequest request = newRequest();
if (groupName != null) {
request.setParam(PARAM_GROUP_NAME, groupName);
}
return db.getDbClient().permissionTemplateDao()
.selectGroupNamesByQueryAndTemplate(db.getSession(), query, templateId);
}
-
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, "add_group_to_template");
- }
}
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.sonar.core.permission.GlobalPermissions.QUALITY_GATE_ADMIN;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
assertThat(templatePermission.get().getWithProjectCreator()).isTrue();
}
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, "add_project_creator_to_template");
- }
-
private PermissionTemplateCharacteristicDto reload(PermissionTemplateCharacteristicDto characteristic) {
return db.getDbClient().permissionTemplateCharacteristicDao().selectByPermissionAndTemplateId(db.getSession(), characteristic.getPermission(), characteristic.getTemplateId()).get();
}
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
import static org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_USER_LOGIN;
public class AddUserToTemplateActionTest extends BasePermissionWsTest<AddUserToTemplateAction> {
- private static final String ACTION = "add_user_to_template";
-
private UserDto user;
private PermissionTemplateDto permissionTemplate;
public void add_user_to_template_by_name() throws Exception {
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, CODEVIEWER)
.setParam(PARAM_TEMPLATE_NAME, permissionTemplate.getName().toUpperCase())
}
private void newRequest(@Nullable String userLogin, @Nullable String templateKey, @Nullable String permission) throws Exception {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, ACTION);
+ TestRequest request = newRequest();
if (userLogin != null) {
request.setParam(PARAM_USER_LOGIN, userLogin);
}
import org.sonar.server.permission.index.PermissionIndexer;
import org.sonar.server.permission.index.PermissionIndexerTester;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.TestResponse;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
@Rule
public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()), new ProjectMeasuresIndexDefinition(new MapSettings()));
- private static final String ACTION = "apply_template";
-
private UserDto user1;
private UserDto user2;
private GroupDto group1;
public void apply_template_with_project_uuid_by_template_name() throws Exception {
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_TEMPLATE_NAME, template1.getName().toUpperCase())
.setParam(PARAM_PROJECT_ID, project.uuid())
.execute();
authorizationIndexerTester.verifyProjectExistsWithPermission(project.uuid(), singletonList(group2.getName()), Collections.emptyList());
}
- private WsTester.Result newRequest(@Nullable String templateUuid, @Nullable String projectUuid, @Nullable String projectKey) throws Exception {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, ACTION);
+ private TestResponse newRequest(@Nullable String templateUuid, @Nullable String projectUuid, @Nullable String projectKey) throws Exception {
+ TestRequest request = newRequest();
if (templateUuid != null) {
request.setParam(PARAM_TEMPLATE_ID, templateUuid);
}
import org.sonar.server.permission.PermissionService;
import org.sonar.server.permission.index.PermissionIndexer;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.sonar.db.component.ComponentTesting.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyTemplateAction> {
- private static final String ACTION = "bulk_apply_template";
-
private UserDto user1;
private UserDto user2;
private GroupDto group1;
PermissionQuery query = PermissionQuery.builder().setPermission(permission).setComponentUuid(project.uuid()).build();
return db.getDbClient().userPermissionDao().selectUserIds(db.getSession(), db.getDefaultOrganization().getUuid(), query);
}
-
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, ACTION);
- }
}
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.TestResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN;
import static org.sonar.test.JsonAssert.assertJson;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_DESCRIPTION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY_PATTERN;
public void create_full_permission_template() throws Exception {
loginAsAdminOnDefaultOrganization();
- WsTester.Result result = newRequest("Finance", "Permissions for financially related projects", ".*\\.finance\\..*");
+ TestResponse result = newRequest("Finance", "Permissions for financially related projects", ".*\\.finance\\..*");
- assertJson(result.outputAsString())
+ assertJson(result.getInput())
.ignoreFields("id")
.isSimilarTo(getClass().getResource("create_template-example.json"));
PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
newRequest("Finance", null, null);
}
- private WsTester.Result newRequest(@Nullable String name, @Nullable String description, @Nullable String projectPattern) throws Exception {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, "create_template");
+ private TestResponse newRequest(@Nullable String name, @Nullable String description, @Nullable String projectPattern) throws Exception {
+ TestRequest request = newRequest();
if (name != null) {
request.setParam(PARAM_NAME, name);
}
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.TestResponse;
import static com.google.common.primitives.Longs.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.internal.util.collections.Sets.newSet;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
public class DeleteTemplateActionTest extends BasePermissionWsTest<DeleteTemplateAction> {
- private static final String ACTION = "delete_template";
-
private DefaultPermissionTemplateFinder defaultTemplatePermissionFinder = mock(DefaultPermissionTemplateFinder.class);
private PermissionTemplateDto template;
@Test
public void delete_template_in_db() throws Exception {
- WsTester.Result result = newRequest(template.getUuid());
+ TestResponse result = newRequest(template.getUuid());
- assertThat(result.outputAsString()).isEmpty();
+ assertThat(result.getInput()).isEmpty();
assertThat(db.getDbClient().permissionTemplateDao().selectByUuid(db.getSession(), template.getUuid())).isNull();
}
@Test
public void delete_template_by_name_case_insensitive() throws Exception {
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_TEMPLATE_NAME, template.getName().toUpperCase())
.execute();
return dto;
}
- private WsTester.Result newRequest(@Nullable String id) throws Exception {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, ACTION);
+ private TestResponse newRequest(@Nullable String id) throws Exception {
+ TestRequest request = newRequest();
if (id != null) {
request.setParam(PARAM_TEMPLATE_ID, id);
}
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.security.DefaultGroups.ANYONE;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<RemoveGroupFromTemplateAction> {
- private static final String ACTION = "remove_group_from_template";
private static final String PERMISSION = CODEVIEWER;
private GroupDto group;
@Test
public void remove_group_from_template_by_name_case_insensitive() throws Exception {
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
.setParam(PARAM_PERMISSION, PERMISSION)
.setParam(PARAM_TEMPLATE_NAME, template.getName().toUpperCase())
@Test
public void remove_group_with_group_id() throws Exception {
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_TEMPLATE_ID, template.getUuid())
.setParam(PARAM_PERMISSION, PERMISSION)
.setParam(PARAM_GROUP_ID, String.valueOf(group.getId()))
}
private void newRequest(@Nullable String groupName, @Nullable String templateKey, @Nullable String permission) throws Exception {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, ACTION);
+ TestRequest request = newRequest();
if (groupName != null) {
request.setParam(PARAM_GROUP_NAME, groupName);
}
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
public class RemoveProjectCreatorFromTemplateActionTest extends BasePermissionWsTest<RemoveProjectCreatorFromTemplateAction> {
- private static final String ACTION = "remove_project_creator_from_template";
-
private System2 system = mock(System2.class);
private PermissionTemplateDto template;
assertThat(templatePermission).isNotPresent();
}
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, ACTION);
- }
-
private PermissionTemplateCharacteristicDto reload(PermissionTemplateCharacteristicDto characteristic) {
return db.getDbClient().permissionTemplateCharacteristicDao().selectByPermissionAndTemplateId(db.getSession(), characteristic.getPermission(), characteristic.getTemplateId())
.get();
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.web.UserRole.CODEVIEWER;
import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_USER_LOGIN;
public class RemoveUserFromTemplateActionTest extends BasePermissionWsTest<RemoveUserFromTemplateAction> {
private static final String DEFAULT_PERMISSION = CODEVIEWER;
- private static final String ACTION = "remove_user_from_template";
private UserDto user;
private PermissionTemplateDto template;
@Test
public void remove_user_from_template_by_name_case_insensitive() throws Exception {
loginAsAdminOnDefaultOrganization();
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
.setParam(PARAM_PERMISSION, DEFAULT_PERMISSION)
.setParam(PARAM_TEMPLATE_NAME, template.getName().toUpperCase())
}
private void newRequest(@Nullable String userLogin, @Nullable String templateKey, @Nullable String permission) throws Exception {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, ACTION);
+ TestRequest request = newRequest();
if (userLogin != null) {
request.setParam(PARAM_USER_LOGIN, userLogin);
}
import org.sonar.server.permission.ws.BasePermissionWsTest;
import org.sonar.server.platform.PersistentSettings;
import org.sonar.server.platform.SettingsChangeNotifier;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY;
import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_QUALIFIER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
public class SetDefaultTemplateActionTest extends BasePermissionWsTest<SetDefaultTemplateAction> {
- private static final String ACTION = "set_default_template";
-
private I18nRule i18n = new I18nRule();
private PersistentSettings persistentSettings = new PersistentSettings(new MapSettings(), db.getDbClient(), new SettingsChangeNotifier());
private PermissionTemplateDto template;
@Test
public void update_settings_for_project_qualifier_by_template_name() throws Exception {
- wsTester.newPostRequest(CONTROLLER, ACTION)
+ newRequest()
.setParam(PARAM_TEMPLATE_NAME, template.getName().toUpperCase())
.execute();
db.getSession().commit();
}
private String newRequest(@Nullable String templateUuid, @Nullable String qualifier) throws Exception {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, ACTION);
+ TestRequest request = newRequest();
if (templateUuid != null) {
request.setParam(PARAM_TEMPLATE_ID, templateUuid);
}
request.setParam(PARAM_QUALIFIER, qualifier);
}
- return request.execute().outputAsString();
+ return request.execute().getInput();
}
}
*/
package org.sonar.server.permission.ws.template;
+import java.io.InputStream;
import javax.annotation.Nullable;
import org.junit.Test;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
import org.sonarqube.ws.WsPermissions.WsGroupsResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.user.GroupTesting.newGroupDto;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.MediaTypes.PROTOBUF;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
String response = newRequest()
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_TEMPLATE_ID, template.getUuid())
- .execute().outputAsString();
+ .execute()
+ .getInput();
assertJson(response)
.ignoreFields("id")
commit();
loginAsAdminOnDefaultOrganization();
- byte[] output = newRequest()
+ InputStream output = newRequest()
.setMediaType(PROTOBUF)
.setParam(PARAM_TEMPLATE_ID, template.getUuid())
.execute()
- .output();
+ .getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "group-1-name", "group-2-name");
commit();
loginAsAdminOnDefaultOrganization();
- byte[] output = newRequest()
+ InputStream output = newRequest()
.setMediaType(PROTOBUF)
.setParam(PARAM_PERMISSION, USER)
.setParam(PARAM_TEMPLATE_ID, template.getUuid())
.execute()
- .output();
+ .getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "group-1-name");
commit();
loginAsAdminOnDefaultOrganization();
- byte[] output = newRequest()
+ InputStream output = newRequest()
.setMediaType(PROTOBUF)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.execute()
- .output();
+ .getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "group-1-name", "group-2-name");
commit();
loginAsAdminOnDefaultOrganization();
- byte[] output = newRequest()
+ InputStream output = newRequest()
.setMediaType(PROTOBUF)
.setParam(PARAM_PERMISSION, USER)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setParam(PAGE, "2")
.setParam(PAGE_SIZE, "1")
.execute()
- .output();
+ .getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("group-2-name");
commit();
loginAsAdminOnDefaultOrganization();
- byte[] output = newRequest()
+ InputStream output = newRequest()
.setMediaType(PROTOBUF)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setParam(TEXT_QUERY, "-nam")
.execute()
- .output();
+ .getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("group-1-name", "group-2-name");
commit();
loginAsAdminOnDefaultOrganization();
- byte[] output = newRequest()
+ InputStream output = newRequest()
.setMediaType(PROTOBUF)
.setParam(PARAM_TEMPLATE_ID, template.getUuid())
.setParam(TEXT_QUERY, "-name")
.execute()
- .output();
+ .getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("group-1-name", "group-2-name", "group-3-name");
commit();
loginAsAdminOnDefaultOrganization();
- byte[] output = newRequest()
+ InputStream output = newRequest()
.setMediaType(PROTOBUF)
.setParam(PARAM_TEMPLATE_ID, template.getUuid())
.setParam(TEXT_QUERY, "nyo")
.execute()
- .output();
+ .getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone");
private void commit() {
db.commit();
}
-
- private WsTester.TestRequest newRequest() {
- return wsTester.newPostRequest(CONTROLLER, "template_groups");
- }
}
*/
package org.sonar.server.permission.ws.template;
+import java.io.InputStream;
import javax.annotation.Nullable;
import org.junit.Test;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
import org.sonarqube.ws.WsPermissions;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.user.UserTesting.newUserDto;
import static org.sonar.test.JsonAssert.assertJson;
import static org.sonarqube.ws.MediaTypes.PROTOBUF;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
addUserToTemplate(newPermissionTemplateUser(ADMIN, template1, user2));
loginAsAdminOnDefaultOrganization();
- String result = newRequest(null, template1.getUuid()).execute().outputAsString();
+ String result = newRequest(null, template1.getUuid()).execute().getInput();
assertJson(result).isSimilarTo(getClass().getResource("template_users-example.json"));
}
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
- byte[] bytes = newRequest(null, null)
+ InputStream bytes = newRequest(null, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setMediaType(PROTOBUF)
- .execute().output();
+ .execute().getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).extracting("login").containsExactly("login-1", "login-2", "login-3");
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
- byte[] bytes = newRequest(null, null)
+ InputStream bytes = newRequest(null, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setParam(WebService.Param.TEXT_QUERY, "ame-1")
.setMediaType(PROTOBUF)
- .execute().output();
+ .execute().getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).extracting("login").containsOnly("login-1");
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
loginAsAdminOnDefaultOrganization();
- byte[] bytes = newRequest(USER, template.getUuid())
+ InputStream bytes = newRequest(USER, template.getUuid())
.setMediaType(PROTOBUF)
- .execute().output();
+ .execute().getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).extracting("login").containsExactly("login-1", "login-2");
assertThat(response.getUsers(0).getPermissionsList()).containsOnly("issueadmin", "user");
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
loginAsAdminOnDefaultOrganization();
- byte[] bytes = newRequest(USER, null)
+ InputStream bytes = newRequest(USER, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setParam(WebService.Param.SELECTED, "all")
.setParam(WebService.Param.PAGE, "2")
.setParam(WebService.Param.PAGE_SIZE, "1")
.setMediaType(PROTOBUF)
- .execute().output();
+ .execute().getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).extracting("login").containsOnly("login-2");
addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
loginAsAdminOnDefaultOrganization();
- byte[] bytes = newRequest(null, null)
+ InputStream bytes = newRequest(null, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setMediaType(PROTOBUF)
- .execute().output();
+ .execute().getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).extracting("login").containsExactly("login-1", "login-2", "login-3");
addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user));
loginAsAdminOnDefaultOrganization();
- byte[] bytes = newRequest(null, null)
+ InputStream bytes = newRequest(null, null)
.setParam(PARAM_TEMPLATE_NAME, template.getName())
.setMediaType(PROTOBUF)
.execute()
- .output();
+ .getInputStream();
WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
assertThat(response.getUsersList()).isEmpty();
.setUserId(user.getId());
}
- private WsTester.TestRequest newRequest(@Nullable String permission, @Nullable String templateUuid) {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, "template_users");
+ private TestRequest newRequest(@Nullable String permission, @Nullable String templateUuid) {
+ TestRequest request = newRequest();
if (permission != null) {
request.setParam(PARAM_PERMISSION, permission);
}
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.permission.ws.BasePermissionWsTest;
-import org.sonar.server.ws.WsTester;
+import org.sonar.server.ws.TestRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.spy;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto;
import static org.sonar.test.JsonAssert.assertJson;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_DESCRIPTION;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_NAME;
public class UpdateTemplateActionTest extends BasePermissionWsTest<UpdateTemplateAction> {
- private static final String ACTION = "update_template";
-
private System2 system = spy(System2.INSTANCE);
private PermissionTemplateDto template;
}
private String call(@Nullable String key, @Nullable String name, @Nullable String description, @Nullable String projectPattern) throws Exception {
- WsTester.TestRequest request = wsTester.newPostRequest(CONTROLLER, ACTION);
+ TestRequest request = newRequest();
if (key != null) {
request.setParam(PARAM_ID, key);
}
request.setParam(PARAM_PROJECT_KEY_PATTERN, projectPattern);
}
- return request.execute().outputAsString();
+ return request.execute().getInput();
}
}