]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8134 remove RoleDao#countComponentPermissions()
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 13 Oct 2016 05:41:44 +0000 (07:41 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 13 Oct 2016 10:18:42 +0000 (12:18 +0200)
replaced by GroupPermissionDao#hasRootComponentPermissions() and
 UserPermissionDao#hasRootComponentPermissions()

16 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ApplyPermissionsStep.java
sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java
sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java
sonar-db/src/main/java/org/sonar/db/permission/UserPermissionDao.java
sonar-db/src/main/java/org/sonar/db/permission/UserPermissionMapper.java
sonar-db/src/main/java/org/sonar/db/user/RoleDao.java
sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java
sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
sonar-db/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml
sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml
sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
sonar-db/src/test/java/org/sonar/db/permission/UserPermissionDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/RoleMapperTest.java [deleted file]
sonar-db/src/test/resources/org/sonar/db/user/RoleDaoTest/should_count_component_permissions.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/user/RoleMapperTest/countRoles.xml [deleted file]

index f038f98488c74c867711ff65cb9374dd0aca6a2e..f3229145c8182e3af22b6e3e169a646ef025801e 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.computation.task.projectanalysis.step;
 
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.MyBatis;
 import org.sonar.db.permission.PermissionRepository;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
@@ -48,7 +47,7 @@ public class ApplyPermissionsStep implements ComputationStep {
   private final TreeRootHolder treeRootHolder;
 
   public ApplyPermissionsStep(DbClient dbClient, DbIdsRepository dbIdsRepository, IssueAuthorizationIndexer indexer, PermissionRepository permissionRepository,
-                              TreeRootHolder treeRootHolder) {
+    TreeRootHolder treeRootHolder) {
     this.dbClient = dbClient;
     this.dbIdsRepository = dbIdsRepository;
     this.indexer = indexer;
@@ -73,19 +72,21 @@ public class ApplyPermissionsStep implements ComputationStep {
   }
 
   private void execute(Component project) {
-    DbSession session = dbClient.openSession(false);
-    try {
+    try (DbSession dbSession = dbClient.openSession(false)) {
       long projectId = dbIdsRepository.getComponentId(project);
-      if (dbClient.roleDao().countComponentPermissions(session, projectId) == 0) {
-        permissionRepository.applyDefaultPermissionTemplate(session, projectId);
-        session.commit();
+      if (hasNoPermissions(dbSession, projectId)) {
+        permissionRepository.applyDefaultPermissionTemplate(dbSession, projectId);
+        dbSession.commit();
         indexer.index();
       }
-    } finally {
-      MyBatis.closeQuietly(session);
     }
   }
 
+  private boolean hasNoPermissions(DbSession dbSession, long projectId) {
+    return !dbClient.groupPermissionDao().hasRootComponentPermissions(dbSession, projectId) &&
+      !dbClient.userPermissionDao().hasRootComponentPermissions(dbSession, projectId);
+  }
+
   @Override
   public String getDescription() {
     return "Apply permissions";
index c1685e3977654ca1475e1da21cd9bb27aa557757..53e579fa6c11bc2633de7062aeeb2f6103304dd6 100644 (file)
@@ -109,6 +109,14 @@ public class GroupPermissionDao implements Dao {
     return session.getMapper(GroupPermissionMapper.class).selectAnyonePermissions(projectId);
   }
 
+  /**
+   * @return {@code true} if the project has at least one permission defined, whatever it is
+   * on a group or on "anyone", else returns {@code false}
+   */
+  public boolean hasRootComponentPermissions(DbSession dbSession, long rootComponentId) {
+    return mapper(dbSession).countRowsByRootComponentId(rootComponentId) > 0;
+  }
+
   public void insert(DbSession dbSession, GroupPermissionDto dto) {
     mapper(dbSession).insert(dto);
   }
index 5a8138776c9efa9dca5f09043d3ec0f91aa3b29b..6c3978bc10eeb033cbaef88b652d232495a75722 100644 (file)
@@ -64,4 +64,6 @@ public interface GroupPermissionMapper {
 
   void delete(@Param("permission") String permission, @Param("organizationUuid") String organizationUuid,
     @Nullable @Param("groupId") Long groupId, @Nullable @Param("rootComponentId") Long rootComponentId);
+
+  int countRowsByRootComponentId(@Param("rootComponentId") long rootComponentId);
 }
index 16a21e2e6c0b6a4174441850df26a8d69408940d..648ea0afd32d68335eea9a93e0d25498d21527cd 100644 (file)
@@ -94,6 +94,13 @@ public class UserPermissionDao implements Dao {
     return executeLargeInputs(projectIds, mapper(dbSession)::countUsersByProjectPermission);
   }
 
+  /**
+   * @return {@code true} if the project has at least one user permission defined, else returns {@code false}
+   */
+  public boolean hasRootComponentPermissions(DbSession dbSession, long rootComponentId) {
+    return mapper(dbSession).countRowsByRootComponentId(rootComponentId) > 0;
+  }
+
   public void insert(DbSession dbSession, UserPermissionDto dto) {
     mapper(dbSession).insert(dto);
   }
index 547db6cec9e549cc2f722bdcca32e50c77e841dd..5da6ff35ff41c7e300a91e253ed06c05cf428605 100644 (file)
@@ -56,4 +56,6 @@ public interface UserPermissionMapper {
    * Delete permissions by user and/or by project. In both cases scope can be restricted to a specified permission
    */
   void delete(@Nullable @Param("login") String login, @Nullable @Param("projectUuid") String projectUuid, @Nullable @Param("permission") String permission);
+
+  int countRowsByRootComponentId(@Param("rootComponentId") long projectId);
 }
index 2eb62c0efc6b1ea9b2cef937349d30abdc3ac621..a09bba9ec3390f842031642081a829be5bf71fc4 100644 (file)
@@ -44,22 +44,11 @@ public class RoleDao implements Dao {
     return session.getMapper(RoleMapper.class).selectGroupPermissions(groupName, resourceId, DefaultGroups.isAnyone(groupName));
   }
 
-  private static int countResourceGroupRoles(DbSession session, Long resourceId) {
-    return mapper(session).countResourceGroupRoles(resourceId);
-  }
-
-  private static int countResourceUserRoles(DbSession session, long resourceId) {
-    return mapper(session).countResourceUserRoles(resourceId);
-  }
 
   public void deleteGroupRolesByGroupId(DbSession session, long groupId) {
     mapper(session).deleteGroupRolesByGroupId(groupId);
   }
 
-  public int countComponentPermissions(DbSession session, Long componentId) {
-    return countResourceGroupRoles(session, componentId) + countResourceUserRoles(session, componentId);
-  }
-
   public int countUserPermissions(DbSession session, String permission, @Nullable Long allGroupsExceptThisGroupId) {
     return mapper(session).countUsersWithPermission(permission, allGroupsExceptThisGroupId);
   }
index 23d154d5cbecae5b0d4e53a64f8451c224afbf10..eae65a9bf340e5e9659f3a58bbf3772421ab883a 100644 (file)
@@ -35,10 +35,6 @@ public interface RoleMapper {
    */
   List<String> selectGroupPermissions(@Param("groupName") String groupName, @Nullable @Param("resourceId") Long resourceId, @Param("isAnyOneGroup") Boolean isAnyOneGroup);
 
-  int countResourceGroupRoles(Long resourceId);
-
-  int countResourceUserRoles(long resourceId);
-
   void deleteGroupRolesByGroupId(long groupId);
 
   int countUsersWithPermission(@Param("permission") String permission, @Nullable @Param("groupId") Long groupId);
index dff26a62a71992a84832db19e071a04baf0289cf..e9c9bbb780e4a30c807bb8eea0d4774bf9907550 100644 (file)
     </if>
   </select>
 
+  <select id="countRowsByRootComponentId" parameterType="long" resultType="int">
+    select count(1)
+    from group_roles
+    where resource_id=#{rootComponentId,jdbcType=BIGINT}
+  </select>
+
   <insert id="insert" parameterType="GroupPermission" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     insert into group_roles (
     organization_uuid,
index b9163e08ad0b0f4004ab15a9501419600c6ce983..a134e797cb6f2f7ccb1726bde908c94615391ef7 100644 (file)
     group by ur.resource_id, ur.role
   </select>
 
+  <select id="countRowsByRootComponentId" parameterType="long" resultType="int">
+    select count(1)
+    from user_roles
+    where resource_id=#{rootComponentId,jdbcType=BIGINT}
+  </select>
+
   <insert id="insert" parameterType="org.sonar.db.permission.UserPermissionDto" useGeneratedKeys="false">
     insert into user_roles (
     organization_uuid,
index 0ac0d4355123eee6db0255989c3775f40f1a5147..766ae4a6bf7f285e5c86b713bf9ec12ce8a1984b 100644 (file)
     </where>
   </select>
 
-  <select id="countResourceUserRoles" parameterType="long" resultType="int">
-    SELECT count(1)
-    FROM user_roles WHERE resource_id=#{id}
-  </select>
-
-  <select id="countResourceGroupRoles" parameterType="long" resultType="int">
-    SELECT count(1)
-    FROM group_roles WHERE resource_id=#{id}
-  </select>
-
   <select id="countUsersWithPermission" parameterType="map" resultType="int">
     SELECT count(c.id)
     FROM (
index 014fafcbb69dec111f2fe08a8ef8c912407bc15e..453e05bce37000242711a03f0f944f5e679d3492 100644 (file)
@@ -316,6 +316,33 @@ public class GroupPermissionDaoTest {
     assertThat(underTest.selectAnyonePermissions(dbSession, UNKNOWN_PROJECT_ID)).isEmpty();
   }
 
+  @Test
+  public void projectHasPermissions_is_false_if_no_permissions_at_all() {
+    ComponentDto project1 = db.components().insertProject();
+    db.users().insertPermissionOnAnyone("perm1");
+
+    assertThat(underTest.hasRootComponentPermissions(dbSession, project1.getId())).isFalse();
+  }
+
+  @Test
+  public void projectHasPermissions_is_true_if_at_least_one_permission_on_group() {
+    GroupDto group1 = db.users().insertGroup(newGroupDto());
+    ComponentDto project1 = db.components().insertProject();
+    db.users().insertProjectPermissionOnGroup(group1, "perm1", project1);
+
+    assertThat(underTest.hasRootComponentPermissions(dbSession, project1.getId())).isTrue();
+  }
+
+  @Test
+  public void projectHasPermissions_is_true_if_at_least_one_permission_on_anyone() {
+    ComponentDto project1 = db.components().insertProject();
+    ComponentDto project2 = db.components().insertProject();
+    db.users().insertProjectPermissionOnAnyone("perm1", project1);
+
+    assertThat(underTest.hasRootComponentPermissions(dbSession, project1.getId())).isTrue();
+    assertThat(underTest.hasRootComponentPermissions(dbSession, project2.getId())).isFalse();
+  }
+
   @Test
   public void deleteByRootComponentId() {
     GroupDto group1 = db.users().insertGroup(newGroupDto());
index 6b9f7a6f7084222f5c56a6686d9ac1ac40f7f874..e056456ec4a8e4b4a7f0ef9b6a76089f49e97646 100644 (file)
@@ -28,6 +28,8 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.user.UserDto;
@@ -52,14 +54,16 @@ public class UserPermissionDaoTest {
   private UserDto user3 = newUserDto().setLogin("login3").setName("Bernard").setActive(true);
   private ComponentDto project1 = newProjectDto();
   private ComponentDto project2 = newProjectDto();
+  private DbSession dbSession = dbTester.getSession();
 
   @Before
   public void setUp() throws Exception {
-    dbTester.getDbClient().userDao().insert(dbTester.getSession(), user1);
-    dbTester.getDbClient().userDao().insert(dbTester.getSession(), user2);
-    dbTester.getDbClient().userDao().insert(dbTester.getSession(), user3);
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project1);
-    dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project2);
+    DbClient dbClient = dbTester.getDbClient();
+    dbClient.userDao().insert(dbSession, user1);
+    dbClient.userDao().insert(dbSession, user2);
+    dbClient.userDao().insert(dbSession, user3);
+    dbClient.componentDao().insert(dbSession, project1);
+    dbClient.componentDao().insert(dbSession, project2);
     dbTester.commit();
   }
 
@@ -188,7 +192,7 @@ public class UserPermissionDaoTest {
     insertProjectPermission(ISSUE_ADMIN, user2.getId(), project2.getId());
 
     // no projects -> return empty list
-    assertThat(underTest.countUsersByProjectPermission(dbTester.getSession(), Collections.emptyList())).isEmpty();
+    assertThat(underTest.countUsersByProjectPermission(dbSession, Collections.emptyList())).isEmpty();
 
     // one project
     expectCount(asList(project1.getId()),
@@ -211,12 +215,12 @@ public class UserPermissionDaoTest {
 
     // logins are ordered by user name: user2 ("Marie") then user1 ("Marius")
     PermissionQuery query = PermissionQuery.builder().setComponentUuid(project1.uuid()).withAtLeastOnePermission().build();
-    List<String> logins = underTest.selectLogins(dbTester.getSession(), query);
+    List<String> logins = underTest.selectLogins(dbSession, query);
     assertThat(logins).containsExactly(user2.getLogin(), user1.getLogin());
 
     // on a project without permissions
     query = PermissionQuery.builder().setComponentUuid("missing").withAtLeastOnePermission().build();
-    assertThat(underTest.selectLogins(dbTester.getSession(), query)).isEmpty();
+    assertThat(underTest.selectLogins(dbSession, query)).isEmpty();
   }
 
   @Test
@@ -228,18 +232,18 @@ public class UserPermissionDaoTest {
     insertProjectPermission(ISSUE_ADMIN, user2.getId(), project2.getId());
 
     // user1 has one global permission and user2 has no global permissions
-    assertThat(underTest.selectPermissionsByLogin(dbTester.getSession(), user1.getLogin(), null)).hasSize(1);
-    assertThat(underTest.selectPermissionsByLogin(dbTester.getSession(), user2.getLogin(), null)).hasSize(0);
+    assertThat(underTest.selectPermissionsByLogin(dbSession, user1.getLogin(), null)).hasSize(1);
+    assertThat(underTest.selectPermissionsByLogin(dbSession, user2.getLogin(), null)).hasSize(0);
 
     // user1 has one permission on project1, user2 has 2
-    assertThat(underTest.selectPermissionsByLogin(dbTester.getSession(), user1.getLogin(), project1.uuid())).hasSize(1);
-    assertThat(underTest.selectPermissionsByLogin(dbTester.getSession(), user2.getLogin(), project1.uuid())).hasSize(2);
+    assertThat(underTest.selectPermissionsByLogin(dbSession, user1.getLogin(), project1.uuid())).hasSize(1);
+    assertThat(underTest.selectPermissionsByLogin(dbSession, user2.getLogin(), project1.uuid())).hasSize(2);
 
     // nobody has permissions on a project that does not exist!
-    assertThat(underTest.selectPermissionsByLogin(dbTester.getSession(), user1.getLogin(), "missing")).hasSize(0);
+    assertThat(underTest.selectPermissionsByLogin(dbSession, user1.getLogin(), "missing")).hasSize(0);
 
     // users who do not exist don't have permissions!
-    assertThat(underTest.selectPermissionsByLogin(dbTester.getSession(), "missing", null)).hasSize(0);
+    assertThat(underTest.selectPermissionsByLogin(dbSession, "missing", null)).hasSize(0);
   }
 
   @Test
@@ -249,11 +253,11 @@ public class UserPermissionDaoTest {
     insertProjectPermission(ISSUE_ADMIN, user2.getId(), project1.getId());
     insertProjectPermission(ISSUE_ADMIN, user2.getId(), project2.getId());
 
-    underTest.delete(dbTester.getSession(), null, project1.uuid(), null);
+    underTest.delete(dbSession, null, project1.uuid(), null);
 
-    assertThat(dbTester.countSql(dbTester.getSession(), "select count(id) from user_roles where resource_id=" + project1.getId())).isEqualTo(0);
+    assertThat(dbTester.countSql(dbSession, "select count(id) from user_roles where resource_id=" + project1.getId())).isEqualTo(0);
     // remains global permission and project2 permission
-    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "user_roles")).isEqualTo(2);
+    assertThat(dbTester.countRowsOfTable(dbSession, "user_roles")).isEqualTo(2);
   }
 
   @Test
@@ -263,11 +267,11 @@ public class UserPermissionDaoTest {
     insertProjectPermission(ISSUE_ADMIN, user2.getId(), project1.getId());
     insertProjectPermission(ISSUE_ADMIN, user2.getId(), project2.getId());
 
-    underTest.delete(dbTester.getSession(), user1.getLogin(), null, null);
+    underTest.delete(dbSession, user1.getLogin(), null, null);
 
-    assertThat(dbTester.countSql(dbTester.getSession(), "select count(id) from user_roles where user_id=" + user1.getId())).isEqualTo(0);
+    assertThat(dbTester.countSql(dbSession, "select count(id) from user_roles where user_id=" + user1.getId())).isEqualTo(0);
     // remains user2 permissions
-    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "user_roles")).isEqualTo(2);
+    assertThat(dbTester.countRowsOfTable(dbSession, "user_roles")).isEqualTo(2);
   }
 
   @Test
@@ -277,15 +281,24 @@ public class UserPermissionDaoTest {
     insertProjectPermission(ISSUE_ADMIN, user2.getId(), project1.getId());
     insertProjectPermission(ISSUE_ADMIN, user2.getId(), project2.getId());
 
-    underTest.delete(dbTester.getSession(), user1.getLogin(), project1.uuid(), USER);
+    underTest.delete(dbSession, user1.getLogin(), project1.uuid(), USER);
 
-    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "user_roles")).isEqualTo(3);
-    assertThat(dbTester.countSql(dbTester.getSession(), "select count(id) from user_roles where user_id=" + user1.getId())).isEqualTo(1);
-    assertThat(dbTester.countSql(dbTester.getSession(), "select count(id) from user_roles where role='" + SYSTEM_ADMIN + "' and user_id=" + user1.getId())).isEqualTo(1);
+    assertThat(dbTester.countRowsOfTable(dbSession, "user_roles")).isEqualTo(3);
+    assertThat(dbTester.countSql(dbSession, "select count(id) from user_roles where user_id=" + user1.getId())).isEqualTo(1);
+    assertThat(dbTester.countSql(dbSession, "select count(id) from user_roles where role='" + SYSTEM_ADMIN + "' and user_id=" + user1.getId())).isEqualTo(1);
+  }
+
+  @Test
+  public void projectHasPermissions() {
+    insertGlobalPermission(SYSTEM_ADMIN, user1.getId());
+    insertProjectPermission(USER, user1.getId(), project1.getId());
+
+    assertThat(underTest.hasRootComponentPermissions(dbSession, project1.getId())).isTrue();
+    assertThat(underTest.hasRootComponentPermissions(dbSession, project2.getId())).isFalse();
   }
 
   private void expectCount(List<Long> projectIds, CountPerProjectPermission... expected) {
-    List<CountPerProjectPermission> got = underTest.countUsersByProjectPermission(dbTester.getSession(), projectIds);
+    List<CountPerProjectPermission> got = underTest.countUsersByProjectPermission(dbSession, projectIds);
     assertThat(got).hasSize(expected.length);
 
     for (CountPerProjectPermission expect : expected) {
@@ -298,7 +311,7 @@ public class UserPermissionDaoTest {
 
   private void expectPermissions(PermissionQuery query, @Nullable Collection<String> logins, UserPermissionDto... expected) {
     // test method "select()"
-    List<ExtendedUserPermissionDto> permissions = underTest.select(dbTester.getSession(), query, logins);
+    List<ExtendedUserPermissionDto> permissions = underTest.select(dbSession, query, logins);
     assertThat(permissions).hasSize(expected.length);
     for (int i = 0; i < expected.length; i++) {
       ExtendedUserPermissionDto got = permissions.get(i);
@@ -315,20 +328,20 @@ public class UserPermissionDaoTest {
     if (logins == null) {
       // test method "countUsers()", which does not make sense if users are filtered
       long distinctUsers = Arrays.stream(expected).mapToLong(p -> p.getUserId()).distinct().count();
-      assertThat((long) underTest.countUsers(dbTester.getSession(), query)).isEqualTo(distinctUsers);
+      assertThat((long) underTest.countUsers(dbSession, query)).isEqualTo(distinctUsers);
     }
   }
 
   private UserPermissionDto insertGlobalPermission(String permission, long userId) {
     UserPermissionDto dto = new UserPermissionDto(dbTester.getDefaultOrganization().getUuid(), permission, userId, null);
-    underTest.insert(dbTester.getSession(), dto);
+    underTest.insert(dbSession, dto);
     dbTester.commit();
     return dto;
   }
 
   private UserPermissionDto insertProjectPermission(String permission, long userId, long projectId) {
     UserPermissionDto dto = new UserPermissionDto(dbTester.getDefaultOrganization().getUuid(), permission, userId, projectId);
-    underTest.insert(dbTester.getSession(), dto);
+    underTest.insert(dbSession, dto);
     dbTester.commit();
     return dto;
   }
index 843cd398aa9c22fea05989856cf4e1bcd58a8ed3..08a880b03c6766efeeaf6e99ace8e7f161d80b9a 100644 (file)
@@ -126,13 +126,6 @@ public class RoleDaoTest {
     db.assertDbUnit(getClass(), "deleteGroupPermissionsByGroupId-result.xml", "group_roles");
   }
 
-  @Test
-  public void should_count_component_permissions() {
-    db.prepareDbUnit(getClass(), "should_count_component_permissions.xml");
-
-    assertThat(underTest.countComponentPermissions(db.getSession(), 123L)).isEqualTo(2);
-  }
-
   @Test
   public void countUserPermissions() {
     db.users().insertProjectPermissionOnUser(user1, GlobalPermissions.SYSTEM_ADMIN, project1);
diff --git a/sonar-db/src/test/java/org/sonar/db/user/RoleMapperTest.java b/sonar-db/src/test/java/org/sonar/db/user/RoleMapperTest.java
deleted file mode 100644 (file)
index 50d7555..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.db.user;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class RoleMapperTest {
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
-  @Test
-  public void count_roles() {
-    dbTester.prepareDbUnit(getClass(), "countRoles.xml");
-
-    RoleMapper mapper = dbTester.getSession().getMapper(RoleMapper.class);
-    assertThat(mapper.countResourceGroupRoles(123L)).isEqualTo(2);
-    assertThat(mapper.countResourceUserRoles(123L)).isEqualTo(1);
-  }
-
-}
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/RoleDaoTest/should_count_component_permissions.xml b/sonar-db/src/test/resources/org/sonar/db/user/RoleDaoTest/should_count_component_permissions.xml
deleted file mode 100644 (file)
index 3c91825..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<dataset>
-
-  <users id="200"
-         login="dave.loper"
-         name="Dave Loper"
-         email="dave.loper@company.net"
-         active="[true]"
-         is_root="[false]"/>
-
-  <groups id="100"
-          name="devs"
-          organization_uuid="org1"/>
-
-  <user_roles id="1"
-              user_id="200"
-              resource_id="123"
-              role="user"
-              organization_uuid="org1"/>
-
-  <group_roles id="1"
-               group_id="100"
-               resource_id="123"
-               role="codeviewer"
-               organization_uuid="org1"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/RoleMapperTest/countRoles.xml b/sonar-db/src/test/resources/org/sonar/db/user/RoleMapperTest/countRoles.xml
deleted file mode 100644 (file)
index c0e3567..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<dataset>
-  <groups id="100"
-          name="sonar-administrators"
-          organization_uuid="org1"/>
-  <groups id="101"
-          name="sonar-users"
-          organization_uuid="org1"/>
-  <users id="200"
-         login="marius"
-         name="Marius"
-         email="[null]"
-         active="[true]"
-         is_root="[false]"/>
-
-  <group_roles id="1"
-               group_id="100"
-               resource_id="123"
-               role="admin"
-               organization_uuid="org1"/>
-  <group_roles id="2"
-               group_id="[null]"
-               resource_id="123"
-               role="user"
-               organization_uuid="org1"/>
-  <user_roles id="1"
-              user_id="200"
-              resource_id="123"
-              role="codeviewer"
-              organization_uuid="org1"/>
-
-  <!-- other resource -->
-  <group_roles id="3"
-               group_id="101"
-               resource_id="999"
-               role="codeviewer"
-               organization_uuid="org1"/>
-  <user_roles id="2"
-              user_id="200"
-              resource_id="999"
-              role="codeviewer"
-              organization_uuid="org1"/>
-
-</dataset>