]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8192 add OrganizationDbTester and add it to DbTester
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 13 Oct 2016 12:52:58 +0000 (14:52 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 19 Oct 2016 12:45:13 +0000 (14:45 +0200)
15 files changed:
server/sonar-server/src/test/java/org/sonar/server/permission/GroupPermissionChangerTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java
sonar-db/src/test/java/org/sonar/db/DbTester.java
sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/organization/OrganizationTesting.java
sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java

index 8588fe97601c111801d6bbc956dac4333e805bc5..d695b207f9bccf22c856003ffd31813fe51f6dbf 100644 (file)
@@ -31,7 +31,6 @@ import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.BadRequestException;
@@ -54,7 +53,7 @@ public class GroupPermissionChangerTest {
 
   @Before
   public void setUp() throws Exception {
-    org = OrganizationTesting.insert(db, OrganizationTesting.newOrganizationDto());
+    org = db.organizations().insert();
     group = db.users().insertGroup(org, "a-group");
     project = new ComponentDbTester(db).insertComponent(ComponentTesting.newProjectDto());
   }
index cbd1c3419199c48882fe7bd23ec187b8ceda4873..70044362dc70aad0025c76286985e17d6fcf5663 100644 (file)
@@ -24,7 +24,6 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -38,7 +37,6 @@ import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.db.component.ComponentTesting.newView;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 import static org.sonar.server.permission.ws.AddGroupAction.ACTION;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.CONTROLLER;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
@@ -73,7 +71,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
 
   @Test
   public void reference_group_by_its_name_in_organization() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org, "the-group");
     loginAsAdmin(org);
 
@@ -227,8 +225,8 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
 
   @Test
   public void fail_if_administrator_of_other_organization_only() throws Exception {
-    OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
-    OrganizationDto org2 = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org1 = db.organizations().insert();
+    OrganizationDto org2 = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org1, "the-group");
     loginAsAdmin(org2);
 
index e2c13126df9fcc8df885120f9ca6b8276f3585bb..91f5b85adb8a11e4aed2c0b66231d3f9a526c6b6 100644 (file)
@@ -32,7 +32,6 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.ForbiddenException;
 
@@ -40,7 +39,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.core.permission.GlobalPermissions.QUALITY_GATE_ADMIN;
 import static org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN;
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonar.server.user.ServerUserSession.createForAnonymous;
 import static org.sonar.server.user.ServerUserSession.createForUser;
@@ -51,12 +49,16 @@ public class ServerUserSessionTest {
   private static final String PROJECT_UUID = "ABCD";
   private static final String FILE_KEY = "com.foo:Bar:BarFile.xoo";
   private static final String FILE_UUID = "BCDE";
-  private static final UserDto ROOT_USER_DTO = new UserDto() {{
-    setRoot(true);
-  }}.setLogin("root_user");
-  private static final UserDto NON_ROOT_USER_DTO = new UserDto() {{
-    setRoot(false);
-  }}.setLogin("regular_user");
+  private static final UserDto ROOT_USER_DTO = new UserDto() {
+    {
+      setRoot(true);
+    }
+  }.setLogin("root_user");
+  private static final UserDto NON_ROOT_USER_DTO = new UserDto() {
+    {
+      setRoot(false);
+    }
+  }.setLogin("regular_user");
 
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
@@ -241,8 +243,8 @@ public class ServerUserSessionTest {
   public void checkComponentPermission_fails_with_FE_when_project_of_specified_uuid_can_not_be_found() {
     ComponentDto project2 = db.components().insertComponent(ComponentTesting.newProjectDto());
     ComponentDto file2 = db.components().insertComponent(ComponentTesting.newFileDto(project2, null)
-        // Simulate file is linked to an invalid project
-        .setProjectUuid("INVALID"));
+      // Simulate file is linked to an invalid project
+      .setProjectUuid("INVALID"));
     addProjectPermissions(project, UserRole.USER);
     UserSession session = newUserSession(userDto);
 
@@ -333,7 +335,7 @@ public class ServerUserSessionTest {
 
   @Test
   public void hasOrganizationPermission_for_logged_in_user() {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     db.users().insertPermissionOnUser(org, userDto, GlobalPermissions.PROVISIONING);
 
     UserSession session = newUserSession(userDto);
@@ -344,7 +346,7 @@ public class ServerUserSessionTest {
 
   @Test
   public void hasOrganizationPermission_for_anonymous_user() {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     db.users().insertPermissionOnAnyone(org, GlobalPermissions.PROVISIONING);
 
     UserSession session = newAnonymousSession();
index afa50f26821a590b865be2c0b5b0c24062b0604f..e876e6f66bda29002000fe501ae2f16982dc6291 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -38,7 +37,6 @@ import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_NAME;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_LOGIN;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_ORGANIZATION_KEY;
@@ -92,7 +90,7 @@ public class AddUserActionTest {
 
   @Test
   public void add_user_to_group_referenced_by_its_name_and_organization() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org, "a-group");
     UserDto user = db.users().insertUser("user_login");
     loginAsAdmin(org);
@@ -201,10 +199,10 @@ public class AddUserActionTest {
 
   @Test
   public void fail_if_administrator_of_another_organization() throws Exception {
-    OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org1 = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org1, "a-group");
     UserDto user = db.users().insertUser("user_login");
-    OrganizationDto org2 = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org2 = db.organizations().insert();
     loginAsAdmin(org2);
 
     expectedException.expect(ForbiddenException.class);
@@ -216,7 +214,6 @@ public class AddUserActionTest {
       .execute();
   }
 
-
   private WsTester.TestRequest newRequest() {
     return ws.newPostRequest("api/user_groups", "add_user");
   }
index 35210d796a7af79fed17bfda84c507294b59d05b..f8c57871d6603c4345e02c6110f73aa465f25b40 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.ServerException;
@@ -38,7 +37,6 @@ import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 
 public class CreateActionTest {
 
@@ -79,7 +77,7 @@ public class CreateActionTest {
 
   @Test
   public void create_group_on_specific_organization() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     loginAsAdmin(org);
 
     newRequest()
@@ -115,8 +113,8 @@ public class CreateActionTest {
 
   @Test
   public void fail_if_administrator_of_another_organization() throws Exception {
-    OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
-    OrganizationDto org2 = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org1 = db.organizations().insert();
+    OrganizationDto org2 = db.organizations().insert();
     loginAsAdmin(org2);
 
     expectedException.expect(ForbiddenException.class);
@@ -167,7 +165,7 @@ public class CreateActionTest {
 
   @Test
   public void fail_if_group_with_same_name_already_exists_in_the_organization() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org, "the-group");
     loginAsAdmin(org);
 
@@ -183,8 +181,8 @@ public class CreateActionTest {
   @Test
   public void add_group_with_a_name_that_already_exists_in_another_organization() throws Exception {
     String name = "the-group";
-    OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
-    OrganizationDto org2 = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org1 = db.organizations().insert();
+    OrganizationDto org2 = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org1, name);
     loginAsAdmin(org2);
 
index 63cbb458d271a7b289cc59c4b19462a730253eb3..6532468cde48a13688007c2e4ee0bf9a30d87003 100644 (file)
@@ -34,7 +34,6 @@ import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateTesting;
 import org.sonar.db.user.GroupDto;
@@ -46,7 +45,6 @@ import org.sonar.server.ws.WsTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_ID;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_NAME;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_ORGANIZATION_KEY;
@@ -108,7 +106,7 @@ public class DeleteActionTest {
 
   @Test
   public void delete_by_name_and_organization() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     addAdmin(org);
     GroupDto group = db.users().insertGroup(org, "to-delete");
     loginAsAdmin(org);
@@ -124,9 +122,7 @@ public class DeleteActionTest {
 
   @Test
   public void delete_by_name_fails_if_organization_is_not_correct() throws Exception {
-    OrganizationDto org = newOrganizationDto();
-    OrganizationTesting.insert(db, org);
-
+    OrganizationDto org = db.organizations().insert();
     loginAsAdmin(org);
 
     expectedException.expect(NotFoundException.class);
@@ -215,7 +211,7 @@ public class DeleteActionTest {
 
   @Test
   public void delete_group_of_an_organization_even_if_name_is_default_group_of_default_organization() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     addAdmin(org);
     GroupDto group = db.users().insertGroup(org, defaultGroup.getName());
     loginAsAdmin(org);
@@ -245,7 +241,7 @@ public class DeleteActionTest {
   @Test
   public void delete_admin_group_fails_if_no_admin_users_left() throws Exception {
     // admin users are part of the group to be deleted
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     GroupDto adminGroup = db.users().insertGroup(org, "admins");
     db.users().insertPermissionOnGroup(adminGroup, SYSTEM_ADMIN);
     UserDto bigBoss = db.users().insertUser();
@@ -260,7 +256,7 @@ public class DeleteActionTest {
 
   @Test
   public void delete_admin_group_succeeds_if_other_groups_have_administrators() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     GroupDto adminGroup1 = db.users().insertGroup(org, "admins");
     db.users().insertPermissionOnGroup(adminGroup1, SYSTEM_ADMIN);
     GroupDto adminGroup2 = db.users().insertGroup(org, "admins");
index b2a6d1c9dfabc85c443015847230d3f2612e40e7..5ae1f3c99e2fdd042d0c4a88e5136d29bd97ebec 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.NotFoundException;
@@ -107,7 +106,7 @@ public class RemoveUserActionTest {
 
   @Test
   public void remove_user_by_group_name_in_specific_organization() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, OrganizationTesting.newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org, "a_group");
     UserDto user = db.users().insertUser("user_login");
     db.users().insertMember(group, user);
index 542a194e5a7fa8547bc4ebb950e374a61297271d..a9ee2cebed3311e342dd17e5dc013bd2ea239481 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.UnauthorizedException;
@@ -37,7 +36,6 @@ import org.sonar.server.ws.WsTester;
 
 import static org.apache.commons.lang.StringUtils.capitalize;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 
 public class SearchActionTest {
@@ -155,7 +153,7 @@ public class SearchActionTest {
 
   @Test
   public void search_in_organization() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org, "users");
     // the group in default org is not returned
     db.users().insertGroup(db.getDefaultOrganization(), "users");
index d95a846e321917aec2db1d2479ff3e5c464f9b31..34444f2ab4c0a87a2ddc170dd48f1d501bc3c8ea 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -46,7 +45,6 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 
 public class UpdateActionTest {
 
@@ -62,7 +60,8 @@ public class UpdateActionTest {
 
   private DefaultOrganizationProviderRule defaultOrganizationProvider = DefaultOrganizationProviderRule.create(db);
   private PersistentSettings settings = mock(PersistentSettings.class);
-  private WsTester ws = new WsTester(new UserGroupsWs(new UpdateAction(db.getDbClient(), userSession, new GroupWsSupport(db.getDbClient(), defaultOrganizationProvider), settings, defaultOrganizationProvider)));
+  private WsTester ws = new WsTester(
+    new UserGroupsWs(new UpdateAction(db.getDbClient(), userSession, new GroupWsSupport(db.getDbClient(), defaultOrganizationProvider), settings, defaultOrganizationProvider)));
 
   @Before
   public void setUp() throws Exception {
@@ -154,7 +153,7 @@ public class UpdateActionTest {
 
   @Test
   public void do_not_update_default_group_of_default_organization_if_updating_group_on_non_default_organization() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     when(settings.getString(DEFAULT_GROUP_NAME_KEY)).thenReturn(DEFAULT_GROUP_NAME_VALUE);
     GroupDto groupInDefaultOrg = db.users().insertGroup(defaultOrganizationProvider.getDto(), DEFAULT_GROUP_NAME_VALUE);
     GroupDto group = db.users().insertGroup(org, DEFAULT_GROUP_NAME_VALUE);
@@ -184,8 +183,8 @@ public class UpdateActionTest {
 
   @Test
   public void fails_if_admin_of_another_organization_only() throws Exception {
-    OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
-    OrganizationDto org2 = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org1 = db.organizations().insert();
+    OrganizationDto org2 = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org1, "group1");
     loginAsAdmin(org2);
 
index 0871bb192d395e4cc10a484168470a930d9068ee..86413d8483684396b8f2970f924606a572d86dbf 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -40,7 +39,6 @@ import org.sonar.server.ws.WsTester;
 import org.sonar.server.ws.WsTester.TestRequest;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_ID;
 
@@ -91,8 +89,8 @@ public class UsersActionTest {
 
   @Test
   public void fail_if_admin_of_other_organization_only() throws Exception {
-    OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
-    OrganizationDto org2 = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org1 = db.organizations().insert();
+    OrganizationDto org2 = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org1, "the-group");
     loginAsAdmin(org2);
 
@@ -132,7 +130,7 @@ public class UsersActionTest {
 
   @Test
   public void references_group_by_its_name() throws Exception {
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     GroupDto group = db.users().insertGroup(org, "the-group");
     UserDto user1 = db.users().insertUser(newUserDto().setLogin("ada").setName("Ada Lovelace"));
     db.users().insertMember(group, user1);
index 2261e47e74932a87348c9c5388f5bcbce60a5c62..d85f779f9dc4a16bb07a56accff822e57d7a9e28 100644 (file)
@@ -65,6 +65,7 @@ import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.util.SequenceUuidFactory;
 import org.sonar.db.component.ComponentDbTester;
+import org.sonar.db.organization.OrganizationDbTester;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.UserDbTester;
@@ -95,6 +96,7 @@ public class DbTester extends ExternalResource {
 
   private final UserDbTester userTester;
   private final ComponentDbTester componentTester;
+  private final OrganizationDbTester organizationTester;
 
   private DbTester(System2 system2, @Nullable String schemaPath) {
     this.system2 = system2;
@@ -102,6 +104,7 @@ public class DbTester extends ExternalResource {
     initDbClient();
     this.userTester = new UserDbTester(this);
     this.componentTester = new ComponentDbTester(this);
+    this.organizationTester = new OrganizationDbTester(this);
   }
 
   public static DbTester create(System2 system2) {
@@ -165,6 +168,10 @@ public class DbTester extends ExternalResource {
     return componentTester;
   }
 
+  public OrganizationDbTester organizations() {
+    return organizationTester;
+  }
+
   @Override
   protected void after() {
     if (session != null) {
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
new file mode 100644 (file)
index 0000000..a4a8f5a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.organization;
+
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+
+public class OrganizationDbTester {
+  private final DbTester dbTester;
+
+  public OrganizationDbTester(DbTester dbTester) {
+    this.dbTester = dbTester;
+  }
+
+  /**
+   * Insert an {@link OrganizationDto} and commit the session
+   */
+  public OrganizationDto insert() {
+    return insert(OrganizationTesting.newOrganizationDto());
+  }
+
+  /**
+   * Insert the provided {@link OrganizationDto} and commit the session
+   */
+  public OrganizationDto insert(OrganizationDto dto) {
+    DbSession dbSession = dbTester.getSession();
+    dbTester.getDbClient().organizationDao().insert(dbSession, dto);
+    dbSession.commit();
+    return dto;
+  }
+}
index bc8dc321aae9452d20014cb4e68550b7fe5033b2..de59eb49f10947f9ebeadaac26733cb72a087942 100644 (file)
@@ -19,9 +19,6 @@
  */
 package org.sonar.db.organization;
 
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 
 public class OrganizationTesting {
@@ -30,16 +27,6 @@ public class OrganizationTesting {
     // only statics
   }
 
-  /**
-   * Insert an {@link OrganizationDto} and commit the session
-   */
-  public static OrganizationDto insert(DbTester dbTester, OrganizationDto dto) {
-    DbSession dbSession = dbTester.getSession();
-    dbTester.getDbClient().organizationDao().insert(dbSession, dto);
-    dbSession.commit();
-    return dto;
-  }
-
   /**
    * Creates a new {@link OrganizationDto} with randomly generated field values.
    */
index 726b2959cfec1c8a51ab1e9120cbdc649db1decd..6a62f5dc51735fcf02eb950292bce1b23b487fcb 100644 (file)
@@ -30,13 +30,11 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 
 import static com.google.common.collect.Sets.newHashSet;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 
 public class AuthorizationDaoTest {
 
@@ -57,7 +55,7 @@ public class AuthorizationDaoTest {
 
   @Before
   public void setUp() throws Exception {
-    org = OrganizationTesting.insert(db, newOrganizationDto());
+    org = db.organizations().insert();
     user = db.users().insertUser();
     group1 = db.users().insertGroup(org, "group1");
     group2 = db.users().insertGroup(org, "group2");
@@ -187,7 +185,7 @@ public class AuthorizationDaoTest {
     UserDto user4 = db.users().insertUser();
     UserDto user5 = db.users().insertUser();
 
-    OrganizationDto org = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org = db.organizations().insert();
     GroupDto group1 = db.users().insertGroup(org, "g1");
     db.users().insertPermissionOnGroup(group1, "perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
index 9c1c34c31bc0e4bfdaf8a4a931ce1f573c9746b5..535fd5bb5d2e99bb23e73d53d4c6e8275e2a0086 100644 (file)
@@ -31,7 +31,6 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.db.user.GroupDto;
 
 import static java.util.Arrays.asList;
@@ -45,15 +44,12 @@ import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
 import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 
 public class GroupPermissionDaoTest {
-  private static final long UNKNOWN_PROJECT_ID = -1L;
-  private static final long UNKNOWN_GROUP_ID = -1L;
-
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
+
   private DbSession dbSession = db.getSession();
   private GroupPermissionDao underTest = new GroupPermissionDao();
 
@@ -281,8 +277,8 @@ public class GroupPermissionDaoTest {
 
   @Test
   public void selectGlobalPermissionsOfGroup() {
-    OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
-    OrganizationDto org2 = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org1 = db.organizations().insert();
+    OrganizationDto org2 = db.organizations().insert();
     GroupDto group1 = db.users().insertGroup(org1, "group1");
     GroupDto group2 = db.users().insertGroup(org2, "group2");
     ComponentDto project = db.components().insertProject();
@@ -305,7 +301,7 @@ public class GroupPermissionDaoTest {
 
   @Test
   public void selectProjectPermissionsOfGroup() {
-    OrganizationDto org1 = OrganizationTesting.insert(db, newOrganizationDto());
+    OrganizationDto org1 = db.organizations().insert();
     GroupDto group1 = db.users().insertGroup(org1, "group1");
     ComponentDto project1 = db.components().insertProject();
     ComponentDto project2 = db.components().insertProject();