From 345367ccbbb19318479cbbd21319447520f3bbbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 3 Dec 2018 12:53:55 +0100 Subject: [PATCH] SONARCLOUD-192 move all analytics SQL out of core mappers --- .../org/sonar/db/component/ComponentDao.java | 9 -- .../sonar/db/component/ComponentMapper.java | 5 - .../db/organization/OrganizationDao.java | 13 -- .../db/organization/OrganizationMapper.java | 7 - .../main/java/org/sonar/db/user/UserDao.java | 32 ---- .../java/org/sonar/db/user/UserMapper.java | 13 -- .../sonar/db/component/ComponentMapper.xml | 77 --------- .../db/organization/OrganizationMapper.xml | 150 ------------------ .../org/sonar/db/user/UserMapper.xml | 66 -------- .../sonar/db/component/ComponentDaoTest.java | 93 ----------- .../db/organization/OrganizationDaoTest.java | 123 -------------- .../java/org/sonar/db/user/UserDaoTest.java | 89 ----------- 12 files changed, 677 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index 5a286a87cd3..93861462c9e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -38,7 +38,6 @@ import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Scopes; import org.sonar.db.Dao; import org.sonar.db.DbSession; -import org.sonar.db.KeyLongValue; import org.sonar.db.RowNotFoundException; import static com.google.common.base.Preconditions.checkArgument; @@ -138,14 +137,6 @@ public class ComponentDao implements Dao { return countByQueryImpl(session, organizationUuid, query); } - public List countByNclocRanges(DbSession dbSession) { - return mapper(dbSession).countByNclocRanges(); - } - - public long countPublicNcloc(DbSession dbSession) { - return mapper(dbSession).countPublicNcloc(); - } - public List selectSubProjectsByComponentUuids(DbSession session, Collection uuids) { if (uuids.isEmpty()) { return emptyList(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java index 0eeef53f633..9bed652792f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java @@ -27,7 +27,6 @@ import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; -import org.sonar.db.KeyLongValue; public interface ComponentMapper { @@ -79,10 +78,6 @@ public interface ComponentMapper { int countByQuery(@Nullable @Param("organizationUuid") String organizationUuid, @Param("query") ComponentQuery query); - List countByNclocRanges(); - - long countPublicNcloc(); - List selectDescendants(@Param("query") ComponentTreeQuery query, @Param("baseUuid") String baseUuid, @Param("baseUuidPath") String baseUuidPath); /** diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java index 87e818e2d3f..0c93afcb98e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java @@ -26,7 +26,6 @@ import java.util.Set; import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; -import org.sonar.db.KeyLongValue; import org.sonar.db.Pagination; import org.sonar.db.component.BranchType; import org.sonar.db.component.KeyType; @@ -59,18 +58,6 @@ public class OrganizationDao implements Dao { return getMapper(dbSession).countByQuery(organizationQuery); } - public List countTeamsByMembers(DbSession dbSession) { - return getMapper(dbSession).countTeamsByMembers(); - } - - public List countTeamsByProjects(DbSession dbSession) { - return getMapper(dbSession).countTeamsByProjects(); - } - - public List countTeamsByNclocRanges(DbSession dbSession) { - return getMapper(dbSession).countTeamsByNclocRanges(); - } - public List selectByQuery(DbSession dbSession, OrganizationQuery organizationQuery, Pagination pagination) { requireNonNull(organizationQuery, "organizationQuery can't be null"); return getMapper(dbSession).selectByQuery(organizationQuery, pagination); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java index 028d44376ef..39d54cf923a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java @@ -22,7 +22,6 @@ package org.sonar.db.organization; import java.util.List; import javax.annotation.CheckForNull; import org.apache.ibatis.annotations.Param; -import org.sonar.db.KeyLongValue; import org.sonar.db.Pagination; import org.sonar.db.component.BranchType; import org.sonar.db.component.KeyType; @@ -32,12 +31,6 @@ public interface OrganizationMapper { int countByQuery(@Param("query") OrganizationQuery organizationQuery); - List countTeamsByMembers(); - - List countTeamsByProjects(); - - List countTeamsByNclocRanges(); - List selectByQuery(@Param("query") OrganizationQuery organizationQuery, @Param("pagination") Pagination pagination); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java index 29ee56dd5e0..aacbee9fa84 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java @@ -34,7 +34,6 @@ import org.sonar.api.utils.System2; import org.sonar.core.util.UuidFactory; import org.sonar.db.Dao; import org.sonar.db.DbSession; -import org.sonar.db.KeyLongValue; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; @@ -117,37 +116,6 @@ public class UserDao implements Dao { return mapper(dbSession).countRootUsersButLogin(login); } - /** - * Includes deactivated users - */ - public long countTotalUsers(DbSession dbSession) { - return mapper(dbSession).countTotalUsers(); - } - - public long countTeamUsers(DbSession dbSession) { - return mapper(dbSession).countTeamUsers(); - } - - public long countPersonalUsers(DbSession dbSession) { - return mapper(dbSession).countPersonalUsers(); - } - - public long countPersonalUsersWithZeroProjects(DbSession dbSession) { - return mapper(dbSession).countPersonalUsersWithZeroProjects(); - } - - public long countNewUsersSince(DbSession dbSession, long since) { - return mapper(dbSession).countNewUsersSince(since); - } - - public long countActiveUsers(DbSession dbSession) { - return mapper(dbSession).countActiveUsers(); - } - - public List countUsersByIdentityProviders(DbSession dbSession) { - return mapper(dbSession).countUsersByIdentityProviders(); - } - public UserDto insert(DbSession session, UserDto dto) { long now = system2.now(); mapper(session).insert(dto.setUuid(uuidFactory.create()).setCreatedAt(now).setUpdatedAt(now)); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java index 6a5e8802d9a..369b1d42de9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java @@ -24,7 +24,6 @@ import javax.annotation.CheckForNull; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.ResultHandler; import org.sonar.api.user.UserQuery; -import org.sonar.db.KeyLongValue; public interface UserMapper { @@ -72,19 +71,7 @@ public interface UserMapper { */ long countRootUsersButLogin(@Param("login") String login); - long countTotalUsers(); - long countTeamUsers(); - - long countPersonalUsers(); - - long countPersonalUsersWithZeroProjects(); - - long countNewUsersSince(@Param("since") long since); - - long countActiveUsers(); - - List countUsersByIdentityProviders(); void insert(@Param("user") UserDto userDto); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 127adb45c14..1f79ca8d1a3 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -288,83 +288,6 @@ and p.id = #{componentId,jdbcType=BIGINT} - - - - - select kee as "key", sum(val) as "value" - from ( - select '0' as kee, 0 as val ${_from_dual} - union - select '1' as kee, 0 as val ${_from_dual} - union - select '2-4' as kee, 0 as val ${_from_dual} - union - select '5-9' as kee, 0 as val ${_from_dual} - union - select '10-24' as kee, 0 as val ${_from_dual} - union - select '+25' as kee, 0 as val ${_from_dual} - union - select kee, count(1) as val - from ( - select case - when nb = 0 then '0' - when nb = 1 then '1' - when nb >= 2 and nb <= 4 then '2-4' - when nb >= 5 and nb <= 9 then '5-9' - when nb >= 10 and nb <= 24 then '10-24' - else '+25' - end as kee - from ( - select o.uuid, count(om.user_id) as nb - from organizations o - left join organization_members om on om.organization_uuid = o.uuid - where not exists( - select 1 - from users u - where u.organization_uuid = o.uuid - and u.active = ${_true} - ) - group by o.uuid - ) alias1 - ) alias2 - group by kee - ) alias3 - group by kee - - - - - - - - - - - - - - - - - - - - update users set active = ${_false}, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index f88d23f8c7c..8ea80638f1d 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -43,13 +43,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.sonar.api.measures.CoreMetrics; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Scopes; import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.KeyLongValue; import org.sonar.db.RowNotFoundException; import org.sonar.db.metric.MetricDto; import org.sonar.db.organization.OrganizationDto; @@ -1193,97 +1191,6 @@ public class ComponentDaoTest { underTest.countByQuery(dbSession, query.build()); } - @Test - public void countByNclocRanges_on_zero_projects() { - db.measures().insertMetric(m -> m.setKey(CoreMetrics.NCLOC_KEY)); - - assertThat(underTest.countByNclocRanges(dbSession)) - .extracting(KeyLongValue::getKey, KeyLongValue::getValue) - .containsExactlyInAnyOrder( - tuple("1K", 0L), - tuple("5K", 0L), - tuple("10K", 0L), - tuple("20K", 0L), - tuple("50K", 0L), - tuple("100K", 0L), - tuple("250K", 0L), - tuple("500K", 0L), - tuple("1M", 0L), - tuple("+1M", 0L)); - } - - @Test - public void countByNclocRanges() { - MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(CoreMetrics.NCLOC_KEY)); - - // project with highest ncloc in non-main branch - OrganizationDto org = db.organizations().insert(); - ComponentDto project1 = db.components().insertMainBranch(org); - ComponentDto project1Branch = db.components().insertProjectBranch(project1); - db.measures().insertLiveMeasure(project1, ncloc, m -> m.setValue(100.0)); - db.measures().insertLiveMeasure(project1Branch, ncloc, m -> m.setValue(90_000.0)); - - // project with only main branch - ComponentDto project2 = db.components().insertMainBranch(org); - db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(50.0)); - - // project with highest ncloc in main branch - ComponentDto project3 = db.components().insertMainBranch(org); - ComponentDto project3Branch = db.components().insertProjectBranch(project3); - db.measures().insertLiveMeasure(project3, ncloc, m -> m.setValue(80_000.0)); - db.measures().insertLiveMeasure(project3Branch, ncloc, m -> m.setValue(25_000.0)); - - assertThat(underTest.countByNclocRanges(dbSession)) - .extracting(KeyLongValue::getKey, KeyLongValue::getValue) - .containsExactlyInAnyOrder( - tuple("1K", 1L), - tuple("5K", 0L), - tuple("10K", 0L), - tuple("20K", 0L), - tuple("50K", 0L), - tuple("100K", 2L), - tuple("250K", 0L), - tuple("500K", 0L), - tuple("1M", 0L), - tuple("+1M", 0L)); - } - - @Test - public void countPublicNcloc_on_zero_projects() { - db.measures().insertMetric(m -> m.setKey(CoreMetrics.NCLOC_KEY)); - - assertThat(underTest.countPublicNcloc(dbSession)).isEqualTo(0L); - } - - @Test - public void countPublicNcloc() { - MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(CoreMetrics.NCLOC_KEY)); - - // public project with highest ncloc in non-main branch - OrganizationDto org = db.organizations().insert(); - ComponentDto project1 = db.components().insertMainBranch(org); - ComponentDto project1Branch = db.components().insertProjectBranch(project1); - db.measures().insertLiveMeasure(project1, ncloc, m -> m.setValue(100.0)); - db.measures().insertLiveMeasure(project1Branch, ncloc, m -> m.setValue(90_000.0)); - - // public project with only main branch - ComponentDto project2 = db.components().insertMainBranch(org); - db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(50.0)); - - // public project with highest ncloc in main branch - ComponentDto project3 = db.components().insertMainBranch(org); - ComponentDto project3Branch = db.components().insertProjectBranch(project3); - db.measures().insertLiveMeasure(project3, ncloc, m -> m.setValue(80_000.0)); - db.measures().insertLiveMeasure(project3Branch, ncloc, m -> m.setValue(25_000.0)); - - // private project is excluded - ComponentDto privateProject = db.components().insertPrivateProject(org); - db.measures().insertLiveMeasure(privateProject, ncloc, m -> m.setValue(1_000.0)); - - assertThat(underTest.countPublicNcloc(dbSession)) - .isEqualTo(90_000L + 50 + 80_000); - } - @Test public void select_ghost_projects() { OrganizationDto organization = db.organizations().insert(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java index 3a4ea34adc9..52f082af090 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java @@ -1001,129 +1001,6 @@ public class OrganizationDaoTest { .containsOnlyOnce(organization.getUuid()); } - @Test - public void countTeamsByMembers_on_zero_orgs() { - assertThat(underTest.countTeamsByMembers(dbSession)) - .extracting(KeyLongValue::getKey, KeyLongValue::getValue) - .containsExactlyInAnyOrder( - tuple("0", 0L), - tuple("1", 0L), - tuple("2-4", 0L), - tuple("5-9", 0L), - tuple("10-24", 0L), - tuple("+25", 0L)); - } - - @Test - public void countTeamsByMembers() { - UserDto user1 = db.users().insertUser(); - UserDto user2 = db.users().insertUser(); - UserDto user3 = db.users().insertUser(); - OrganizationDto org1 = db.organizations().insert(); - db.organizations().addMember(org1, user1, user2, user3); - OrganizationDto org2 = db.organizations().insert(); - db.organizations().addMember(org2, user1); - OrganizationDto org3 = db.organizations().insert(); - db.organizations().addMember(org3, user1, user2); - - assertThat(underTest.countTeamsByMembers(dbSession)) - .extracting(KeyLongValue::getKey, KeyLongValue::getValue) - .containsExactlyInAnyOrder( - tuple("0", 0L), - tuple("1", 1L), - tuple("2-4", 2L), - tuple("5-9", 0L), - tuple("10-24", 0L), - tuple("+25", 0L)); - } - - @Test - public void countTeamsByProjects_on_zero_projects() { - assertThat(underTest.countTeamsByProjects(dbSession)) - .extracting(KeyLongValue::getKey, KeyLongValue::getValue) - .containsExactlyInAnyOrder( - tuple("0", 0L), - tuple("1", 0L), - tuple("2-4", 0L), - tuple("5-9", 0L), - tuple("10-24", 0L), - tuple("+25", 0L)); - } - - @Test - public void countTeamsByProjects() { - OrganizationDto org1 = db.organizations().insert(); - db.components().insertPrivateProject(org1); - OrganizationDto org2 = db.organizations().insert(); - db.components().insertPrivateProject(org2); - db.components().insertPrivateProject(org2); - OrganizationDto org3 = db.organizations().insert(); - db.components().insertPrivateProject(org3); - db.components().insertPrivateProject(org3); - db.components().insertPrivateProject(org3); - - assertThat(underTest.countTeamsByProjects(dbSession)) - .extracting(KeyLongValue::getKey, KeyLongValue::getValue) - .containsExactlyInAnyOrder( - tuple("0", 0L), - tuple("1", 1L), - tuple("2-4", 2L), - tuple("5-9", 0L), - tuple("10-24", 0L), - tuple("+25", 0L)); - } - - @Test - public void countTeamsByNclocRanges() { - MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(CoreMetrics.NCLOC_KEY)); - - OrganizationDto org1 = db.organizations().insert(); - // project with highest ncloc in non-main branch - ComponentDto project1 = db.components().insertMainBranch(org1); - ComponentDto project1Branch = db.components().insertProjectBranch(project1); - db.measures().insertLiveMeasure(project1, ncloc, m -> m.setValue(1_000.0)); - db.measures().insertLiveMeasure(project1Branch, ncloc, m -> m.setValue(110_000.0)); - // project with only main branch - ComponentDto project2 = db.components().insertMainBranch(org1); - db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(400_000.0)); - - OrganizationDto org2 = db.organizations().insert(); - // project with highest ncloc in main branch - ComponentDto project3 = db.components().insertMainBranch(org2); - ComponentDto project3Branch = db.components().insertProjectBranch(project3); - db.measures().insertLiveMeasure(project3, ncloc, m -> m.setValue(5_800_000.0)); - db.measures().insertLiveMeasure(project3Branch, ncloc, m -> m.setValue(25_000.0)); - - assertThat(underTest.countTeamsByNclocRanges(dbSession)) - .extracting(KeyLongValue::getKey, KeyLongValue::getValue) - .containsExactlyInAnyOrder( - tuple("100K", 0L), - tuple("500K", 1L), - tuple("1M", 0L), - tuple("2M", 0L), - tuple("5M", 0L), - tuple("10M", 1L), - tuple("20M", 0L), - tuple("50M", 0L), - tuple("+50M", 0L)); - } - - @Test - public void countTeamsByNclocRanges_on_zero_orgs() { - assertThat(underTest.countTeamsByNclocRanges(dbSession)) - .extracting(KeyLongValue::getKey, KeyLongValue::getValue) - .containsExactlyInAnyOrder( - tuple("100K", 0L), - tuple("500K", 0L), - tuple("1M", 0L), - tuple("2M", 0L), - tuple("5M", 0L), - tuple("10M", 0L), - tuple("20M", 0L), - tuple("50M", 0L), - tuple("+50M", 0L)); - } - @Test public void selectOrganizationsWithNcloc_on_zero_orgs() { assertThat(underTest.selectOrganizationsWithNcloc(dbSession, new ArrayList<>())) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java index d7baf7809e2..f4c4977e3e3 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java @@ -32,7 +32,6 @@ import org.sonar.db.DatabaseUtils; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.KeyLongValue; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; @@ -294,94 +293,6 @@ public class UserDaoTest { assertThat(underTest.countRootUsersButLogin(session, rootLogin)).isEqualTo(2); } - @Test - public void countTotalUsers() { - assertThat(underTest.countTotalUsers(session)).isEqualTo(0); - - db.users().insertUser(u -> u.setActive(false)); - db.users().insertUser(u -> u.setActive(true)); - - assertThat(underTest.countTotalUsers(session)).isEqualTo(2); - } - - @Test - public void countTeamUsers() { - assertThat(underTest.countTeamUsers(session)).isEqualTo(0); - - // user 1: with only personal organization - OrganizationDto user1Org = db.organizations().insert(); - insertNonRootUser(newUserDto().setOrganizationUuid(user1Org.getUuid())); - assertThat(underTest.countTeamUsers(session)).isEqualTo(0); - - // user 2: with no organizations at all - insertNonRootUser(newUserDto().setOrganizationUuid(null)); - assertThat(underTest.countTeamUsers(session)).isEqualTo(0); - - // user 3: with personal and team organizations - OrganizationDto user3Org = db.organizations().insert(); - OrganizationDto teamOrg = db.organizations().insert(); - UserDto user3 = insertNonRootUser(newUserDto().setOrganizationUuid(user3Org.getUuid())); - db.organizations().addMember(teamOrg, user3); - assertThat(underTest.countTeamUsers(session)).isEqualTo(1); - } - - @Test - public void countPersonalUsers() { - assertThat(underTest.countPersonalUsers(session)).isEqualTo(0); - - // user 1: with only personal organization - OrganizationDto user1Org = db.organizations().insert(); - insertNonRootUser(newUserDto().setOrganizationUuid(user1Org.getUuid())); - assertThat(underTest.countPersonalUsers(session)).isEqualTo(1); - - // user 2: with no organizations at all - insertNonRootUser(newUserDto().setOrganizationUuid(null)); - assertThat(underTest.countPersonalUsers(session)).isEqualTo(1); - - // user 3: with personal and team organizations - OrganizationDto user3Org = db.organizations().insert(); - OrganizationDto teamOrg = db.organizations().insert(); - UserDto user3 = insertNonRootUser(newUserDto().setOrganizationUuid(user3Org.getUuid())); - db.organizations().addMember(teamOrg, user3); - assertThat(underTest.countPersonalUsers(session)).isEqualTo(1); - - // user 4: excluded because deactivated - OrganizationDto user4Org = db.organizations().insert(); - insertNonRootUser(newUserDto().setOrganizationUuid(user4Org.getUuid()).setActive(false)); - assertThat(underTest.countPersonalUsers(session)).isEqualTo(1); - } - - @Test - public void countNewUsersSince() { - assertThat(underTest.countNewUsersSince(session, 400L)).isEqualTo(0); - - system2.setNow(100L); - insertNonRootUser(newUserDto()); - system2.setNow(200L); - insertNonRootUser(newUserDto()); - system2.setNow(300L); - insertNonRootUser(newUserDto()); - - assertThat(underTest.countNewUsersSince(session, 50L)).isEqualTo(3); - assertThat(underTest.countNewUsersSince(session, 190L)).isEqualTo(2); - assertThat(underTest.countNewUsersSince(session, 400L)).isEqualTo(0); - } - - @Test - public void countUsersByIdentityProviders() { - assertThat(underTest.countUsersByIdentityProviders(session)).isEmpty(); - - db.users().insertUser(u -> u.setActive(true).setExternalIdentityProvider("bitbucket")); - db.users().insertUser(u -> u.setActive(true).setExternalIdentityProvider("github")); - db.users().insertUser(u -> u.setActive(true).setExternalIdentityProvider("github")); - // this used is excluded because deactivated - db.users().insertUser(u -> u.setActive(false).setExternalIdentityProvider("github")); - - assertThat(underTest.countUsersByIdentityProviders(session)) - .extracting(KeyLongValue::getKey, KeyLongValue::getValue) - .containsExactlyInAnyOrder(tuple("bitbucket", 1L), tuple("github", 2L)); - } - private UserDto insertInactiveRootUser(UserDto dto) { insertRootUser(dto); dto.setActive(false); -- 2.39.5