]> source.dussan.org Git - sonarqube.git/commitdiff
Fix UT on MySQL 5.6
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 16 Jul 2014 07:05:16 +0000 (09:05 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 16 Jul 2014 07:15:46 +0000 (09:15 +0200)
sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java
sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java

index e76001acafc21e18846a0acc4484924847312a09..9b1596d7d55a9395dd1850e518474bc5b20e7861 100644 (file)
@@ -59,10 +59,18 @@ public class PermissionFacadeTest extends AbstractDaoTestCase {
   public void should_apply_permission_template() throws Exception {
     setupData("should_apply_permission_template");
 
+    assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", 123L)).isEmpty();
+    assertThat(permissionFacade.selectGroupPermissions("sonar-users", 123L)).isEmpty();
+    assertThat(permissionFacade.selectGroupPermissions("Anyone", 123L)).isEmpty();
+    assertThat(permissionFacade.selectUserPermissions("marius", 123L)).isEmpty();
+
     permissionFacade.applyPermissionTemplate("default_20130101_010203", 123L);
 
-    checkTable("should_apply_permission_template", "group_roles", "group_id", "resource_id", "role");
-    checkTable("should_apply_permission_template", "user_roles", "group_id", "resource_id", "role");
+    assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", 123L)).containsOnly("admin", "issueadmin");
+    assertThat(permissionFacade.selectGroupPermissions("sonar-users", 123L)).containsOnly("user", "codeviewer");
+    assertThat(permissionFacade.selectGroupPermissions("Anyone", 123L)).containsOnly("user", "codeviewer");
+
+    assertThat(permissionFacade.selectUserPermissions("marius", 123L)).containsOnly("admin");
   }
 
   @Test
index e24d07ba7ef14655ec73c018d94a05531422acb8..eb0cb230752be82f495c53a99170a45ffbbb6526 100644 (file)
@@ -38,18 +38,21 @@ import static org.fest.assertions.Assertions.assertThat;
 
 public class DefaultResourcePermissionsTest extends AbstractDaoTestCase {
 
+  private final static Long PROJECT_ID = 123L;
+
   private Resource project;
   private Settings settings;
   private DefaultResourcePermissions permissions;
+  private PermissionFacade permissionFacade;
 
   @Rule
   public ExpectedException throwable = ExpectedException.none();
 
   @Before
   public void initResourcePermissions() {
-    project = new Project("project").setId(123);
+    project = new Project("project").setId(PROJECT_ID.intValue());
     settings = new Settings();
-    PermissionFacade permissionFacade = new PermissionFacade(getMyBatis(),
+    permissionFacade = new PermissionFacade(getMyBatis(),
       new RoleDao(getMyBatis()), new UserDao(getMyBatis()), new ResourceDao(getMyBatis()), new PermissionTemplateDao(getMyBatis(), System2.INSTANCE), settings);
     permissions = new DefaultResourcePermissions(getMyBatis(), permissionFacade);
   }
@@ -112,9 +115,18 @@ public class DefaultResourcePermissionsTest extends AbstractDaoTestCase {
 
     settings.setProperty("sonar.permission.template.default", "default_template_20130101_010203");
 
+    assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", PROJECT_ID)).isEmpty();
+    assertThat(permissionFacade.selectGroupPermissions("sonar-users", PROJECT_ID)).isEmpty();
+    assertThat(permissionFacade.selectGroupPermissions("Anyone", PROJECT_ID)).isEmpty();
+    assertThat(permissionFacade.selectUserPermissions("marius", PROJECT_ID)).isEmpty();
+
     permissions.grantDefaultRoles(project);
 
-    checkTables("grantDefaultRoles", "user_roles", "group_roles");
+    assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", PROJECT_ID)).containsOnly("admin");
+    assertThat(permissionFacade.selectGroupPermissions("sonar-users", PROJECT_ID)).containsOnly("user", "codeviewer");
+    assertThat(permissionFacade.selectGroupPermissions("Anyone", PROJECT_ID)).containsOnly("user", "codeviewer");
+
+    assertThat(permissionFacade.selectUserPermissions("marius", PROJECT_ID)).isEmpty();
   }
 
   @Test
@@ -139,7 +151,6 @@ public class DefaultResourcePermissionsTest extends AbstractDaoTestCase {
       .expectMessage("The \"foo.project\" key matches multiple permission templates: \"Start with foo\", \"Start with foo again\". A system administrator must update these templates so that only one of them matches the key.");
 
     permissions.grantDefaultRoles(project);
-
   }
 
   @Test
@@ -149,9 +160,18 @@ public class DefaultResourcePermissionsTest extends AbstractDaoTestCase {
     settings.setProperty("sonar.permission.template.default", "default_20130101_010203");
     settings.setProperty("sonar.permission.template.TRK.default", "default_for_trk_20130101_010203");
 
+    assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", PROJECT_ID)).isEmpty();
+    assertThat(permissionFacade.selectGroupPermissions("sonar-users", PROJECT_ID)).isEmpty();
+    assertThat(permissionFacade.selectGroupPermissions("Anyone", PROJECT_ID)).isEmpty();
+    assertThat(permissionFacade.selectUserPermissions("marius", PROJECT_ID)).isEmpty();
+
     permissions.grantDefaultRoles(project);
 
-    checkTables("grantDefaultRolesProject", "user_roles", "group_roles");
+    assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", PROJECT_ID)).containsOnly("admin", "user", "codeviewer");
+    assertThat(permissionFacade.selectGroupPermissions("sonar-users", PROJECT_ID)).containsOnly("admin");
+    assertThat(permissionFacade.selectGroupPermissions("Anyone", PROJECT_ID)).containsOnly("codeviewer");
+
+    assertThat(permissionFacade.selectUserPermissions("marius", PROJECT_ID)).containsOnly("codeviewer");
   }
 
   @Test