From ee433377a279245a69edc43e8ca3145de6eed7db Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 19 Oct 2016 16:55:09 +0200 Subject: [PATCH] SONAR-8134 replace WsTester by WsActionTester in tests of permissions web services --- .../permission/ws/AddGroupActionTest.java | 10 ++--- .../permission/ws/AddUserActionTest.java | 35 +++++++++-------- .../permission/ws/BasePermissionWsTest.java | 11 ++++-- .../permission/ws/GroupsActionTest.java | 28 +++++++------- .../permission/ws/RemoveGroupActionTest.java | 21 ---------- .../permission/ws/RemoveUserActionTest.java | 37 +++++++++--------- .../ws/SearchGlobalPermissionsActionTest.java | 22 +++++------ .../SearchProjectPermissionsActionTest.java | 27 ++++++------- .../server/permission/ws/UsersActionTest.java | 19 ++++------ .../AddGroupToTemplateActionTest.java | 9 +---- ...AddProjectCreatorToTemplateActionTest.java | 6 --- .../template/AddUserToTemplateActionTest.java | 9 ++--- .../ws/template/ApplyTemplateActionTest.java | 12 +++--- .../template/BulkApplyTemplateActionTest.java | 8 ---- .../ws/template/CreateTemplateActionTest.java | 12 +++--- .../ws/template/DeleteTemplateActionTest.java | 16 ++++---- .../RemoveGroupFromTemplateActionTest.java | 10 ++--- ...eProjectCreatorFromTemplateActionTest.java | 8 ---- .../RemoveUserFromTemplateActionTest.java | 8 ++-- .../SetDefaultTemplateActionTest.java | 11 ++---- .../ws/template/TemplateGroupsActionTest.java | 38 +++++++++---------- .../ws/template/TemplateUsersActionTest.java | 34 ++++++++--------- .../ws/template/UpdateTemplateActionTest.java | 9 ++--- 23 files changed, 158 insertions(+), 242 deletions(-) diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java index 4c8948cb130..7f1dbc05fe8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java @@ -30,7 +30,6 @@ 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.ISSUE_ADMIN; @@ -38,8 +37,6 @@ import static org.sonar.core.permission.GlobalPermissions.PROVISIONING; 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; @@ -191,7 +188,8 @@ public class AddGroupActionTest extends BasePermissionWsTest { expectedException.expect(ServerException.class); - wsTester.newGetRequest(CONTROLLER, ACTION) + newRequest() + .setMethod("GET") .setParam(PARAM_GROUP_NAME, "sonar-administrators") .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); @@ -312,6 +310,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { 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()); @@ -382,7 +381,4 @@ public class AddGroupActionTest extends BasePermissionWsTest { .execute(); } - private WsTester.TestRequest newRequest() { - return wsTester.newPostRequest(CONTROLLER, ACTION); - } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java index de022b8efee..4a135b3b6f9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java @@ -30,7 +30,7 @@ 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 org.sonar.server.ws.TestRequest; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.api.web.UserRole.ISSUE_ADMIN; @@ -38,8 +38,6 @@ import static org.sonar.core.permission.GlobalPermissions.SYSTEM_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; @@ -63,7 +61,7 @@ public class AddUserActionTest extends BasePermissionWsTest { @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(); @@ -76,7 +74,7 @@ public class AddUserActionTest extends BasePermissionWsTest { 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) @@ -91,7 +89,7 @@ public class AddUserActionTest extends BasePermissionWsTest { 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) @@ -106,7 +104,7 @@ public class AddUserActionTest extends BasePermissionWsTest { 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) @@ -122,7 +120,7 @@ public class AddUserActionTest extends BasePermissionWsTest { 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) @@ -135,7 +133,7 @@ public class AddUserActionTest extends BasePermissionWsTest { expectedException.expect(BadRequestException.class); - wsTester.newPostRequest(CONTROLLER, ACTION) + newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PERMISSION, UserRole.ISSUE_ADMIN) .execute(); @@ -148,7 +146,7 @@ public class AddUserActionTest extends BasePermissionWsTest { 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) @@ -161,7 +159,8 @@ public class AddUserActionTest extends BasePermissionWsTest { expectedException.expect(ServerException.class); - wsTester.newGetRequest(CONTROLLER, ACTION) + newRequest() + .setMethod("GET") .setParam(PARAM_USER_LOGIN, "george.orwell") .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); @@ -173,7 +172,7 @@ public class AddUserActionTest extends BasePermissionWsTest { expectedException.expect(IllegalArgumentException.class); - wsTester.newPostRequest(CONTROLLER, ACTION) + newRequest() .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); } @@ -184,7 +183,7 @@ public class AddUserActionTest extends BasePermissionWsTest { expectedException.expect(NotFoundException.class); - wsTester.newPostRequest(CONTROLLER, ACTION) + newRequest() .setParam(PARAM_USER_LOGIN, "jrr.tolkien") .execute(); } @@ -197,7 +196,7 @@ public class AddUserActionTest extends BasePermissionWsTest { 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") @@ -211,7 +210,7 @@ public class AddUserActionTest extends BasePermissionWsTest { expectedException.expect(ForbiddenException.class); - wsTester.newPostRequest(CONTROLLER, ACTION) + newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); @@ -224,7 +223,7 @@ public class AddUserActionTest extends BasePermissionWsTest { 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()) @@ -240,7 +239,7 @@ public class AddUserActionTest extends BasePermissionWsTest { 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) @@ -324,7 +323,7 @@ public class AddUserActionTest extends BasePermissionWsTest { } 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) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java index 93fb1a0d09c..89b839e86eb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java @@ -38,7 +38,8 @@ import org.sonar.server.permission.UserPermissionChanger; 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; @@ -53,11 +54,11 @@ public abstract class BasePermissionWsTest { 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(); @@ -82,6 +83,10 @@ public abstract class BasePermissionWsTest { new GroupPermissionChanger(db.getDbClient(), defaultOrganizationProvider)); } + protected TestRequest newRequest() { + return wsTester.newRequest().setMethod("POST"); + } + protected PermissionTemplateDto insertTemplate() { PermissionTemplateDto dto = PermissionTemplateTesting.newPermissionTemplateDto() .setOrganizationUuid(db.getDefaultOrganization().getUuid()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java index aa03a2523c2..e177e22bbf6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java @@ -28,7 +28,6 @@ import org.sonar.db.user.GroupDto; 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; @@ -40,7 +39,7 @@ import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION; 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; @@ -75,10 +74,12 @@ public class GroupsActionTest extends BasePermissionWsTest { @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" + @@ -115,7 +116,7 @@ public class GroupsActionTest extends BasePermissionWsTest { String result = newRequest() .setParam(PARAM_PERMISSION, SCAN_EXECUTION) .execute() - .outputAsString(); + .getInput(); assertThat(result).containsSequence(DefaultGroups.ANYONE, "group-1", "group-2"); } @@ -128,7 +129,7 @@ public class GroupsActionTest extends BasePermissionWsTest { .setParam(PAGE_SIZE, "1") .setParam(PAGE, "3") .execute() - .outputAsString(); + .getInput(); assertThat(result).contains("group-2") .doesNotContain("group-1") @@ -142,7 +143,7 @@ public class GroupsActionTest extends BasePermissionWsTest { .setParam(PARAM_PERMISSION, SCAN_EXECUTION) .setParam(TEXT_QUERY, "group-") .execute() - .outputAsString(); + .getInput(); assertThat(result) .contains("group-1", "group-2") @@ -166,7 +167,7 @@ public class GroupsActionTest extends BasePermissionWsTest { .setParam(PARAM_PERMISSION, ISSUE_ADMIN) .setParam(PARAM_PROJECT_ID, "project-uuid") .execute() - .outputAsString(); + .getInput(); assertThat(result).contains(group.getName()) .doesNotContain(anotherGroup.getName()) @@ -188,7 +189,7 @@ public class GroupsActionTest extends BasePermissionWsTest { .setParam(PARAM_PROJECT_ID, "project-uuid") .setParam(TEXT_QUERY, "group-with") .execute() - .outputAsString(); + .getInput(); assertThat(result).contains(group.getName()) .doesNotContain(groupWithoutPermission.getName()) @@ -208,7 +209,7 @@ public class GroupsActionTest extends BasePermissionWsTest { .setParam(PARAM_PERMISSION, ISSUE_ADMIN) .setParam(PARAM_PROJECT_ID, project.uuid()) .execute() - .outputAsString(); + .getInput(); assertThat(result).contains(group.getName()) .doesNotContain(groupWithoutPermission.getName()); @@ -225,7 +226,7 @@ public class GroupsActionTest extends BasePermissionWsTest { .setParam(PARAM_PROJECT_ID, project.uuid()) .setParam(TEXT_QUERY, "nyo") .execute() - .outputAsString(); + .getInput(); assertThat(result).contains("Anyone"); } @@ -241,7 +242,7 @@ public class GroupsActionTest extends BasePermissionWsTest { .setParam(PARAM_PERMISSION, ISSUE_ADMIN) .setParam(PARAM_PROJECT_ID, "view-uuid") .execute() - .outputAsString(); + .getInput(); assertThat(result).contains("project-group-name") .doesNotContain("group-1") @@ -283,7 +284,4 @@ public class GroupsActionTest extends BasePermissionWsTest { .execute(); } - private WsTester.TestRequest newRequest() { - return wsTester.newPostRequest(CONTROLLER, "groups"); - } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java index bd4b7f6f1cb..a4de755e229 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java @@ -29,8 +29,6 @@ import org.sonar.db.user.UserDto; 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; @@ -41,8 +39,6 @@ import static org.sonar.core.permission.GlobalPermissions.SYSTEM_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; @@ -197,19 +193,6 @@ public class RemoveGroupActionTest extends BasePermissionWsTest 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(); @@ -89,7 +87,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest 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(); @@ -102,7 +100,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest 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) @@ -118,7 +116,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest 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) @@ -134,7 +132,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest 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) @@ -149,7 +147,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest 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) @@ -162,7 +160,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest expectedException.expect(BadRequestException.class); - wsTester.newPostRequest(CONTROLLER, ACTION) + newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PERMISSION, ISSUE_ADMIN) .execute(); @@ -175,7 +173,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest 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) @@ -188,7 +186,8 @@ public class RemoveUserActionTest extends BasePermissionWsTest expectedException.expect(ServerException.class); - wsTester.newGetRequest(CONTROLLER, ACTION) + newRequest() + .setMethod("GET") .setParam(PARAM_USER_LOGIN, "george.orwell") .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); @@ -200,7 +199,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest expectedException.expect(IllegalArgumentException.class); - wsTester.newPostRequest(CONTROLLER, ACTION) + newRequest() .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); } @@ -211,7 +210,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest expectedException.expect(IllegalArgumentException.class); - wsTester.newPostRequest(CONTROLLER, ACTION) + newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) .execute(); } @@ -224,7 +223,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest 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()) @@ -273,7 +272,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest } 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()) @@ -281,7 +280,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest } 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(); @@ -293,7 +292,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest expectedException.expect(ForbiddenException.class); - wsTester.newPostRequest(CONTROLLER, ACTION) + newRequest() .setParam(PARAM_USER_LOGIN, user.getLogin()) .setParam(PARAM_PERMISSION, PROVISIONING) .execute(); @@ -306,7 +305,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest 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()) @@ -323,7 +322,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest 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) diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java index 4195cd40b22..38cf43d2a99 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java @@ -41,9 +41,7 @@ import static org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_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 { @@ -80,10 +78,10 @@ public class SearchGlobalPermissionsActionTest extends BasePermissionWsTest { 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")); } @@ -72,7 +70,7 @@ public class UsersActionTest extends BasePermissionWsTest { 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")); } @@ -97,7 +95,7 @@ public class UsersActionTest extends BasePermissionWsTest { .setParam(PARAM_PERMISSION, ISSUE_ADMIN) .setParam(PARAM_PROJECT_ID, project.uuid()) .execute() - .outputAsString(); + .getInput(); assertThat(result).contains(user.getLogin()) .doesNotContain(userHavePermissionOnAnotherProject.getLogin()) @@ -118,7 +116,7 @@ public class UsersActionTest extends BasePermissionWsTest { String result = newRequest() .setParam(PARAM_PROJECT_ID, project.uuid()) .execute() - .outputAsString(); + .getInput(); assertThat(result).contains(user.getLogin()) .doesNotContain(withoutPermission.getLogin()); @@ -140,7 +138,7 @@ public class UsersActionTest extends BasePermissionWsTest { .setParam(PARAM_PROJECT_ID, project.uuid()) .setParam(TEXT_QUERY, "with") .execute() - .outputAsString(); + .getInput(); assertThat(result) .contains(user.getLogin()) @@ -157,7 +155,7 @@ public class UsersActionTest extends BasePermissionWsTest { .setParam("permission", "scan") .setParam(TEXT_QUERY, "ame-1") .execute() - .outputAsString(); + .getInput(); assertThat(result).contains("login-1") .doesNotContain("login-2") @@ -171,7 +169,7 @@ public class UsersActionTest extends BasePermissionWsTest { loginAsAdminOnDefaultOrganization(); String result = newRequest() .execute() - .outputAsString(); + .getInput(); assertThat(result).contains("login-1", "login-2", "login-3"); } @@ -244,7 +242,4 @@ public class UsersActionTest extends BasePermissionWsTest { db.users().insertPermissionOnUser(user3, SYSTEM_ADMIN); } - private WsTester.TestRequest newRequest() { - return wsTester.newPostRequest(CONTROLLER, "users"); - } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java index c1fddb125bd..89d0d44e032 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java @@ -32,14 +32,13 @@ import org.sonar.server.exceptions.BadRequestException; 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; @@ -192,7 +191,7 @@ public class AddGroupToTemplateActionTest extends BasePermissionWsTest { - private static final String ACTION = "add_user_to_template"; - private UserDto user; private PermissionTemplateDto permissionTemplate; @@ -73,7 +70,7 @@ public class AddUserToTemplateActionTest extends BasePermissionWsTest { - private static final String ACTION = "bulk_apply_template"; - private UserDto user1; private UserDto user2; private GroupDto group1; @@ -215,8 +211,4 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest { - private static final String ACTION = "delete_template"; - private DefaultPermissionTemplateFinder defaultTemplatePermissionFinder = mock(DefaultPermissionTemplateFinder.class); private PermissionTemplateDto template; @@ -69,15 +67,15 @@ public class DeleteTemplateActionTest extends BasePermissionWsTest { - private static final String ACTION = "remove_group_from_template"; private static final String PERMISSION = CODEVIEWER; private GroupDto group; @@ -76,7 +74,7 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest { - private static final String ACTION = "remove_project_creator_from_template"; - private System2 system = mock(System2.class); private PermissionTemplateDto template; @@ -148,10 +144,6 @@ public class RemoveProjectCreatorFromTemplateActionTest extends BasePermissionWs 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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java index 84474200ad3..2173a500b19 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java @@ -32,12 +32,11 @@ import org.sonar.server.exceptions.ForbiddenException; 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; @@ -45,7 +44,6 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_U public class RemoveUserFromTemplateActionTest extends BasePermissionWsTest { private static final String DEFAULT_PERMISSION = CODEVIEWER; - private static final String ACTION = "remove_user_from_template"; private UserDto user; private PermissionTemplateDto template; @@ -73,7 +71,7 @@ public class RemoveUserFromTemplateActionTest extends BasePermissionWsTest { - 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; @@ -90,7 +87,7 @@ public class SetDefaultTemplateActionTest extends BasePermissionWsTest { - private static final String ACTION = "update_template"; - private System2 system = spy(System2.INSTANCE); private PermissionTemplateDto template; @@ -201,7 +198,7 @@ public class UpdateTemplateActionTest extends BasePermissionWsTest