From d1ef0c0544f74baeb796715da2326178accfadd9 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 16 Jul 2014 09:05:16 +0200 Subject: [PATCH] Fix UT on MySQL 5.6 --- .../core/permission/PermissionFacadeTest.java | 12 ++++++-- .../DefaultResourcePermissionsTest.java | 30 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java b/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java index e76001acafc..9b1596d7d55 100644 --- a/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java +++ b/sonar-core/src/test/java/org/sonar/core/permission/PermissionFacadeTest.java @@ -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 diff --git a/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java b/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java index e24d07ba7ef..eb0cb230752 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java @@ -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 -- 2.39.5