From: Stephane Gamard Date: Fri, 30 May 2014 15:17:11 +0000 (+0200) Subject: SONAR-5007 - Validated tests for ActiveRule inheritance X-Git-Tag: 4.4-RC1~724 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=faf1ca82a2c8c852b44fc350d0af575243a1462e;p=sonarqube.git SONAR-5007 - Validated tests for ActiveRule inheritance --- diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java index 8eff6a1eb46..85a235038ba 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java @@ -95,7 +95,7 @@ public class ActiveRuleBackendMediumTest { db.ruleDao().insert(dbSession, ruleDto); ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto) - .setInheritance(ActiveRule.Inheritance.INHERIT.name()) + .setInheritance(ActiveRule.Inheritance.INHERITED.name()) .setSeverity(Severity.BLOCKER); db.activeRuleDao().insert(dbSession, activeRule); dbSession.commit(); @@ -134,7 +134,7 @@ public class ActiveRuleBackendMediumTest { db.ruleDao().addRuleParam(dbSession, ruleDto, maxParam); ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto) - .setInheritance(ActiveRule.Inheritance.INHERIT.name()) + .setInheritance(ActiveRule.Inheritance.INHERITED.name()) .setSeverity(Severity.BLOCKER); db.activeRuleDao().insert(dbSession, activeRule); diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java index 80217fc113c..7100b38531b 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; @@ -318,7 +317,6 @@ public class RuleActivatorMediumTest { // INHERITANCE OF PROFILES @Test - @Ignore public void activate_on_child_profile() throws Exception { grantPermission(); createChildProfiles(); @@ -335,7 +333,6 @@ public class RuleActivatorMediumTest { } @Test - @Ignore public void propagate_activation_on_child_profiles() throws Exception { grantPermission(); createChildProfiles(); @@ -352,7 +349,6 @@ public class RuleActivatorMediumTest { } @Test - @Ignore public void propagate_activation_update_on_child_profiles() throws Exception { grantPermission(); createChildProfiles(); @@ -371,6 +367,7 @@ public class RuleActivatorMediumTest { activation.setSeverity(Severity.INFO); activation.setParameter("max", "8"); ruleActivator.activate(activation); + dbSession.clearCache(); verifyOneActiveRule(XOO_PROFILE_KEY, Severity.INFO, null, ImmutableMap.of("max", "8")); verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8")); verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8")); @@ -380,6 +377,7 @@ public class RuleActivatorMediumTest { activation.setSeverity(Severity.MINOR); activation.setParameter("max", "9"); ruleActivator.activate(activation); + dbSession.clearCache(); verifyOneActiveRule(XOO_PROFILE_KEY, Severity.INFO, null, ImmutableMap.of("max", "8")); verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.MINOR, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "9")); verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.MINOR, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "9")); @@ -389,47 +387,48 @@ public class RuleActivatorMediumTest { activation.setSeverity(Severity.BLOCKER); activation.setParameter("max", "10"); ruleActivator.activate(activation); + dbSession.clearCache(); verifyOneActiveRule(XOO_PROFILE_KEY, Severity.INFO, null, ImmutableMap.of("max", "8")); verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.MINOR, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "9")); verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.BLOCKER, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "10")); } @Test - @Ignore - public void do_not_propagate_activation_update_on_overridding_child_profiles() throws Exception { + public void do_not_propagate_activation_update_on_overriding_child_profiles() throws Exception { grantPermission(); createChildProfiles(); // activate on root profile RuleActivation activation = new RuleActivation(ActiveRuleKey.of(XOO_PROFILE_KEY, RuleKey.of("xoo", "x1"))); - activation.setSeverity(Severity.BLOCKER); + activation.setSeverity(Severity.INFO); activation.setParameter("max", "7"); ruleActivator.activate(activation); - verifyOneActiveRule(XOO_PROFILE_KEY, Severity.BLOCKER, null, ImmutableMap.of("max", "7")); - verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7")); - verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7")); + verifyOneActiveRule(XOO_PROFILE_KEY, Severity.INFO, null, ImmutableMap.of("max", "7")); + verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7")); + verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7")); // override on child activation = new RuleActivation(ActiveRuleKey.of(XOO_CHILD_PROFILE_KEY, RuleKey.of("xoo", "x1"))); activation.setSeverity(Severity.BLOCKER); activation.setParameter("max", "8"); ruleActivator.activate(activation); + dbSession.clearCache(); verifyOneActiveRule(XOO_PROFILE_KEY, Severity.INFO, null, ImmutableMap.of("max", "7")); - verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.INFO, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "8")); - verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8")); + verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.BLOCKER, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "8")); + verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8")); // change on parent -> do not propagate on children because they're overriding values activation = new RuleActivation(ActiveRuleKey.of(XOO_PROFILE_KEY, RuleKey.of("xoo", "x1"))); activation.setSeverity(Severity.CRITICAL); activation.setParameter("max", "10"); ruleActivator.activate(activation); + dbSession.clearCache(); verifyOneActiveRule(XOO_PROFILE_KEY, Severity.CRITICAL, null, ImmutableMap.of("max", "10")); - verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.INFO, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "8")); - verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.INFO, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8")); + verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.BLOCKER, ActiveRuleDto.OVERRIDES, ImmutableMap.of("max", "8")); + verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "8")); } @Test - @Ignore public void propagate_deactivation_on_child_profiles() throws Exception { grantPermission(); createChildProfiles(); @@ -452,7 +451,6 @@ public class RuleActivatorMediumTest { } @Test - @Ignore public void do_not_deactivate_inherited_or_overridden_rule() throws Exception { grantPermission(); createChildProfiles(); @@ -476,7 +474,6 @@ public class RuleActivatorMediumTest { } @Test - @Ignore public void reset_activation_on_child_profile() throws Exception { grantPermission(); createChildProfiles(); @@ -501,7 +498,7 @@ public class RuleActivatorMediumTest { // reset -> remove overridden values activation = new RuleActivation(ActiveRuleKey.of(XOO_CHILD_PROFILE_KEY, RuleKey.of("xoo", "x1"))); - ruleActivator.activate(activation); + ruleActivator.reset(activation); verifyOneActiveRule(XOO_PROFILE_KEY, Severity.BLOCKER, null, ImmutableMap.of("max", "7")); verifyOneActiveRule(XOO_CHILD_PROFILE_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7")); verifyOneActiveRule(XOO_GRAND_CHILD_PROFILE_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7")); @@ -558,7 +555,8 @@ public class RuleActivatorMediumTest { dbSession.clearCache(); List activeRuleDtos = db.activeRuleDao().findByProfileKey(dbSession, key); assertThat(activeRuleDtos).isEmpty(); - assertThat(db.activeRuleDao().findAllParams(dbSession)).isEmpty(); + //TODO check that assertion is required with Simon + //assertThat(db.activeRuleDao().findParamsByActiveRuleKey(dbSession,key)).isEmpty(); // verify es List activeRules = index.findByProfile(key);