]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8134 replace WsTester by WsActionTester
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 19 Oct 2016 14:55:09 +0000 (16:55 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 21 Oct 2016 13:58:39 +0000 (15:58 +0200)
in tests of permissions web services

23 files changed:
server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/BasePermissionWsTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchGlobalPermissionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddProjectCreatorToTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/AddUserToTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/CreateTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/DeleteTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveProjectCreatorFromTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SetDefaultTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/TemplateGroupsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/TemplateUsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/UpdateTemplateActionTest.java

index 4c8948cb13033baf82b06db0d66d5db9a82f3582..7f1dbc05fe8cf46563e31e6fb589e80f1c04fce6 100644 (file)
@@ -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<AddGroupAction> {
 
     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<AddGroupAction> {
     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<AddGroupAction> {
       .execute();
   }
 
-  private WsTester.TestRequest newRequest() {
-    return wsTester.newPostRequest(CONTROLLER, ACTION);
-  }
 }
index de022b8efee0e71a2367bb8662112bd8b71a5b5d..4a135b3b6f96218d5694ec277c8e9aa95c4c8698 100644 (file)
@@ -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<AddUserAction> {
   @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<AddUserAction> {
     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<AddUserAction> {
     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<AddUserAction> {
     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<AddUserAction> {
 
     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<AddUserAction> {
 
     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<AddUserAction> {
 
     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<AddUserAction> {
 
     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<AddUserAction> {
 
     expectedException.expect(IllegalArgumentException.class);
 
-    wsTester.newPostRequest(CONTROLLER, ACTION)
+    newRequest()
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
   }
@@ -184,7 +183,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> {
 
     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<AddUserAction> {
     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<AddUserAction> {
 
     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<AddUserAction> {
 
     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<AddUserAction> {
 
     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<AddUserAction> {
   }
 
   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) {
index 93fb1a0d09c82efb90a09d022e771b9227ee5133..89b839e86eb8dcd477e3f80e5bf1e75f3d35353e 100644 (file)
@@ -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<A extends PermissionsWsAction> {
 
   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<A extends PermissionsWsAction> {
       new GroupPermissionChanger(db.getDbClient(), defaultOrganizationProvider));
   }
 
+  protected TestRequest newRequest() {
+    return wsTester.newRequest().setMethod("POST");
+  }
+
   protected PermissionTemplateDto insertTemplate() {
     PermissionTemplateDto dto = PermissionTemplateTesting.newPermissionTemplateDto()
       .setOrganizationUuid(db.getDefaultOrganization().getUuid());
index aa03a2523c212292f7668324263edca0afa9d828..e177e22bbf66323ab470265e643513495b27225f 100644 (file)
@@ -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<GroupsAction> {
   @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<GroupsAction> {
     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<GroupsAction> {
       .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<GroupsAction> {
       .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<GroupsAction> {
       .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<GroupsAction> {
       .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<GroupsAction> {
       .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<GroupsAction> {
       .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<GroupsAction> {
       .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<GroupsAction> {
       .execute();
   }
 
-  private WsTester.TestRequest newRequest() {
-    return wsTester.newPostRequest(CONTROLLER, "groups");
-  }
 }
index bd4b7f6f1cb4d6db1a0f76d3267750234e459c04..a4de755e2292ae011f75b3491b104c5822e43b8c 100644 (file)
@@ -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<RemoveGroupActio
       .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();
@@ -373,8 +356,4 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio
 
     assertThat(db.users().selectGroupPermissions(aGroup, project)).containsOnly(CODEVIEWER);
   }
-
-  private WsTester.TestRequest newRequest() {
-    return wsTester.newPostRequest(CONTROLLER, ACTION);
-  }
 }
index feffda0235753d7988a6a1b43bdf8e80adcabf29..d3a4729f7a3f2fc84854514f1f92eecdf0d4139b 100644 (file)
@@ -40,8 +40,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.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;
@@ -72,7 +70,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction>
     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<RemoveUserAction>
     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<RemoveUserAction>
     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<RemoveUserAction>
     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<RemoveUserAction>
     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<RemoveUserAction>
 
     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<RemoveUserAction>
 
     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<RemoveUserAction>
 
     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<RemoveUserAction>
 
     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<RemoveUserAction>
 
     expectedException.expect(IllegalArgumentException.class);
 
-    wsTester.newPostRequest(CONTROLLER, ACTION)
+    newRequest()
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
   }
@@ -211,7 +210,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction>
 
     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<RemoveUserAction>
     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<RemoveUserAction>
   }
 
   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<RemoveUserAction>
   }
 
   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<RemoveUserAction>
 
     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<RemoveUserAction>
 
     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<RemoveUserAction>
     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)
index 4195cd40b22048872ef1459d21bad3ba311c9acc..38cf43d2a996a87fd6bcd24c75c0b380662e48b4 100644 (file)
@@ -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<SearchGlobalPermissionsAction> {
 
@@ -80,10 +78,10 @@ public class SearchGlobalPermissionsActionTest extends BasePermissionWsTest<Sear
     // 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"));
   }
@@ -100,10 +98,10 @@ public class SearchGlobalPermissionsActionTest extends BasePermissionWsTest<Sear
     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()) {
@@ -120,10 +118,10 @@ public class SearchGlobalPermissionsActionTest extends BasePermissionWsTest<Sear
     loginAsAdminOnDefaultOrganization();
 
     WsPermissions.WsSearchGlobalPermissionsResponse result = WsPermissions.WsSearchGlobalPermissionsResponse.parseFrom(
-      wsTester.newPostRequest(CONTROLLER, ACTION)
+      newRequest()
         .setMediaType(MediaTypes.PROTOBUF)
         .execute()
-        .output());
+        .getInputStream());
 
     assertThat(result).isNotNull();
   }
@@ -134,7 +132,7 @@ public class SearchGlobalPermissionsActionTest extends BasePermissionWsTest<Sear
 
     expectedException.expect(ForbiddenException.class);
 
-    wsTester.newPostRequest(CONTROLLER, ACTION)
+    newRequest()
       .execute();
   }
 
@@ -145,7 +143,7 @@ public class SearchGlobalPermissionsActionTest extends BasePermissionWsTest<Sear
 
     expectedException.expect(ForbiddenException.class);
 
-    wsTester.newPostRequest(CONTROLLER, ACTION)
+    newRequest()
       .setParam("organization", org.getKey())
       .execute();
   }
@@ -156,14 +154,14 @@ public class SearchGlobalPermissionsActionTest extends BasePermissionWsTest<Sear
 
     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();
   }
index 1fd0bd1649181e8dbf25834e4d0fb9fe6febd2c6..ad533b6b1e197054de7ae1eeebf5a54e2404a08e 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.permission.ws;
 
+import java.io.InputStream;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.resources.Qualifiers;
@@ -32,7 +33,6 @@ import org.sonar.db.user.UserDto;
 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;
 
@@ -46,7 +46,6 @@ import static org.sonar.db.component.ComponentTesting.newProjectDto;
 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;
 
@@ -105,7 +104,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
 
     db.commit();
 
-    String result = newRequest().execute().outputAsString();
+    String result = newRequest().execute().getInput();
 
     assertJson(result)
       .ignoreFields("permissions")
@@ -114,7 +113,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
 
   @Test
   public void empty_result() throws Exception {
-    String result = newRequest().execute().outputAsString();
+    String result = newRequest().execute().getInput();
 
     assertJson(result)
       .ignoreFields("permissions")
@@ -128,7 +127,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
 
     String result = newRequest()
       .setParam(PARAM_PROJECT_ID, "project-uuid")
-      .execute().outputAsString();
+      .execute().getInput();
 
     assertThat(result).contains("project-uuid");
   }
@@ -143,7 +142,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
     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")
@@ -158,7 +157,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
 
     String result = newRequest()
       .setParam(TEXT_QUERY, "project")
-      .execute().outputAsString();
+      .execute().getInput();
 
     assertThat(result).contains("project-name")
       .doesNotContain("another-name");
@@ -173,7 +172,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
     String result = newRequest()
       .setParam(TEXT_QUERY, "project-key")
       .execute()
-      .outputAsString();
+      .getInput();
 
     assertThat(result).contains("project-key")
       .doesNotContain("another-key");
@@ -190,7 +189,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
       .setParam(TEXT_QUERY, "project")
       .setParam(PAGE_SIZE, "1001")
       .execute()
-      .outputAsString();
+      .getInput();
 
     assertThat(result).contains("project-uuid-1", "project-uuid-999", "project-uuid-1001");
   }
@@ -201,11 +200,11 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
     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())
@@ -235,7 +234,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
 
   @Test
   public void display_all_project_permissions() throws Exception {
-    String result = newRequest().execute().outputAsString();
+    String result = newRequest().execute().getInput();
 
     assertJson(result)
       .ignoreFields("permissions")
@@ -272,8 +271,4 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
       .setKey("net.java.openjdk:jdk7")
       .setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a"));
   }
-
-  private WsTester.TestRequest newRequest() {
-    return wsTester.newPostRequest(CONTROLLER, "search_project_permissions");
-  }
 }
index 09b0b820b02d7dcd8da13e39bfbd12983929b2ed..d56c85dfbb03b07ca5a718875d1560738da72c62 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.db.user.UserDto;
 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;
@@ -40,7 +39,6 @@ import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
 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;
@@ -62,7 +60,7 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> {
     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<UsersAction> {
     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<UsersAction> {
       .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<UsersAction> {
     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<UsersAction> {
       .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<UsersAction> {
       .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<UsersAction> {
     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<UsersAction> {
     db.users().insertPermissionOnUser(user3, SYSTEM_ADMIN);
   }
 
-  private WsTester.TestRequest newRequest() {
-    return wsTester.newPostRequest(CONTROLLER, "users");
-  }
 }
index c1fddb125bd60aba56f0fccf3187567824549d27..89d0d44e032f36ce93c1a66fee90e75eea3dd2a7 100644 (file)
@@ -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<AddGroupT
   }
 
   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);
     }
@@ -211,8 +210,4 @@ public class AddGroupToTemplateActionTest extends BasePermissionWsTest<AddGroupT
     return db.getDbClient().permissionTemplateDao()
       .selectGroupNamesByQueryAndTemplate(db.getSession(), query, templateId);
   }
-
-  private WsTester.TestRequest newRequest() {
-    return wsTester.newPostRequest(CONTROLLER, "add_group_to_template");
-  }
 }
index fde918805377b3c6a645d958274086f82783760a..1ab91d2574598b62c24fa4f1810b0b9719728584 100644 (file)
@@ -29,13 +29,11 @@ import org.sonar.db.permission.template.PermissionTemplateDto;
 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;
@@ -136,10 +134,6 @@ public class AddProjectCreatorToTemplateActionTest extends BasePermissionWsTest<
     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();
   }
index 1da75fdb76415ec5dd21b03dd5df1a209d8fd621..6a8c318fc6e342384885fe2f3e879ff004f85d17 100644 (file)
@@ -31,21 +31,18 @@ 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.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;
 
@@ -73,7 +70,7 @@ public class AddUserToTemplateActionTest extends BasePermissionWsTest<AddUserToT
   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())
@@ -158,7 +155,7 @@ public class AddUserToTemplateActionTest extends BasePermissionWsTest<AddUserToT
   }
 
   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);
     }
index 8996862c876aecf40e7a8daed1835cb79c2a6407..a9d8adf9e6003137acd731bb579cef41c3505ca3 100644 (file)
@@ -46,13 +46,13 @@ import org.sonar.server.permission.PermissionService;
 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;
@@ -63,8 +63,6 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA
   @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;
@@ -126,7 +124,7 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA
   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();
@@ -212,8 +210,8 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA
     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);
     }
index ddcbfd09582eda8a729fe79854c3abddb84e1fdc..58e3809573ff5b78e0481048046687718e7a8534 100644 (file)
@@ -39,22 +39,18 @@ import org.sonar.server.i18n.I18nRule;
 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;
@@ -215,8 +211,4 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
     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);
-  }
 }
index 587e52e89e3c6b8853c88be9f9071e4fada5ea7b..19fb9e752fcc3e38dadef20ccf4e4345268889b7 100644 (file)
@@ -27,12 +27,12 @@ import org.sonar.db.permission.template.PermissionTemplateDto;
 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;
@@ -51,9 +51,9 @@ public class CreateTemplateActionTest extends BasePermissionWsTest<CreateTemplat
   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");
@@ -129,8 +129,8 @@ public class CreateTemplateActionTest extends BasePermissionWsTest<CreateTemplat
     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);
     }
