@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);
  }
  @Test
  public void index_all_project() {
    componentDbTester.insertProjectAndSnapshot(newProjectDto());
    componentDbTester.insertProjectAndSnapshot(newProjectDto());
    componentDbTester.insertProjectAndSnapshot(newProjectDto());

    underTest.index();

    assertThat(esTester.countDocuments(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES)).isEqualTo(3);
  }
  @Test
  public void count_all_by_quality_profile_key() {
    indexRules(RuleDocTesting.newDoc(RULE_KEY_1));

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

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

    // 1. Assert by term aggregation;
    assertThat(index.countAllByQualityProfileKey())
        .containsOnly(entry(QUALITY_PROFILE_KEY1, 1L), entry(QUALITY_PROFILE_KEY2, 1L));
  }
예제 #4
0
  @Test
  public void delete_views() throws Exception {
    esTester.putDocuments(
        ViewIndexDefinition.INDEX,
        ViewIndexDefinition.TYPE_VIEW,
        this.getClass(),
        "view1.json",
        "view2.json");

    index.delete(
        newArrayList(
            "fed0a543-9d9c-4af5-a4ec-450a8fe78ce7", "8d0bc2a5-bfba-464b-92de-bb170e9d978e"));

    assertThat(esTester.countDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW))
        .isEqualTo(0L);
  }
예제 #5
0
 private long countDocuments() {
   return es.countDocuments(INDEX, TYPE);
 }
  @Test
  public void index_nothing() {
    underTest.index();

    assertThat(esTester.countDocuments(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES)).isZero();
  }