From c3566e58ecc041f7ec0ef5c1c7d47f77df667b33 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Fri, 23 May 2014 11:19:36 +0200 Subject: [PATCH] SONAR-5007 - Added assertions for QualityProfile Registration --- .../persistence/ActiveRuleDao.java | 22 +++++++++++++++++++ .../ActiveRuleServiceMediumTest.java | 10 +++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/ActiveRuleDao.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/ActiveRuleDao.java index be56443888e..1d525c512af 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/ActiveRuleDao.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/ActiveRuleDao.java @@ -166,6 +166,14 @@ public class ActiveRuleDao extends BaseDao findParamsByKey(ActiveRuleKey key, DbSession session) { + Preconditions.checkArgument(key != null, "ActiveRuleKey cannot be null"); + ActiveRuleDto activeRule = this.getByKey(key,session); + return mapper(session).selectParamsByActiveRuleId(activeRule.getId()); + } + + public ActiveRuleParamDto getParamsByKeyAndName(ActiveRuleKey key, String name, DbSession session) { + Preconditions.checkArgument(key != null, "ActiveRuleKey cannot be null"); + Preconditions.checkArgument(name != null, "ParameterName cannot be null"); + ActiveRuleDto activeRule = this.getByKey(key,session); + return mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), name); + } + + public List findParamsByActiveRule(ActiveRuleDto dto, DbSession session) { Preconditions.checkArgument(dto.getId() != null, "ActiveRule is not persisted"); return mapper(session).selectParamsByActiveRuleId(dto.getId()); diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java index da6e03b5be0..ab100038911 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java @@ -162,10 +162,16 @@ public class ActiveRuleServiceMediumTest { public void update_activation_but_new_parameter() throws Exception { // initial activation grantPermission(); - RuleActivation activation = new RuleActivation(ActiveRuleKey.of(profileKey, RuleKey.of("xoo", "x1"))); + ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profileKey, RuleKey.of("xoo", "x1")); + RuleActivation activation = new RuleActivation(activeRuleKey); activation.setSeverity(Severity.BLOCKER); service.activate(activation); - // TODO delete activeruleparam max + + + assertThat(dbClient.activeRuleDao().getParamsByKeyAndName(activeRuleKey,"max",dbSession)).isNotNull(); + dbClient.activeRuleDao().removeParamByKeyAndName(activeRuleKey,"max",dbSession); + dbSession.commit(); + assertThat(dbClient.activeRuleDao().getParamsByKeyAndName(activeRuleKey,"max",dbSession)).isNull(); // update -- 2.39.5