Search in sources :

Example 16 with NewBuiltInQualityProfile

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);
}
Also used : NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Test(org.junit.Test)

Example 17 with NewBuiltInQualityProfile

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");
    });
}
Also used : NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Test(org.junit.Test)

Example 18 with NewBuiltInQualityProfile

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");
}
Also used : BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Consumer(java.util.function.Consumer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RuleKey(org.sonar.api.rule.RuleKey) BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) Test(org.junit.Test) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) ExpectedException(org.junit.rules.ExpectedException) NewBuiltInActiveRule(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Map(java.util.Map) Test(org.junit.Test)

Example 19 with NewBuiltInQualityProfile

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]");
}
Also used : BuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) NewBuiltInActiveRule(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Map(java.util.Map) Test(org.junit.Test)

Example 20 with NewBuiltInQualityProfile

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);
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Test(org.junit.Test)

Aggregations

NewBuiltInQualityProfile (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile)24 Test (org.junit.Test)22 BuiltInQualityProfilesDefinition (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition)19 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)14 ActiveRuleChange (org.sonar.server.qualityprofile.ActiveRuleChange)11 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)10 OrgActiveRuleDto (org.sonar.db.qualityprofile.OrgActiveRuleDto)10 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)10 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)4 RuleParamDto (org.sonar.db.rule.RuleParamDto)4 Map (java.util.Map)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)2 RuleKey (org.sonar.api.rule.RuleKey)2 BuiltInActiveRule (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInActiveRule)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