private BuiltInActiveRule(NewBuiltInActiveRule newBuiltInActiveRule) { this.repoKey = newBuiltInActiveRule.repoKey(); this.ruleKey = newBuiltInActiveRule.ruleKey(); this.overriddenSeverity = newBuiltInActiveRule.overriddenSeverity; Map<String, OverriddenParam> paramsBuilder = new HashMap<>(); for (NewOverriddenParam newParam : newBuiltInActiveRule.getOverriddenParams()) { paramsBuilder.put(newParam.key, new OverriddenParam(newParam)); } this.overriddenParams = Collections.unmodifiableMap(paramsBuilder); }
@Test public void test_built_in_quality_profile() { BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); underTest.define(context); BuiltInQualityProfile profile = context.profile("xoo", "test BuiltInQualityProfilesDefinition"); assertThat(profile.isDefault()).isFalse(); assertThat(profile.name()).isEqualTo("test BuiltInQualityProfilesDefinition"); assertThat(profile.language()).isEqualTo("xoo"); assertThat(profile.rules()).hasSize(1); BuiltInQualityProfilesDefinition.BuiltInActiveRule activeRule = profile.rule(RuleKey.of("xoo", "HasTag")); assertThat(activeRule.overriddenSeverity()).isEqualTo("BLOCKER"); assertThat(activeRule.overriddenParams()).hasSize(1); assertThat(activeRule.overriddenParam("tag").overriddenValue()).isEqualTo("TODO"); } }
private BuiltInActiveRule(NewBuiltInActiveRule newBuiltInActiveRule) { this.repoKey = newBuiltInActiveRule.repoKey(); this.ruleKey = newBuiltInActiveRule.ruleKey(); this.overriddenSeverity = newBuiltInActiveRule.overriddenSeverity; Map<String, OverriddenParam> paramsBuilder = new HashMap<>(); for (NewOverriddenParam newParam : newBuiltInActiveRule.getOverriddenParams()) { paramsBuilder.put(newParam.key, new OverriddenParam(newParam)); } this.overriddenParams = Collections.unmodifiableMap(paramsBuilder); }
@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"); }