diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-01-25 16:27:18 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-01-27 16:55:16 +0100 |
commit | a50808c9a385d75daaeae79168b37c15194b2617 (patch) | |
tree | d3f36a015f98816aa490724c84ee5a4f796b2c84 /sonar-db/src/test/java/org | |
parent | c04694a7b2db32cdf9cc8aaf872bc90ffbf9c95d (diff) | |
download | sonarqube-a50808c9a385d75daaeae79168b37c15194b2617.tar.gz sonarqube-a50808c9a385d75daaeae79168b37c15194b2617.zip |
SONAR-8690 read and write default templates from ORGANIZATIONS table
Diffstat (limited to 'sonar-db/src/test/java/org')
4 files changed, 45 insertions, 14 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/organization/DefaultTemplatesTest.java b/sonar-db/src/test/java/org/sonar/db/organization/DefaultTemplatesTest.java index bc1edd302be..51ed0bdf6ef 100644 --- a/sonar-db/src/test/java/org/sonar/db/organization/DefaultTemplatesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/organization/DefaultTemplatesTest.java @@ -34,22 +34,30 @@ public class DefaultTemplatesTest { @Test public void setProject_throws_NPE_if_argument_is_null() { expectedException.expect(NullPointerException.class); - expectedException.expectMessage("project default template can't be null"); + expectedException.expectMessage("defaultTemplates.project can't be null"); - underTest.setProject(null); + underTest.setProjectUuid(null); + } + + @Test + public void getProject_throws_NPE_if_project_is_null() { + expectedException.expect(NullPointerException.class); + expectedException.expectMessage("defaultTemplates.project can't be null"); + + underTest.getProjectUuid(); } @Test public void setView_accepts_null() { - underTest.setView(null); + underTest.setViewUuid(null); } @Test public void check_toString() { - assertThat(underTest.toString()).isEqualTo("DefaultTemplates{project='null', view='null'}"); + assertThat(underTest.toString()).isEqualTo("DefaultTemplates{projectUuid='null', viewUuid='null'}"); underTest - .setProject("a project") - .setView("a view"); - assertThat(underTest.toString()).isEqualTo("DefaultTemplates{project='a project', view='a view'}"); + .setProjectUuid("a project") + .setViewUuid("a view"); + assertThat(underTest.toString()).isEqualTo("DefaultTemplates{projectUuid='a project', viewUuid='a view'}"); } } diff --git a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java index b4b3f2c9ae5..7f4d8b79fc0 100644 --- a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java @@ -460,7 +460,7 @@ public class OrganizationDaoTest { @Test public void getDefaultTemplates_returns_data_when_project_default_templates_column_is_not_null() { insertOrganization(ORGANIZATION_DTO_1); - underTest.setDefaultTemplates(dbSession, ORGANIZATION_DTO_1.getUuid(), new DefaultTemplates().setProject("foo")); + underTest.setDefaultTemplates(dbSession, ORGANIZATION_DTO_1.getUuid(), new DefaultTemplates().setProjectUuid("foo")); verifyGetDefaultTemplates(ORGANIZATION_DTO_1, "foo", null); } @@ -492,7 +492,7 @@ public class OrganizationDaoTest { @Test public void getDefaultTemplates_is_case_sensitive() { insertOrganization(ORGANIZATION_DTO_1); - underTest.setDefaultTemplates(dbSession, ORGANIZATION_DTO_1.getUuid(), new DefaultTemplates().setProject("foo").setView("bar")); + underTest.setDefaultTemplates(dbSession, ORGANIZATION_DTO_1.getUuid(), new DefaultTemplates().setProjectUuid("foo").setViewUuid("bar")); assertThat(underTest.getDefaultTemplates(dbSession, ORGANIZATION_DTO_1.getUuid().toUpperCase(Locale.ENGLISH))) .isEmpty(); @@ -503,7 +503,7 @@ public class OrganizationDaoTest { expectedException.expect(NullPointerException.class); expectedException.expectMessage("uuid can't be null"); - underTest.setDefaultTemplates(dbSession, null, new DefaultTemplates().setProject("p")); + underTest.setDefaultTemplates(dbSession, null, new DefaultTemplates().setProjectUuid("p")); } @Test @@ -527,7 +527,7 @@ public class OrganizationDaoTest { expectedException.expect(NullPointerException.class); expectedException.expectMessage("defaultTemplates.project can't be null"); - underTest.setDefaultTemplates(dbSession, "uuid", new DefaultTemplates().setView("foo")); + underTest.setDefaultTemplates(dbSession, "uuid", new DefaultTemplates().setViewUuid("foo")); } @Test @@ -731,7 +731,7 @@ public class OrganizationDaoTest { } private void setDefaultTemplate(OrganizationDto organizationDto1, @Nullable String project, @Nullable String view) { - underTest.setDefaultTemplates(dbSession, organizationDto1.getUuid(), new DefaultTemplates().setProject(project).setView(view)); + underTest.setDefaultTemplates(dbSession, organizationDto1.getUuid(), new DefaultTemplates().setProjectUuid(project).setViewUuid(view)); dbSession.commit(); } @@ -792,7 +792,7 @@ public class OrganizationDaoTest { Optional<DefaultTemplates> optional = underTest.getDefaultTemplates(dbSession, organizationDto.getUuid()); assertThat(optional).isNotEmpty(); DefaultTemplates defaultTemplates = optional.get(); - assertThat(defaultTemplates.getProject()).isEqualTo(expectedProject); - assertThat(defaultTemplates.getView()).isEqualTo(expectedView); + assertThat(defaultTemplates.getProjectUuid()).isEqualTo(expectedProject); + assertThat(defaultTemplates.getViewUuid()).isEqualTo(expectedView); } } diff --git a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java index f6e47333181..15f8c312626 100644 --- a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java @@ -19,6 +19,7 @@ */ package org.sonar.db.organization; +import javax.annotation.Nullable; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -53,4 +54,12 @@ public class OrganizationDbTester { dbSession.commit(); return dto; } + + public void setDefaultTemplates(OrganizationDto defaultOrganization, + String projectDefaultTemplateUuid, @Nullable String viewDefaultTemplateUuid) { + DbSession dbSession = dbTester.getSession(); + dbTester.getDbClient().organizationDao().setDefaultTemplates(dbSession, defaultOrganization.getUuid(), new DefaultTemplates().setProjectUuid(projectDefaultTemplateUuid).setViewUuid(viewDefaultTemplateUuid)); + dbSession.commit(); + } + } diff --git a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java index b2677425ef9..9f1cfb3e28c 100644 --- a/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/permission/template/PermissionTemplateDbTester.java @@ -25,6 +25,8 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.organization.OrganizationDto; +import org.sonar.db.user.GroupDto; +import org.sonar.db.user.UserDto; import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateCharacteristicDto; import static org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto; @@ -55,11 +57,23 @@ public class PermissionTemplateDbTester { return templateInDb; } + public void addGroupToTemplate(PermissionTemplateDto permissionTemplate, GroupDto group, String permission) { + addGroupToTemplate(permissionTemplate.getId(), group.getId(), permission); + } + public void addGroupToTemplate(long templateId, @Nullable Long groupId, String permission) { dbClient.permissionTemplateDao().insertGroupPermission(dbSession, templateId, groupId, permission); db.commit(); } + public void addAnyoneToTemplate(PermissionTemplateDto permissionTemplate, String permission) { + addGroupToTemplate(permissionTemplate.getId(), null, permission); + } + + public void addUserToTemplate(PermissionTemplateDto permissionTemplate, UserDto user, String permission) { + addUserToTemplate(permissionTemplate.getId(), user.getId(), permission); + } + public void addUserToTemplate(long templateId, long userId, String permission) { dbClient.permissionTemplateDao().insertUserPermission(dbSession, templateId, userId, permission); db.commit(); |