]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7747 IT to add and remove a project template creator
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 16 Jun 2016 13:25:52 +0000 (15:25 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 17 Jun 2016 13:38:49 +0000 (15:38 +0200)
it/it-tests/src/test/java/it/authorisation/PermissionSearchTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsService.java
sonar-ws/src/test/java/org/sonarqube/ws/client/permission/PermissionsServiceTest.java

index 06728cb237bc0c9e564ab5b25b3ec5cb0a985ee1..0d7508a3ee1683836c01a8faa87b76f4a7a47033 100644 (file)
@@ -35,12 +35,14 @@ import org.sonarqube.ws.client.PostRequest;
 import org.sonarqube.ws.client.WsClient;
 import org.sonarqube.ws.client.permission.AddGroupToTemplateWsRequest;
 import org.sonarqube.ws.client.permission.AddGroupWsRequest;
+import org.sonarqube.ws.client.permission.AddProjectCreatorToTemplateWsRequest;
 import org.sonarqube.ws.client.permission.AddUserToTemplateWsRequest;
 import org.sonarqube.ws.client.permission.AddUserWsRequest;
 import org.sonarqube.ws.client.permission.CreateTemplateWsRequest;
 import org.sonarqube.ws.client.permission.GroupsWsRequest;
 import org.sonarqube.ws.client.permission.PermissionsService;
 import org.sonarqube.ws.client.permission.RemoveGroupFromTemplateWsRequest;
+import org.sonarqube.ws.client.permission.RemoveProjectCreatorFromTemplateWsRequest;
 import org.sonarqube.ws.client.permission.RemoveUserFromTemplateWsRequest;
 import org.sonarqube.ws.client.permission.SearchTemplatesWsRequest;
 import org.sonarqube.ws.client.permission.UsersWsRequest;
@@ -134,6 +136,12 @@ public class PermissionSearchTest {
         .setTemplateName("my-new-template")
         .setGroupName(GROUP_NAME));
 
+    permissionsWsClient.addProjectCreatorToTemplate(
+      AddProjectCreatorToTemplateWsRequest.builder()
+        .setPermission("admin")
+        .setTemplateName("my-new-template")
+        .build());
+
     SearchTemplatesWsResponse searchTemplatesWsResponse = permissionsWsClient.searchTemplates(
       new SearchTemplatesWsRequest()
         .setQuery("my-new-template"));
@@ -141,6 +149,7 @@ public class PermissionSearchTest {
     assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getKey()).isEqualTo("admin");
     assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getUsersCount()).isEqualTo(1);
     assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getGroupsCount()).isEqualTo(1);
+    assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getWithProjectCreator()).isTrue();
 
     permissionsWsClient.removeGroupFromTemplate(
       new RemoveGroupFromTemplateWsRequest()
@@ -154,13 +163,20 @@ public class PermissionSearchTest {
         .setTemplateName("my-new-template")
         .setLogin(LOGIN));
 
+    permissionsWsClient.removeProjectCreatorFromTemplate(
+      RemoveProjectCreatorFromTemplateWsRequest.builder()
+        .setPermission("admin")
+        .setTemplateName("my-new-template")
+      .build()
+    );
+
     SearchTemplatesWsResponse clearedSearchTemplatesWsResponse = permissionsWsClient.searchTemplates(
       new SearchTemplatesWsRequest()
         .setQuery("my-new-template"));
     assertThat(clearedSearchTemplatesWsResponse.getPermissionTemplates(0).getPermissionsList())
-      .extracting(Permission::getUsersCount, Permission::getGroupsCount)
+      .extracting(Permission::getUsersCount, Permission::getGroupsCount, Permission::getWithProjectCreator)
       .hasSize(5)
-      .containsOnly(tuple(0, 0));
+      .containsOnly(tuple(0, 0, false));
   }
 
   private static void createUser(String login, String name) {
index 694f100d1f1385036133260c75621a0224a5e4b2..b39aca3bfc81e4435ad7dde10874029b2aacacf8 100644 (file)
@@ -152,6 +152,14 @@ public class PermissionsService extends BaseService {
       .setParam(PARAM_TEMPLATE_NAME, request.getTemplateName()));
   }
 
+  public void removeProjectCreatorFromTemplate(RemoveProjectCreatorFromTemplateWsRequest request) {
+    call(
+      new PostRequest(path("remove_project_creator_from_template"))
+        .setParam(PARAM_PERMISSION, request.getPermission())
+        .setParam(PARAM_TEMPLATE_ID, request.getTemplateId())
+        .setParam(PARAM_TEMPLATE_NAME, request.getTemplateName()));
+  }
+
   public void removeUser(RemoveUserWsRequest request) {
     call(new PostRequest(path("remove_user"))
       .setParam(PARAM_PERMISSION, request.getPermission())
index e18ff730830dfb9efd4bbdea0097103e342dfabf..f82ae59934b1c1af1b7b0ac6cd4ecb1789183a2c 100644 (file)
@@ -472,4 +472,22 @@ public class PermissionsServiceTest {
       .hasParam(PARAM_TEMPLATE_NAME, TEMPLATE_NAME_VALUE)
       .andNoOtherParam();
   }
+
+  @Test
+  public void remove_project_creator_from_template() {
+    underTest.removeProjectCreatorFromTemplate(RemoveProjectCreatorFromTemplateWsRequest.builder()
+      .setPermission(PERMISSION_VALUE)
+      .setTemplateId(TEMPLATE_ID_VALUE)
+      .setTemplateName(TEMPLATE_NAME_VALUE)
+      .build());
+
+    assertThat(serviceTester.getPostParser()).isNull();
+    PostRequest getRequest = serviceTester.getPostRequest();
+    serviceTester.assertThat(getRequest)
+      .hasPath("remove_project_creator_from_template")
+      .hasParam(PARAM_PERMISSION, PERMISSION_VALUE)
+      .hasParam(PARAM_TEMPLATE_ID, TEMPLATE_ID_VALUE)
+      .hasParam(PARAM_TEMPLATE_NAME, TEMPLATE_NAME_VALUE)
+      .andNoOtherParam();
+  }
 }