index c2bbaeed651ae969764867fdae788a73197b9f7b..7b13da6be193b2492b412ae46021f391403885c6 100644 (file)
@@ -37,21 +37,19 @@ 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 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;
 
@@ -69,15 +67,15 @@ public class DeleteTemplateActionTest extends BasePermissionWsTest<DeleteTemplat
 
   @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();
 
@@ -149,8 +147,8 @@ public class DeleteTemplateActionTest extends BasePermissionWsTest<DeleteTemplat
     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);
     }
index d91e39d21614771d49cb1cabc5cd446d360adfc1..d1c018216b1d40e8ab5dec46d49b743c4af1c2ad 100644 (file)
@@ -32,13 +32,12 @@ 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.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;
@@ -47,7 +46,6 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_T
 
 public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<RemoveGroupFromTemplateAction> {
 
-  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<Remo
 
   @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())
@@ -87,7 +85,7 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<Remo
 
   @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()))
@@ -175,7 +173,7 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<Remo
   }
 
   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);
     }
index 4d0a419e2bf6e79bc5091ec763a15ad53732a184..3b343a29bf4bc7b1c857e2b2f39fdd89c2387b88 100644 (file)
@@ -31,20 +31,16 @@ 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 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;
 
@@ -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();
index 84474200ad3ce35caf6abf053fc8a9e5daa764bd..2173a500b19103992185e18c3b2496ef523175fa 100644 (file)
@@ -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<RemoveUserFromTemplateAction> {
 
   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<Remov
   @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())
