]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5844 Profile inheritance is always displaying '0 rules' whatever the content...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 7 Nov 2014 09:25:15 +0000 (10:25 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 7 Nov 2014 09:25:15 +0000 (10:25 +0100)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java

index e96cafcecbaad146b89449ace2eb96f93dafb763..dfffc90eb3a143c51aa2754b34968528de09dffd 100644 (file)
@@ -180,7 +180,7 @@ public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, Active
           .mustNot(FilterBuilders.hasParentFilter(this.getParentType(),
             FilterBuilders.termFilter(RuleNormalizer.RuleField.STATUS.field(), RuleStatus.REMOVED.name())))))
       .addAggregation(AggregationBuilders.terms(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field())
-        .field(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field())
+        .field(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field()).size(0)
         .subAggregation(AggregationBuilders.terms(ActiveRuleNormalizer.ActiveRuleField.INHERITANCE.field())
           .field(ActiveRuleNormalizer.ActiveRuleField.INHERITANCE.field()))
         .subAggregation(AggregationBuilders.terms(ActiveRuleNormalizer.ActiveRuleField.SEVERITY.field())
index db00b4efd32eace5d2cf1bbfcd3252ca8b107acc..6172df090ba89fa1da2ba514c991a21501e4c7c4 100644 (file)
@@ -43,6 +43,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
 
 public class ActiveRuleBackendMediumTest extends SearchMediumTest {
@@ -324,6 +325,35 @@ public class ActiveRuleBackendMediumTest extends SearchMediumTest {
     assertThat(stats).hasSize(2);
   }
 
+  /**
+   * SONAR-5844
+   */
+  @Test
+  public void stats_for_all_with_lof_of_profiles() {
+    RuleDto ruleDto1 = newRuleDto(RuleTesting.XOO_X1);
+    RuleDto ruleDto2 = newRuleDto(RuleTesting.XOO_X2);
+    db.ruleDao().insert(dbSession, ruleDto1, ruleDto2);
+
+    List<String> profileKeys = newArrayList();
+    for (int i = 0; i<30; i++) {
+      QualityProfileDto profileDto = QProfileTesting.newDto(QProfileName.createFor("xoo", "profile-" + i), "profile-" + i);
+      profileKeys.add(profileDto.getKey());
+      db.qualityProfileDao().insert(dbSession, profileDto);
+
+      db.activeRuleDao().insert(dbSession,
+        ActiveRuleDto.createFor(profileDto, ruleDto1)
+          .setSeverity(Severity.BLOCKER),
+        ActiveRuleDto.createFor(profileDto, ruleDto2)
+          .setSeverity(Severity.MAJOR)
+      );
+    }
+    dbSession.commit();
+    dbSession.clearCache();
+
+    Map<String, Multimap<String, FacetValue>> stats = index.get(ActiveRuleIndex.class).getStatsByProfileKeys(profileKeys);
+    assertThat(stats).hasSize(30);
+  }
+
   private RuleDto newRuleDto(RuleKey ruleKey) {
     return new RuleDto()
       .setRuleKey(ruleKey.rule())