use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class CompareActionMediumTest method createActiveRule.
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity(rule.getSeverityString());
db.activeRuleDao().insert(session, activeRule);
return activeRule;
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method verifyHasActiveRuleInDb.
private void verifyHasActiveRuleInDb(ActiveRuleKey activeRuleKey, String expectedSeverity, @Nullable String expectedInheritance, Map<String, String> expectedParams) {
// verify db
boolean found = false;
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, activeRuleKey.qProfile());
for (ActiveRuleDto activeRuleDto : activeRuleDtos) {
if (activeRuleDto.getKey().equals(activeRuleKey)) {
found = true;
assertThat(activeRuleDto.getSeverityString()).isEqualTo(expectedSeverity);
assertThat(activeRuleDto.getInheritance()).isEqualTo(expectedInheritance);
// Dates should be set
assertThat(activeRuleDto.getCreatedAt()).isNotNull();
assertThat(activeRuleDto.getUpdatedAt()).isNotNull();
List<ActiveRuleParamDto> paramDtos = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
assertThat(paramDtos).hasSize(expectedParams.size());
for (Map.Entry<String, String> entry : expectedParams.entrySet()) {
ActiveRuleParamDto paramDto = db.activeRuleDao().selectParamByKeyAndName(activeRuleDto.getKey(), entry.getKey(), dbSession);
assertThat(paramDto).isNotNull();
assertThat(paramDto.getValue()).isEqualTo(entry.getValue());
}
}
}
assertThat(found).as("Rule is not activated in db").isTrue();
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class ShowActionMediumTest method show_rule_when_activated.
@Test
public void show_rule_when_activated() throws Exception {
RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001")).setName("Rule S001").setDescription("Rule S001 <b>description</b>").setDescriptionFormat(Format.HTML).setSeverity(MINOR).setStatus(RuleStatus.BETA).setLanguage("xoo").setType(RuleType.BUG).setCreatedAt(new Date().getTime()).setUpdatedAt(new Date().getTime());
ruleDao.insert(session, ruleDto);
RuleParamDto regexParam = RuleParamDto.createFor(ruleDto).setName("regex").setType("STRING").setDescription("Reg *exp*").setDefaultValue(".*");
ruleDao.insertRuleParam(session, ruleDto, regexParam);
QualityProfileDto profile = QualityProfileDto.createFor("profile").setOrganizationUuid(defaultOrganizationProvider.get().getUuid()).setName("Profile").setLanguage("xoo");
tester.get(QualityProfileDao.class).insert(session, profile);
ActiveRuleDto activeRuleDto = new ActiveRuleDto().setProfileId(profile.getId()).setRuleId(ruleDto.getId()).setSeverity(MINOR).setCreatedAt(new Date().getTime()).setUpdatedAt(new Date().getTime());
tester.get(ActiveRuleDao.class).insert(session, activeRuleDto);
tester.get(ActiveRuleDao.class).insertParam(session, activeRuleDto, new ActiveRuleParamDto().setRulesParameterId(regexParam.getId()).setKey(regexParam.getName()).setValue(".*?"));
session.commit();
session.clearCache();
tester.get(RuleIndexer.class).index();
tester.get(ActiveRuleIndexer.class).index();
WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show").setParam("key", ruleDto.getKey().toString()).setParam("actives", "true");
request.execute().assertJson(getClass(), "show_rule_when_activated.json");
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class SearchActionMediumTest method search_profile_active_rules.
@Test
public void search_profile_active_rules() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
tester.get(QualityProfileDao.class).insert(dbSession, profile);
QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123");
tester.get(QualityProfileDao.class).insert(dbSession, profile2);
dbSession.commit();
RuleDto rule = RuleTesting.newXooX1();
ruleDao.insert(dbSession, rule);
RuleParamDto param = RuleParamDto.createFor(rule).setDefaultValue("some value").setType("string").setDescription("My small description").setName("my_var");
ruleDao.insertRuleParam(dbSession, rule, param);
RuleParamDto param2 = RuleParamDto.createFor(rule).setDefaultValue("other value").setType("integer").setDescription("My small description").setName("the_var");
ruleDao.insertRuleParam(dbSession, rule, param2);
// SONAR-7083
RuleParamDto param3 = RuleParamDto.createFor(rule).setDefaultValue(null).setType("string").setDescription("Empty Param").setName("empty_var");
ruleDao.insertRuleParam(dbSession, rule, param3);
ActiveRuleDto activeRule = newActiveRule(profile, rule);
tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
ActiveRuleDto activeRule2 = newActiveRule(profile2, rule);
tester.get(ActiveRuleDao.class).insert(dbSession, activeRule2);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param).setValue("The VALUE");
tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule2, activeRuleParam);
ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(param2).setValue("The Other Value");
tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule2, activeRuleParam2);
ActiveRuleParamDto activeRuleParam3 = ActiveRuleParamDto.createFor(param3).setValue(null);
tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule2, activeRuleParam3);
dbSession.commit();
ruleIndexer.index();
activeRuleIndexer.index();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.TEXT_QUERY, "x1");
request.setParam(PARAM_ACTIVATION, "true");
request.setParam(PARAM_QPROFILE, profile2.getKey());
request.setParam(WebService.Param.FIELDS, "actives");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_profile_active_rules.json");
tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(PARAM_ACTIVATION, "true").setParam(PARAM_QPROFILE, "unknown_profile").setParam(WebService.Param.FIELDS, "actives").execute().assertJson(this.getClass(), "search_no_rules.json");
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class RegisterRulesMediumTest method update_active_rules_on_param_changes.
@Test
public void update_active_rules_on_param_changes() {
register(new Rules() {
@Override
public void init(RulesDefinition.NewRepository repository) {
RulesDefinition.NewRule x1Rule = repository.createRule("x1").setName("x1 name").setHtmlDescription("x1 desc");
// has default value
x1Rule.createParam("min").setType(RuleParamType.INTEGER).setDefaultValue("5");
// no default value
x1Rule.createParam("format").setType(RuleParamType.STRING);
}
});
// Create profile and activate rule
logInAsQProfileAdministrator();
db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
dbSession.commit();
dbSession.clearCache();
RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
activation.setParameter("format", "txt");
TESTER.get(QProfileService.class).activate(QProfileTesting.XOO_P1_KEY, activation);
// Default value of "min" is changed, "format" is removed, "format2" is added, "max" is added with a default value
register(new Rules() {
@Override
public void init(RulesDefinition.NewRepository repository) {
RulesDefinition.NewRule x1Rule = repository.createRule("x1").setName("x1 name").setHtmlDescription("x1 desc");
x1Rule.createParam("min").setType(RuleParamType.INTEGER).setDefaultValue("6");
x1Rule.createParam("format2").setType(RuleParamType.STRING);
x1Rule.createParam("max").setType(RuleParamType.INTEGER).setDefaultValue("10");
}
});
ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, ActiveRuleKey.of(QProfileTesting.XOO_P1_KEY, RuleTesting.XOO_X1));
List<ActiveRuleParamDto> params = db.activeRuleDao().selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
assertThat(params).hasSize(2);
Map<String, ActiveRuleParamDto> parmsByKey = FluentIterable.from(params).uniqueIndex(ActiveRuleParamToKey.INSTANCE);
// do not change default value on existing active rules -> keep min=5
assertThat(parmsByKey.get("min").getValue()).isEqualTo("5");
// new param with default value
assertThat(parmsByKey.get("max").getValue()).isEqualTo("10");
}
Aggregations