import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
public class ActiveRuleBackendMediumTest extends SearchMediumTest {
- ActiveRuleIndex index;
-
- @Before
- public void before() {
- index = tester.get(ActiveRuleIndex.class);
- }
-
@Test
public void synchronize_index() throws Exception {
// 1. Synchronize since 0
tester.clearIndexes();
- assertThat(index.getByKey(activeRule.getKey())).isNull();
+ assertThat(index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey())).isNull();
db.activeRuleDao().synchronizeAfter(dbSession, new Date(0L));
- assertThat(index.getByKey(activeRule.getKey())).isNotNull();
+ assertThat(index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey())).isNotNull();
// 2. Synchronize since beginning
tester.clearIndexes();
- assertThat(index.getByKey(activeRule.getKey())).isNull();
+ assertThat(index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey())).isNull();
db.activeRuleDao().synchronizeAfter(dbSession, beginning);
- assertThat(index.getByKey(activeRule.getKey())).isNotNull();
+ assertThat(index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey())).isNotNull();
// 3. Assert startup picks it up
tester.clearIndexes();
- Date before = index.getLastSynchronization();
+ Date before = index.get(ActiveRuleIndex.class).getLastSynchronization();
tester.get(Platform.class).executeStartupTasks();
- assertThat(index.getByKey(activeRule.getKey())).isNotNull();
- assertThat(before.before(index.getLastSynchronization())).isTrue();
+ assertThat(index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey())).isNotNull();
+ assertThat(before.before(index.get(ActiveRuleIndex.class).getLastSynchronization())).isTrue();
}
@Test
assertThat(persistedDtos).hasSize(1);
// verify es
- ActiveRule hit = index.getByKey(activeRule.getKey());
+ ActiveRule hit = index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey());
assertThat(hit).isNotNull();
assertThat(hit.key()).isEqualTo(activeRule.getKey());
assertThat(hit.inheritance().name()).isEqualTo(activeRule.getInheritance());
assertThat(persistedDtos).hasSize(2);
// verify es
- ActiveRule rule = index.getByKey(activeRule.getKey());
+ ActiveRule rule = index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey());
assertThat(rule).isNotNull();
assertThat(rule.params()).hasSize(2);
assertThat(rule.params().keySet()).containsOnly("min", "max");
assertThat(db.activeRuleDao().findByRule(dbSession, rule2)).hasSize(2);
// in es
- List<ActiveRule> activeRules = index.findByRule(RuleTesting.XOO_X1);
+ List<ActiveRule> activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X1);
assertThat(activeRules).hasSize(1);
assertThat(activeRules.get(0).key().ruleKey()).isEqualTo(RuleTesting.XOO_X1);
- activeRules = index.findByRule(RuleTesting.XOO_X2);
+ activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X2);
assertThat(activeRules).hasSize(2);
assertThat(activeRules.get(0).key().ruleKey()).isEqualTo(RuleTesting.XOO_X2);
- activeRules = index.findByRule(RuleTesting.XOO_X3);
+ activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X3);
assertThat(activeRules).isEmpty();
// 2. find by profile
- activeRules = index.findByProfile(profile1.getKey());
+ activeRules = index.get(ActiveRuleIndex.class).findByProfile(profile1.getKey());
assertThat(activeRules).hasSize(2);
assertThat(activeRules.get(0).key().qProfile()).isEqualTo(profile1.getKey());
assertThat(activeRules.get(1).key().qProfile()).isEqualTo(profile1.getKey());
- activeRules = index.findByProfile(profile2.getKey());
+ activeRules = index.get(ActiveRuleIndex.class).findByProfile(profile2.getKey());
assertThat(activeRules).hasSize(1);
assertThat(activeRules.get(0).key().qProfile()).isEqualTo(profile2.getKey());
- activeRules = index.findByProfile("unknown");
+ activeRules = index.get(ActiveRuleIndex.class).findByProfile("unknown");
assertThat(activeRules).isEmpty();
}
dbSession.clearCache();
// verify index
- Collection<ActiveRule> activeRules = index.findByProfile(profileDto.getKey());
+ Collection<ActiveRule> activeRules = index.get(ActiveRuleIndex.class).findByProfile(profileDto.getKey());
assertThat(activeRules).hasSize(nb);
}
dbSession.commit();
// 0. Test base case
- assertThat(index.countAll()).isEqualTo(2);
+ assertThat(index.get(ActiveRuleIndex.class).countAll()).isEqualTo(2);
// 1. Assert by profileKey
- assertThat(index.countByQualityProfileKey(profileDto1.getKey())).isEqualTo(1);
+ assertThat(index.get(ActiveRuleIndex.class).countByQualityProfileKey(profileDto1.getKey())).isEqualTo(1);
// 2. Assert by term aggregation;
- Map<String, Long> counts = index.countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY);
+ Map<String, Long> counts = index.get(ActiveRuleIndex.class).countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY);
assertThat(counts).hasSize(2);
assertThat(counts.values()).containsOnly(1L, 1L);
assertThat(counts.keySet()).containsOnly(profileDto1.getKey().toString(), profileDto2.getKey().toString());
dbSession.commit();
// 0. Test base case
- assertThat(index.countAll()).isEqualTo(2);
+ assertThat(index.get(ActiveRuleIndex.class).countAll()).isEqualTo(2);
// 1. Assert by term aggregation;
- Map<String, Long> counts = index.countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY);
+ Map<String, Long> counts = index.get(ActiveRuleIndex.class).countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY);
assertThat(counts).hasSize(2);
assertThat(counts.values()).containsOnly(1L, 1L);
assertThat(counts.keySet()).containsOnly(profileDto1.getKey(), profileDto2.getKey());
dbSession.clearCache();
// 0. Test base case
- assertThat(index.countAll()).isEqualTo(4);
+ assertThat(index.get(ActiveRuleIndex.class).countAll()).isEqualTo(4);
// 1. Assert by term aggregation;
- Map<String, Multimap<String, FacetValue>> stats = index.getStatsByProfileKeys(
+ Map<String, Multimap<String, FacetValue>> stats = index.get(ActiveRuleIndex.class).getStatsByProfileKeys(
ImmutableList.of(profileDto1.getKey(),
profileDto2.getKey()));