Search in sources :

Example 1 with ActiveRuleIndexer

use of org.sonar.server.qualityprofile.index.ActiveRuleIndexer in project sonarqube by SonarSource.

the class RuleActivatorMediumTest method before.

@Before
public void before() {
    tester.clearDbAndIndexes();
    db = tester.get(DbClient.class);
    dbSession = db.openSession(false);
    ruleActivator = tester.get(RuleActivator.class);
    activeRuleIndex = tester.get(ActiveRuleIndex.class);
    activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
    ruleIndexer = tester.get(RuleIndexer.class);
    // create pre-defined rules
    RuleDto javaRule = newDto(RuleKey.of("squid", "j1")).setSeverity("MAJOR").setLanguage("java");
    RuleDto xooRule1 = newXooX1().setSeverity("MINOR");
    RuleDto xooRule2 = newXooX2().setSeverity("INFO");
    RuleDto xooTemplateRule1 = newTemplateRule(TEMPLATE_RULE_KEY).setSeverity("MINOR").setLanguage("xoo");
    db.ruleDao().insert(dbSession, javaRule);
    db.ruleDao().insert(dbSession, xooRule1);
    db.ruleDao().insert(dbSession, xooRule2);
    db.ruleDao().insert(dbSession, xooTemplateRule1);
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("max").setDefaultValue("10").setType(RuleParamType.INTEGER.type()));
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("min").setType(RuleParamType.INTEGER.type()));
    db.ruleDao().insertRuleParam(dbSession, xooTemplateRule1, RuleParamDto.createFor(xooTemplateRule1).setName("format").setType(RuleParamType.STRING.type()));
    RuleDto xooCustomRule1 = newCustomRule(xooTemplateRule1).setRuleKey(CUSTOM_RULE_KEY.rule()).setSeverity("MINOR").setLanguage("xoo");
    db.ruleDao().insert(dbSession, xooCustomRule1);
    db.ruleDao().insertRuleParam(dbSession, xooCustomRule1, RuleParamDto.createFor(xooTemplateRule1).setName("format").setDefaultValue("txt").setType(RuleParamType.STRING.type()));
    // create pre-defined profile P1
    profileDto = QProfileTesting.newXooP1("org-123");
    db.qualityProfileDao().insert(dbSession, profileDto);
    dbSession.commit();
    dbSession.clearCache();
    ruleIndexer.index();
}
Also used : ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) ActiveRuleIndex(org.sonar.server.qualityprofile.index.ActiveRuleIndex) DbClient(org.sonar.db.DbClient) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) Before(org.junit.Before)

Example 2 with ActiveRuleIndexer

use of org.sonar.server.qualityprofile.index.ActiveRuleIndexer in project sonarqube by SonarSource.

the class QProfileCopierMediumTest method before.

@Before
public void before() {
    tester.clearDbAndIndexes();
    db = tester.get(DbClient.class);
    dbSession = db.openSession(false);
    ruleActivator = tester.get(RuleActivator.class);
    index = tester.get(ActiveRuleIndex.class);
    copier = tester.get(QProfileCopier.class);
    ruleIndexer = tester.get(RuleIndexer.class);
    activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
    // create pre-defined rules
    RuleDto xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR");
    RuleDto xooRule2 = RuleTesting.newXooX2().setSeverity("MAJOR");
    db.ruleDao().insert(dbSession, xooRule1);
    db.ruleDao().insert(dbSession, xooRule2);
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("max").setDefaultValue("10").setType(RuleParamType.INTEGER.type()));
    // create pre-defined profile
    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
    dbSession.commit();
    dbSession.clearCache();
    ruleIndexer.index();
}
Also used : ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) ActiveRuleIndex(org.sonar.server.qualityprofile.index.ActiveRuleIndex) DbClient(org.sonar.db.DbClient) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) Before(org.junit.Before)

Example 3 with ActiveRuleIndexer

use of org.sonar.server.qualityprofile.index.ActiveRuleIndexer in project sonarqube by SonarSource.

the class RuleIndexTest method setUp.

@Before
public void setUp() {
    ruleIndexer = new RuleIndexer(system2, null, tester.client());
    activeRuleIndexer = new ActiveRuleIndexer(system2, null, tester.client());
    index = new RuleIndex(tester.client());
}
Also used : ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) Before(org.junit.Before)

Example 4 with ActiveRuleIndexer

use of org.sonar.server.qualityprofile.index.ActiveRuleIndexer in project sonarqube by SonarSource.

the class BuiltInQProfileUpdateImplTest method do_not_load_descendants_if_no_changes.

