]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8951 active rule dao: remove “selectAll”
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Mon, 10 Apr 2017 15:27:56 +0000 (17:27 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Fri, 14 Apr 2017 06:57:18 +0000 (08:57 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDao.java
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java

index ffa57508df2ac21f7adb5198c5feef9a5a45df5d..e40bce98037ac0297537ca809251dc3748867e69 100644 (file)
@@ -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<ActiveRuleDto> selectAll(DbSession dbSession) {
-    return mapper(dbSession).selectAll();
-  }
-
   /**
    * Active rule on removed rule are NOT returned
    */
index 9d03879a332f1f405b78c9174835c912071bb2c9..de8449cd7f99c13bde824d06d0aa2d5c36dd14e6 100644 (file)
@@ -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);
index 2653ce32b68168345c370de12fd861329b58eefa..d3f27f9118f85da50822066a4e125913a72f80da 100644 (file)
@@ -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<QualityProfileDto> profiles = db.qualityProfileDao().selectAll(dbSession, organization);
     assertThat(profiles).hasSize(1);
     assertThat(profiles.get(0).getName()).isEqualTo("P1");
index 29763300fd0be5768ec4bdfcc1d4389fc3ad9ceb..d98e8eb214095685a7542a6e3481460ba8894932 100644 (file)
@@ -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<String> 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<QualityProfileDto> profiles = db.getDbClient().qualityProfileDao().selectAll(db.getSession(), org);
-    assertThat(profiles).extracting(QualityProfileDto::getKey).containsOnly(profile.getKey());
-
-    List<ActiveRuleDto> activeRules = db.getDbClient().activeRuleDao().selectAll(db.getSession());
-    assertThat(activeRules).extracting(ActiveRuleDto::getProfileId).containsOnly(profile.getId());
-
-    List<ActiveRuleParamDto> activeParams = db.getDbClient().activeRuleDao().selectAllParams(db.getSession());
-    List<Integer> 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<?, QualityProfileDto> assertQualityProfileFromDb(QualityProfileDto profile) {
+    return assertThat(db.getDbClient().qualityProfileDao().selectByKey(db.getSession(), profile.getKey()));
+  }
 }