From d6ee52ba18767c63c8111ddbbe144c200e4bd2ae Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Mon, 10 Apr 2017 17:27:56 +0200 Subject: [PATCH] =?utf8?q?SONAR-8951=20active=20rule=20dao:=20remove=20?= =?utf8?q?=E2=80=9CselectAll=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../db/qualityprofile/ActiveRuleDao.java | 5 --- .../db/qualityprofile/ActiveRuleDaoTest.java | 13 ------- .../QProfileBackuperMediumTest.java | 2 +- .../qualityprofile/QProfileFactoryTest.java | 35 ++++++++----------- 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java index ffa57508df2..e40bce98037 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java @@ -67,11 +67,6 @@ public class ActiveRuleDao implements Dao { return executeLargeInputs(ids, mapper(dbSession)::selectByRuleIds); } - // TODO As it's only used by MediumTest, it should be replaced by DbTester.countRowsOfTable() - public List selectAll(DbSession dbSession) { - return mapper(dbSession).selectAll(); - } - /** * Active rule on removed rule are NOT returned */ diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java index 9d03879a332..de8449cd7f9 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java @@ -173,19 +173,6 @@ public class ActiveRuleDaoTest { .extracting("key").containsOnly(activeRule1.getKey(), activeRule2.getKey(), activeRule3.getKey()); } - @Test - public void select_all() { - ActiveRuleDto activeRule1 = createFor(profile1, rule1).setSeverity(BLOCKER); - ActiveRuleDto activeRule2 = createFor(profile1, rule2).setSeverity(BLOCKER); - ActiveRuleDto activeRule3 = createFor(profile2, rule1).setSeverity(BLOCKER); - underTest.insert(dbSession, activeRule1); - underTest.insert(dbSession, activeRule2); - underTest.insert(dbSession, activeRule3); - dbSession.commit(); - - assertThat(underTest.selectAll(dbSession)).hasSize(3); - } - @Test public void select_by_profile() { ActiveRuleDto activeRule1 = createFor(profile1, rule1).setSeverity(BLOCKER); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java index 2653ce32b68..d3f27f9118f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java @@ -388,7 +388,7 @@ public class QProfileBackuperMediumTest { organization, null); dbSession.clearCache(); - assertThat(db.activeRuleDao().selectAll(dbSession)).hasSize(0); + assertThat(db.openSession(false).selectList("SELECT * FROM active_rules")).isEmpty(); List profiles = db.qualityProfileDao().selectAll(dbSession, organization); assertThat(profiles).hasSize(1); assertThat(profiles.get(0).getName()).isEqualTo("P1"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java index 29763300fd0..d98e8eb2140 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java @@ -21,7 +21,7 @@ package org.sonar.server.qualityprofile; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; +import org.assertj.core.api.AbstractObjectAssert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -35,9 +35,8 @@ import org.sonar.db.organization.OrganizationDto; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QualityProfileDto; -import org.sonar.db.rule.RuleDto; +import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleParamDto; -import org.sonar.db.rule.RuleTesting; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; import static java.util.Arrays.asList; @@ -54,12 +53,12 @@ public class QProfileFactoryTest { private ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class); private QProfileFactory underTest = new QProfileFactory(db.getDbClient(), new SequenceUuidFactory(), System2.INSTANCE, activeRuleIndexer); - private RuleDto rule; + private RuleDefinitionDto rule; private RuleParamDto ruleParam; @Before public void setUp() throws Exception { - rule = db.rules().insertRule(RuleTesting.newRuleDto()); + rule = db.rules().insert(); ruleParam = db.rules().insertRuleParam(rule); } @@ -73,8 +72,10 @@ public class QProfileFactoryTest { List profileKeys = asList(profile1.getKey(), profile2.getKey(), "does_not_exist"); underTest.deleteByKeys(db.getSession(), profileKeys); - assertOnlyExists(org, profile3); verify(activeRuleIndexer).deleteByProfileKeys(profileKeys); + assertQualityProfileFromDb(profile1).isNull(); + assertQualityProfileFromDb(profile2).isNull(); + assertQualityProfileFromDb(profile3).isNotNull(); } @Test @@ -84,20 +85,8 @@ public class QProfileFactoryTest { underTest.deleteByKeys(db.getSession(), Collections.emptyList()); - assertOnlyExists(org, profile1); verifyZeroInteractions(activeRuleIndexer); - } - - private void assertOnlyExists(OrganizationDto org, QualityProfileDto profile) { - List profiles = db.getDbClient().qualityProfileDao().selectAll(db.getSession(), org); - assertThat(profiles).extracting(QualityProfileDto::getKey).containsOnly(profile.getKey()); - - List activeRules = db.getDbClient().activeRuleDao().selectAll(db.getSession()); - assertThat(activeRules).extracting(ActiveRuleDto::getProfileId).containsOnly(profile.getId()); - - List activeParams = db.getDbClient().activeRuleDao().selectAllParams(db.getSession()); - List activeRuleIds = activeRules.stream().map(ActiveRuleDto::getId).collect(Collectors.toList()); - assertThat(activeParams).extracting(ActiveRuleParamDto::getActiveRuleId).containsOnlyElementsOf(activeRuleIds); + assertQualityProfileFromDb(profile1).isNotNull(); } private QualityProfileDto createRandomProfile(OrganizationDto org) { @@ -109,10 +98,16 @@ public class QProfileFactoryTest { .setRuleId(rule.getId()) .setSeverity(Severity.BLOCKER); db.getDbClient().activeRuleDao().insert(db.getSession(), activeRuleDto); - ActiveRuleParamDto activeRuleParam = new ActiveRuleParamDto().setRulesParameterId(ruleParam.getId()).setKey("foo").setValue("bar"); + ActiveRuleParamDto activeRuleParam = new ActiveRuleParamDto() + .setRulesParameterId(ruleParam.getId()) + .setKey("foo") + .setValue("bar"); db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRuleDto, activeRuleParam); db.getSession().commit(); return profile; } + private AbstractObjectAssert assertQualityProfileFromDb(QualityProfileDto profile) { + return assertThat(db.getDbClient().qualityProfileDao().selectByKey(db.getSession(), profile.getKey())); + } } -- 2.39.5