@Test
public void do_not_load_descendants_if_no_changes() {
    RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo"));
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true));
    QProfileDto childProfile = createChildProfile(profile);
    BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
    NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile(profile.getName(), profile.getLanguage());
    newQp.activateRule(rule.getRepositoryKey(), rule.getRuleKey());
    newQp.done();
    // first run
    BuiltInQProfile builtIn = builtInProfileRepository.create(context.profile(profile.getLanguage(), profile.getName()), rule);
    List<ActiveRuleChange> changes = underTest.update(db.getSession(), builtIn, RulesProfileDto.from(profile));
    assertThat(changes).hasSize(2).extracting(ActiveRuleChange::getType).containsOnly(ActiveRuleChange.Type.ACTIVATED);
    verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(persistedProfile.getLanguage()));
    // second run, without any input changes
    RuleActivator ruleActivatorWithoutDescendants = new RuleActivator(system2, db.getDbClient(), typeValidations, userSession) {

        @Override
        DescendantProfilesSupplier createDescendantProfilesSupplier(DbSession dbSession) {
            return (profiles, ruleIds) -> {
                throw new IllegalStateException("BOOM - descendants should not be loaded");
            };
        }
    };
    changes = new BuiltInQProfileUpdateImpl(db.getDbClient(), ruleActivatorWithoutDescendants, activeRuleIndexer, qualityProfileChangeEventService).update(db.getSession(), builtIn, RulesProfileDto.from(profile));
    assertThat(changes).isEmpty();
    verifyNoMoreInteractions(qualityProfileChangeEventService);
}
Also used : INHERITED(org.sonar.server.qualityprofile.ActiveRuleInheritance.INHERITED) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DbSession(org.sonar.db.DbSession) Collections.singletonList(java.util.Collections.singletonList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) BLOCKER(org.sonar.api.rules.RulePriority.BLOCKER) RulePriority(org.sonar.api.rules.RulePriority) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Collection(java.util.Collection) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) OrgActiveRuleDto(org.sonar.db.qualityprofile.OrgActiveRuleDto) List(java.util.List) MAJOR(org.sonar.api.rules.RulePriority.MAJOR) RuleKey(org.sonar.api.rule.RuleKey) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) MINOR(org.sonar.api.rules.RulePriority.MINOR) TypeValidations(org.sonar.server.util.TypeValidations) TestSystem2(org.sonar.api.impl.utils.TestSystem2) Severity(org.sonar.api.rule.Severity) CRITICAL(org.sonar.api.rules.RulePriority.CRITICAL) RulesProfileDto(org.sonar.db.qualityprofile.RulesProfileDto) IntegerTypeValidation(org.sonar.server.util.IntegerTypeValidation) Nullable(javax.annotation.Nullable) Before(org.junit.Before) QualityProfileChangeEventService(org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService) UserSessionRule(org.sonar.server.tester.UserSessionRule) Collections.emptyMap(java.util.Collections.emptyMap) Tuple(org.assertj.core.groups.Tuple) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test) QualityProfileTesting.newRuleProfileDto(org.sonar.db.qualityprofile.QualityProfileTesting.newRuleProfileDto) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) RuleParamDto(org.sonar.db.rule.RuleParamDto) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) StringTypeValidation(org.sonar.server.util.StringTypeValidation) ActiveRuleInheritance(org.sonar.server.qualityprofile.ActiveRuleInheritance) ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Test(org.junit.Test)

Example 5 with ActiveRuleIndexer

use of org.sonar.server.qualityprofile.index.ActiveRuleIndexer in project sonarqube by SonarSource.

the class QProfileComparisonTest method before.

@Before
public void before() {
    DbClient db = dbTester.getDbClient();
    dbSession = db.openSession(false);
    RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
    ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(db, es.client());
    QualityProfileChangeEventService qualityProfileChangeEventService = mock(QualityProfileChangeEventService.class);
    RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, db, new TypeValidations(singletonList(new IntegerTypeValidation())), userSession);
    qProfileRules = new QProfileRulesImpl(db, ruleActivator, ruleIndex, activeRuleIndexer, qualityProfileChangeEventService);
    comparison = new QProfileComparison(db);
    xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR").getDefinition();
    xooRule2 = RuleTesting.newXooX2().setSeverity("MAJOR").getDefinition();
    db.ruleDao().insert(dbSession, xooRule1);
    db.ruleDao().insert(dbSession, xooRule2);
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("max").setType(RuleParamType.INTEGER.type()));
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("min").setType(RuleParamType.INTEGER.type()));
    left = QualityProfileTesting.newQualityProfileDto().setLanguage("xoo");
    right = QualityProfileTesting.newQualityProfileDto().setLanguage("xoo");
    db.qualityProfileDao().insert(dbSession, left, right);
    dbSession.commit();
}
Also used : ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) QualityProfileChangeEventService(org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService) RuleIndex(org.sonar.server.rule.index.RuleIndex) DbClient(org.sonar.db.DbClient) IntegerTypeValidation(org.sonar.server.util.IntegerTypeValidation) RuleActivator(org.sonar.server.qualityprofile.builtin.RuleActivator) TypeValidations(org.sonar.server.util.TypeValidations) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)9 ActiveRuleIndexer (org.sonar.server.qualityprofile.index.ActiveRuleIndexer)9 RuleIndexer (org.sonar.server.rule.index.RuleIndexer)6 DbClient (org.sonar.db.DbClient)5 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)4 RuleDto (org.sonar.db.rule.RuleDto)3 TypeValidations (org.sonar.server.util.TypeValidations)3 QualityProfileChangeEventService (org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService)2 ActiveRuleIndex (org.sonar.server.qualityprofile.index.ActiveRuleIndex)2 RuleIndex (org.sonar.server.rule.index.RuleIndex)2 IntegerTypeValidation (org.sonar.server.util.IntegerTypeValidation)2 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1