use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class FakeRule method shouldParseAnnotatedClasses.
@Test
public void shouldParseAnnotatedClasses() {
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
NewBuiltInQualityProfile newProfile = context.createBuiltInQualityProfile("Foo way", "java");
new BuiltInQualityProfileAnnotationLoader().load(newProfile, "squid", FakeRule.class, RuleNoProfile.class);
newProfile.done();
assertThat(context.profile("java", "Foo way").rule(RuleKey.of("squid", "fake")).overriddenSeverity()).isEqualTo(Severity.BLOCKER);
}
use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class BuiltInQualityProfilesDefinitionTest method createProfileWithDuplicateRules.
@Test
public void createProfileWithDuplicateRules() {
define(c -> {
NewBuiltInQualityProfile profile = c.createBuiltInQualityProfile("Foo", "xoo");
profile.activateRule("repo", "rule");
assertThatThrownBy(() -> profile.activateRule("repo", "rule")).isInstanceOf(IllegalArgumentException.class).hasMessage("The rule 'repo:rule' is already activated");
});
}
use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class BuiltInQualityProfilesDefinitionTest method createProfileWithRules.
@Test
public void createProfileWithRules() {
Map<String, Map<String, BuiltInQualityProfile>> profiles = define(c -> {
NewBuiltInQualityProfile profile = c.createBuiltInQualityProfile("Foo", "xoo");
profile.activateRule("repo", "ruleWithoutParam");
profile.activateRule("repo", "ruleWithSeverity").overrideSeverity("CRITICAL");
profile.activateRule("repo", "ruleWithParam").overrideParam("param", "value");
profile.done();
});
assertThat(profiles).containsOnlyKeys("xoo");
assertThat(profiles.get("xoo")).containsOnlyKeys("Foo");
BuiltInQualityProfile profile = profiles.get("xoo").get("Foo");
assertThat(profile.name()).isEqualTo("Foo");
assertThat(profile.language()).isEqualTo("xoo");
assertThat(profile.isDefault()).isFalse();
assertThat(profile.rules()).extracting(BuiltInQualityProfilesDefinition.BuiltInActiveRule::repoKey, BuiltInQualityProfilesDefinition.BuiltInActiveRule::ruleKey, BuiltInQualityProfilesDefinition.BuiltInActiveRule::overriddenSeverity, r -> r.overriddenParams().size()).containsOnly(tuple("repo", "ruleWithoutParam", null, 0), tuple("repo", "ruleWithSeverity", "CRITICAL", 0), tuple("repo", "ruleWithParam", null, 1));
assertThat(profile.rule(RuleKey.of("repo", "ruleWithParam")).overriddenParam("param").key()).isEqualTo("param");
assertThat(profile.rule(RuleKey.of("repo", "ruleWithParam")).overriddenParam("param").overriddenValue()).isEqualTo("value");
}
use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class BuiltInQualityProfilesDefinitionTest method sanityEqualCheck.
@Test
public void sanityEqualCheck() {
Map<String, Map<String, BuiltInQualityProfile>> profiles = define(c -> {
NewBuiltInQualityProfile profile1 = c.createBuiltInQualityProfile("Foo1", "xoo");
NewBuiltInActiveRule rule = profile1.activateRule("repo", "rule");
profile1.done();
NewBuiltInQualityProfile profile2 = c.createBuiltInQualityProfile("Foo2", "xoo");
profile2.done();
NewBuiltInQualityProfile profile3 = c.createBuiltInQualityProfile("Foo1", "xoo2");
profile3.done();
assertThat(profile1).isNotNull();
assertThat(profile1).isNotEqualTo(profile2);
assertThat(profile1).isNotEqualTo(profile3);
assertThat(profile1.hashCode()).isNotEqualTo(profile2.hashCode());
assertThat(profile1.name()).isNotEqualTo("Foo");
assertThat(profile1.toString()).hasToString("NewBuiltInQualityProfile{name='Foo1', language='xoo', default='false'}");
assertThat(rule.toString()).hasToString("[repository=repo, key=rule]");
});
BuiltInQualityProfile profile1 = profiles.get("xoo").get("Foo1");
BuiltInQualityProfile profile2 = profiles.get("xoo").get("Foo2");
BuiltInQualityProfile profile3 = profiles.get("xoo2").get("Foo1");
assertThat(profile1).isNotNull().isNotEqualTo(profile2).isNotEqualTo(profile3);
assertThat(profile1.hashCode()).isNotEqualTo(profile2.hashCode());
assertThat(profile1.name()).isNotEqualTo("Foo");
assertThat(profile1.toString()).hasToString("BuiltInQualityProfile{name='Foo1', language='xoo', default='false'}");
assertThat(profile1.rule(RuleKey.of("repo", "rule")).toString()).hasToString("[repository=repo, key=rule]");
}
use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class BuiltInQProfileInsertImplTest method insert_active_rules_with_params.
@Test
public void insert_active_rules_with_params() {
RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo"));
RuleParamDto param1 = db.rules().insertRuleParam(rule1, p -> p.setType(PropertyType.STRING.name()));
RuleParamDto param2 = db.rules().insertRuleParam(rule1, p -> p.setType(PropertyType.STRING.name()));
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("the name", "xoo");
newQp.activateRule(rule1.getRepositoryKey(), rule1.getRuleKey()).overrideSeverity(Severity.CRITICAL);
newQp.done();
BuiltInQProfile builtIn = builtInQProfileRepository.create(context.profile("xoo", "the name"), rule1);
call(builtIn);
verifyTableSize("rules_profiles", 1);
verifyTableSize("org_qprofiles", 1);
verifyTableSize("active_rules", 1);
verifyTableSize("active_rule_parameters", 2);
verifyTableSize("qprofile_changes", 1);
QProfileDto profile = verifyProfileInDb(builtIn);
verifyActiveRuleInDb(profile, rule1, Severity.CRITICAL, param1, param2);
}
Aggregations