コード例 #1
0
  @Test
  public void stats_for_all() {
    indexRules(newDoc(RULE_KEY_1), newDoc(RULE_KEY_2));

    ActiveRuleKey activeRuleKey1 = ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_1);
    ActiveRuleKey activeRuleKey2 = ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_2);

    indexActiveRules(
        ActiveRuleDocTesting.newDoc(activeRuleKey1).setSeverity(BLOCKER),
        ActiveRuleDocTesting.newDoc(activeRuleKey2).setSeverity(MINOR),
        // Profile 2 is a child a profile 1
        ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1))
            .setSeverity(MAJOR)
            .setInheritance(INHERITED.name()),
        ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2))
            .setSeverity(BLOCKER)
            .setInheritance(OVERRIDES.name()));

    // 0. Test base case
    assertThat(tester.countDocuments(INDEX, TYPE_ACTIVE_RULE)).isEqualTo(4);

    // 1. Assert by term aggregation;
    Map<String, Multimap<String, FacetValue>> stats =
        index.getStatsByProfileKeys(ImmutableList.of(QUALITY_PROFILE_KEY1, QUALITY_PROFILE_KEY2));
    assertThat(stats).hasSize(2);
  }
コード例 #2
0
  /** SONAR-5844 */
  @Test
  public void stats_for_all_with_lof_of_profiles() {
    indexRules(RuleDocTesting.newDoc(RULE_KEY_1), RuleDocTesting.newDoc(RULE_KEY_2));

    indexActiveRules(
        ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_1)),
        ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)));

    List<String> profileKeys = new ArrayList<>();
    List<ActiveRuleDoc> docs = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
      String profileKey = "profile-" + i;
      profileKeys.add(profileKey);
      docs.add(
          ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(profileKey, RULE_KEY_1))
              .setSeverity(BLOCKER));
      docs.add(
          ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(profileKey, RULE_KEY_2)).setSeverity(MAJOR));
    }
    indexActiveRules(docs.toArray(new ActiveRuleDoc[] {}));

    Map<String, Multimap<String, FacetValue>> stats = index.getStatsByProfileKeys(profileKeys);
    assertThat(stats).hasSize(30);
  }