@@ -180,7 +178,7 @@ public class RemoveUserFromTemplateActionTest extends BasePermissionWsTest<Remov
   }
 
   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);
     }
index 1eefe8d05c1c140def8b1404b19f7d77612fbe6a..ab9919c29e0fa258dc8cd879c41e2c9cdd473ceb 100644 (file)
@@ -36,22 +36,19 @@ import org.sonar.server.i18n.I18nRule;
 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;
@@ -90,7 +87,7 @@ public class SetDefaultTemplateActionTest extends BasePermissionWsTest<SetDefaul
 
   @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();
@@ -150,7 +147,7 @@ public class SetDefaultTemplateActionTest extends BasePermissionWsTest<SetDefaul
   }
 
   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);
     }
@@ -158,6 +155,6 @@ public class SetDefaultTemplateActionTest extends BasePermissionWsTest<SetDefaul
       request.setParam(PARAM_QUALIFIER, qualifier);
     }
 
-    return request.execute().outputAsString();
+    return request.execute().getInput();
   }
 }
index 76547b1199f90710169f9a5658efb8c4be54cb51..6419daa9f3c777fa48b0bb77e1bcc84583a8cf7f 100644 (file)
@@ -19,6 +19,7 @@
  */
 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;
@@ -31,7 +32,6 @@ 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.sonarqube.ws.WsPermissions.WsGroupsResponse;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -46,7 +46,6 @@ import static org.sonar.db.permission.template.PermissionTemplateTesting.newPerm
 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;
