aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-10-13 14:52:58 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-10-19 14:45:13 +0200
commit7c33862f5582a5feb8353e084b6a098fa07262c0 (patch)
treed0a58b873fa1164ba1a88912dd043f0d4d536111 /sonar-db
parent601e3acdc5ff2e050f9b43d8db199c92ef5d2257 (diff)
downloadsonarqube-7c33862f5582a5feb8353e084b6a098fa07262c0.tar.gz
sonarqube-7c33862f5582a5feb8353e084b6a098fa07262c0.zip
SONAR-8192 add OrganizationDbTester and add it to DbTester
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/DbTester.java7
-rw-r--r--sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java48
-rw-r--r--sonar-db/src/test/java/org/sonar/db/organization/OrganizationTesting.java13
-rw-r--r--sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java6
-rw-r--r--sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java12
5 files changed, 61 insertions, 25 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/DbTester.java b/sonar-db/src/test/java/org/sonar/db/DbTester.java
index 2261e47e749..d85f779f9dc 100644
--- a/sonar-db/src/test/java/org/sonar/db/DbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/DbTester.java
@@ -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
index 00000000000..a4a8f5af1a9
--- /dev/null
+++ b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDbTester.java
@@ -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;
+ }
+}
diff --git a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationTesting.java b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationTesting.java
index bc8dc321aae..de59eb49f10 100644
--- a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationTesting.java
+++ b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationTesting.java
@@ -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 {
@@ -31,16 +28,6 @@ public class OrganizationTesting {
}
/**
- * 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.
*/
public static OrganizationDto newOrganizationDto() {
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
index 726b2959cfe..6a62f5dc517 100644
--- a/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
@@ -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");
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
index 9c1c34c31bc..535fd5bb5d2 100644
--- a/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
@@ -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();