use of org.sonar.server.util.TypeValidations 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);
}
use of org.sonar.server.util.TypeValidations 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();
}
use of org.sonar.server.util.TypeValidations in project sonarqube by SonarSource.
the class ChangeParentActionTest method setUp.
@Before
public void setUp() {
dbClient = db.getDbClient();
dbSession = db.getSession();
EsClient esClient = es.client();
ruleIndex = new RuleIndex(esClient, System2.INSTANCE);
ruleIndexer = new RuleIndexer(esClient, dbClient);
activeRuleIndexer = new ActiveRuleIndexer(dbClient, esClient);
TypeValidations typeValidations = new TypeValidations(Collections.emptyList());
RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, dbClient, typeValidations, userSession);
qProfileTree = new QProfileTreeImpl(dbClient, ruleActivator, System2.INSTANCE, activeRuleIndexer, mock(QualityProfileChangeEventService.class));
ChangeParentAction underTest = new ChangeParentAction(dbClient, qProfileTree, new Languages(), new QProfileWsSupport(dbClient, userSession), userSession);
ws = new WsActionTester(underTest);
userSession.logIn().addPermission(ADMINISTER_QUALITY_PROFILES);
}
Aggregations