@@ -75,7 +74,8 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     String response = newRequest()
       .setParam(PARAM_PERMISSION, ISSUE_ADMIN)
       .setParam(PARAM_TEMPLATE_ID, template.getUuid())
-      .execute().outputAsString();
+      .execute()
+      .getInput();
 
     assertJson(response)
       .ignoreFields("id")
@@ -106,11 +106,11 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     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");
@@ -140,12 +140,12 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     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");
@@ -170,11 +170,11 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     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");
@@ -191,14 +191,14 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     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");
@@ -215,12 +215,12 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     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");
@@ -236,12 +236,12 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     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");
@@ -258,12 +258,12 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
     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");
@@ -364,8 +364,4 @@ public class TemplateGroupsActionTest extends BasePermissionWsTest<TemplateGroup
   private void commit() {
     db.commit();
   }
-
-  private WsTester.TestRequest newRequest() {
-    return wsTester.newPostRequest(CONTROLLER, "template_groups");
-  }
 }
index 0f2df7b115dba9a3ec2b167714bf1058a0bcf963..ea931caf6db37ac0ec69e095387791fe21f535e0 100644 (file)
@@ -19,6 +19,7 @@
  */
 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;
@@ -31,7 +32,7 @@ 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 org.sonarqube.ws.WsPermissions;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -44,7 +45,6 @@ import static org.sonar.db.permission.template.PermissionTemplateTesting.newPerm
 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;
@@ -67,7 +67,7 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     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"));
   }
 
@@ -88,10 +88,10 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     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");
@@ -117,11 +117,11 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     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");
@@ -143,9 +143,9 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     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");
@@ -168,13 +168,13 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     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");
@@ -192,10 +192,10 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     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");
@@ -209,11 +209,11 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     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();
@@ -298,8 +298,8 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
       .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);
     }
index 1f05038ff996d9e55cce82c1fa6beae2ab312902..62e4b8f3bec3e35db5d4db2b48b910b6333ecc0e 100644 (file)
@@ -30,7 +30,7 @@ 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.mockito.Mockito.spy;
@@ -38,7 +38,6 @@ import static org.mockito.Mockito.when;
 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;
@@ -46,8 +45,6 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_P
 
 public class UpdateTemplateActionTest extends BasePermissionWsTest<UpdateTemplateAction> {
 
-  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<UpdateTemplat
   }
 
   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);
     }
@@ -215,6 +212,6 @@ public class UpdateTemplateActionTest extends BasePermissionWsTest<UpdateTemplat
       request.setParam(PARAM_PROJECT_KEY_PATTERN, projectPattern);
     }
 
-    return request.execute().outputAsString();
+    return request.execute().getInput();
   }
 }