@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 static RuleActivation convert(BuiltInQProfile.ActiveRule ar) { Map<String, String> params = ar.getBuiltIn().overriddenParams().stream() .collect(MoreCollectors.uniqueIndex(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue)); return RuleActivation.create(ar.getRuleId(), ar.getBuiltIn().overriddenSeverity(), params); }
@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")); }
private ActiveRuleChange insertActiveRule(DbSession dbSession, RulesProfileDto rulesProfileDto, BuiltInQProfile.ActiveRule activeRule, long now) { RuleKey ruleKey = activeRule.getRuleKey(); RuleDefinitionDto ruleDefinitionDto = ruleRepository.getDefinition(ruleKey) .orElseThrow(() -> new IllegalStateException("RuleDefinition not found for key " + ruleKey)); ActiveRuleDto dto = new ActiveRuleDto(); dto.setProfileId(rulesProfileDto.getId()); dto.setRuleId(ruleDefinitionDto.getId()); dto.setKey(ActiveRuleKey.of(rulesProfileDto, ruleDefinitionDto.getKey())); dto.setSeverity(firstNonNull(activeRule.getBuiltIn().overriddenSeverity(), ruleDefinitionDto.getSeverityString())); dto.setUpdatedAt(now); dto.setCreatedAt(now); dbClient.activeRuleDao().insert(dbSession, dto); List<ActiveRuleParamDto> paramDtos = insertActiveRuleParams(dbSession, activeRule, dto); ActiveRuleChange change = new ActiveRuleChange(ActiveRuleChange.Type.ACTIVATED, dto, ruleDefinitionDto); change.setSeverity(dto.getSeverityString()); paramDtos.forEach(paramDto -> change.setParameter(paramDto.getKey(), paramDto.getValue())); return change; }
private static RuleActivation convert(BuiltInQProfile.ActiveRule ar) { Map<String, String> params = ar.getBuiltIn().overriddenParams().stream() .collect(MoreCollectors.uniqueIndex(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue)); return RuleActivation.create(ar.getRuleId(), ar.getBuiltIn().overriddenSeverity(), params); }
private ActiveRuleChange insertActiveRule(DbSession dbSession, RulesProfileDto rulesProfileDto, BuiltInQProfile.ActiveRule activeRule, long now) { RuleKey ruleKey = activeRule.getRuleKey(); RuleDefinitionDto ruleDefinitionDto = ruleRepository.getDefinition(ruleKey) .orElseThrow(() -> new IllegalStateException("RuleDefinition not found for key " + ruleKey)); ActiveRuleDto dto = new ActiveRuleDto(); dto.setProfileId(rulesProfileDto.getId()); dto.setRuleId(ruleDefinitionDto.getId()); dto.setKey(ActiveRuleKey.of(rulesProfileDto, ruleDefinitionDto.getKey())); dto.setSeverity(firstNonNull(activeRule.getBuiltIn().overriddenSeverity(), ruleDefinitionDto.getSeverityString())); dto.setUpdatedAt(now); dto.setCreatedAt(now); dbClient.activeRuleDao().insert(dbSession, dto); List<ActiveRuleParamDto> paramDtos = insertActiveRuleParams(dbSession, activeRule, dto); ActiveRuleChange change = new ActiveRuleChange(ActiveRuleChange.Type.ACTIVATED, dto, ruleDefinitionDto); change.setSeverity(dto.getSeverityString()); paramDtos.forEach(paramDto -> change.setParameter(paramDto.getKey(), paramDto.getValue())); return change; }
@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); }