private Map<String, Map<String, BuiltInQualityProfile>> validateAndClean(BuiltInQualityProfilesDefinition.Context context) { Map<String, Map<String, BuiltInQualityProfile>> profilesByLanguageAndName = context.profilesByLanguageAndName(); profilesByLanguageAndName.entrySet() .removeIf(entry -> { String language = entry.getKey(); if (languages.get(language) == null) { LOGGER.info("Language {} is not installed, related quality profiles are ignored", language); return true; } return false; }); return profilesByLanguageAndName; }
@Test public void bridgeProfileDefinitions() { BuiltInQProfileDefinitionsBridge bridge = new BuiltInQProfileDefinitionsBridge(new Profile1(), new NullProfile(), new ProfileWithError()); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); bridge.define(context); assertThat(context.profilesByLanguageAndName()).hasSize(1); assertThat(context.profilesByLanguageAndName().get("xoo")).hasSize(1); BuiltInQualityProfile profile1 = context.profile("xoo", "Profile 1"); assertThat(profile1).isNotNull(); assertThat(profile1.rules()).hasSize(3); BuiltInActiveRule defaultSeverity = profile1.rule(RuleKey.of("repo1", "defaultSeverity")); assertThat(defaultSeverity).isNotNull(); assertThat(defaultSeverity.overriddenSeverity()).isNull(); assertThat(defaultSeverity.overriddenParams()).isEmpty(); assertThat(profile1.rule(RuleKey.of("repo1", "overrideSeverity")).overriddenSeverity()).isEqualTo(Severity.CRITICAL); assertThat(profile1.rule(RuleKey.of("repo1", "overrideParam")).overriddenParams()) .extracting(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue).containsOnly(tuple("param", "value")); }
@Test public void noProfileDefinitions() { BuiltInQProfileDefinitionsBridge bridge = new BuiltInQProfileDefinitionsBridge(); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); bridge.define(context); assertThat(context.profilesByLanguageAndName()).isEmpty(); }
@Test public void should_create_sonar_way_profile() { ValidationMessages validation = ValidationMessages.create(); BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); new SonarWayProfile().define(context); assertThat(context.profilesByLanguageAndName()).hasSize(1); BuiltInQualityProfilesDefinition.BuiltInQualityProfile profile = context.profile("go", "Sonar way"); assertThat(profile.language()).isEqualTo("go"); assertThat(profile.name()).isEqualTo("Sonar way"); assertThat(profile.rules()).extracting("repoKey").containsOnly(GoRulesDefinition.REPOSITORY_KEY); assertThat(validation.hasErrors()).isFalse(); assertThat(profile.rules()).extracting("ruleKey").contains("S2068"); assertThat(profile.rules()).extracting("ruleKey").doesNotContain("S3801"); }
private Map<String, Map<String, BuiltInQualityProfile>> validateAndClean(BuiltInQualityProfilesDefinition.Context context) { Map<String, Map<String, BuiltInQualityProfile>> profilesByLanguageAndName = context.profilesByLanguageAndName(); profilesByLanguageAndName.entrySet() .removeIf(entry -> { String language = entry.getKey(); if (languages.get(language) == null) { LOGGER.info("Language {} is not installed, related quality profiles are ignored", language); return true; } return false; }); return profilesByLanguageAndName; }
private Map<String, Map<String, BuiltInQualityProfile>> define(Consumer<BuiltInQualityProfilesDefinition.Context> consumer) { BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); new FakeProfile(consumer).define(context); return context.profilesByLanguageAndName(); }