Search in sources :

Example 1 with INHERITED

use of org.sonar.server.qualityprofile.ActiveRuleInheritance.INHERITED in project sonarqube by SonarSource.

the class RuleActivatorTest method request_new_severity_and_param_for_child_rule.

@Test
public void request_new_severity_and_param_for_child_rule() {
    RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER));
    RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10"));
    QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true));
    ActiveRuleDto parentActiveRuleDto = activateRuleInDb(RulesProfileDto.from(parentProfile), rule, RulePriority.valueOf(Severity.BLOCKER), null);
    ActiveRuleParamDto parentActiveRuleParam = activateRuleParamInDb(parentActiveRuleDto, ruleParam, "10");
    QProfileDto childProfile = createChildProfile(parentProfile);
    ActiveRuleDto childActiveRuleDto = activateRuleInDb(RulesProfileDto.from(childProfile), rule, RulePriority.valueOf(Severity.BLOCKER), INHERITED);
    ActiveRuleParamDto childActiveRuleParam = activateRuleParamInDb(childActiveRuleDto, ruleParam, "10");
    DbSession session = db.getSession();
    RuleActivation resetRequest = RuleActivation.create(rule.getUuid(), Severity.MINOR, ImmutableMap.of("min", "15"));
    RuleActivationContext context = new RuleActivationContext.Builder().setProfiles(asList(parentProfile, childProfile)).setBaseProfile(RulesProfileDto.from(childProfile)).setDate(NOW).setDescendantProfilesSupplier((profiles, ruleUuids) -> new Result(emptyList(), emptyList(), emptyList())).setRules(singletonList(rule)).setRuleParams(singletonList(ruleParam)).setActiveRules(asList(parentActiveRuleDto, childActiveRuleDto)).setActiveRuleParams(asList(parentActiveRuleParam, childActiveRuleParam)).build();
    List<ActiveRuleChange> result = underTest.activate(session, resetRequest, context);
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getParameters()).containsEntry("min", "15");
    assertThat(result.get(0).getSeverity()).isEqualTo(Severity.MINOR);
    assertThat(result.get(0).getInheritance()).isEqualTo(OVERRIDES);
}
Also used : INHERITED(org.sonar.server.qualityprofile.ActiveRuleInheritance.INHERITED) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assert.assertThrows(org.junit.Assert.assertThrows) TypeValidations(org.sonar.server.util.TypeValidations) DbSession(org.sonar.db.DbSession) TestSystem2(org.sonar.api.impl.utils.TestSystem2) BadRequestException(org.sonar.server.exceptions.BadRequestException) Collections.singletonList(java.util.Collections.singletonList) Severity(org.sonar.api.rule.Severity) Arrays.asList(java.util.Arrays.asList) RulesProfileDto(org.sonar.db.qualityprofile.RulesProfileDto) ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) IntegerTypeValidation(org.sonar.server.util.IntegerTypeValidation) Nullable(javax.annotation.Nullable) RulePriority(org.sonar.api.rules.RulePriority) QualityProfileChangeEventService(org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) RuleActivation(org.sonar.server.qualityprofile.RuleActivation) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Result(org.sonar.server.qualityprofile.builtin.DescendantProfilesSupplier.Result) ImmutableMap(com.google.common.collect.ImmutableMap) System2(org.sonar.api.utils.System2) Collections.emptyList(java.util.Collections.emptyList) Test(org.junit.Test) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) List(java.util.List) Rule(org.junit.Rule) RuleParamDto(org.sonar.db.rule.RuleParamDto) OVERRIDES(org.sonar.server.qualityprofile.ActiveRuleInheritance.OVERRIDES) RuleKey(org.sonar.api.rule.RuleKey) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) StringTypeValidation(org.sonar.server.util.StringTypeValidation) ActiveRuleInheritance(org.sonar.server.qualityprofile.ActiveRuleInheritance) Mockito.mock(org.mockito.Mockito.mock) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleActivation(org.sonar.server.qualityprofile.RuleActivation) ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Result(org.sonar.server.qualityprofile.builtin.DescendantProfilesSupplier.Result) DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assert.assertThrows (org.junit.Assert.assertThrows)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 Mockito.mock (org.mockito.Mockito.mock)1 TestSystem2 (org.sonar.api.impl.utils.TestSystem2)1 RuleKey (org.sonar.api.rule.RuleKey)1 Severity (org.sonar.api.rule.Severity)1 RulePriority (org.sonar.api.rules.RulePriority)1 System2 (org.sonar.api.utils.System2)1 DbSession (org.sonar.db.DbSession)1 DbTester (org.sonar.db.DbTester)1 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)1 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)1