Search in sources :

Example 1 with OVERRIDES

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

the class RuleActivatorTest method reset_overridden_active_rule.

@Test
public void reset_overridden_active_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.MINOR), OVERRIDES);
    ActiveRuleParamDto childActiveRuleParam = activateRuleParamInDb(childActiveRuleDto, ruleParam, "15");
    DbSession session = db.getSession();
    RuleActivation resetRequest = RuleActivation.createReset(rule.getUuid());
    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", "10");
    assertThat(result.get(0).getSeverity()).isEqualTo(Severity.BLOCKER);
    assertThat(result.get(0).getInheritance()).isEqualTo(ActiveRuleInheritance.INHERITED);
}
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)

Example 2 with OVERRIDES

use of org.sonar.server.qualityprofile.ActiveRuleInheritance.OVERRIDES 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)2 Arrays.asList (java.util.Arrays.asList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assert.assertThrows (org.junit.Assert.assertThrows)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 Mockito.mock (org.mockito.Mockito.mock)2 TestSystem2 (org.sonar.api.impl.utils.TestSystem2)2 RuleKey (org.sonar.api.rule.RuleKey)2 Severity (org.sonar.api.rule.Severity)2 RulePriority (org.sonar.api.rules.RulePriority)2 System2 (org.sonar.api.utils.System2)2 DbSession (org.sonar.db.DbSession)2 DbTester (org.sonar.db.DbTester)2 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)2 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)2