From cc323b14712f52133e7853e131750827df084239 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 14 Jan 2014 11:08:24 +0100 Subject: [PATCH] SONAR-4923 QProfileActiveRuleOperations do not reload the rule -> it's the responsability to the client --- .../QProfileActiveRuleOperations.java | 41 ++++++-------- .../server/qualityprofile/QProfiles.java | 28 +++++++--- .../org/sonar/server/rule/ProfileRules.java | 18 +++++++ .../new_rules_configuration_controller.rb | 14 +++-- .../QProfileActiveRuleOperationsTest.java | 53 ++++--------------- .../server/qualityprofile/QProfilesTest.java | 18 +++++++ .../sonar/server/rule/ProfileRulesTest.java | 15 ++++++ 7 files changed, 108 insertions(+), 79 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java index ceed9901163..e604ce0bc60 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java @@ -37,11 +37,11 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDao; import org.sonar.core.qualityprofile.db.ActiveRuleDto; import org.sonar.core.qualityprofile.db.ActiveRuleParamDto; import org.sonar.core.rule.RuleDao; +import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleParamDto; import org.sonar.server.configuration.ProfilesManager; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.NotFoundException; -import org.sonar.server.rule.ProfileRules; import org.sonar.server.rule.RuleRegistry; import org.sonar.server.user.UserSession; @@ -61,53 +61,50 @@ public class QProfileActiveRuleOperations implements ServerComponent { private final QProfileLookup profileLookup; private final RuleRegistry ruleRegistry; private final ProfilesManager profilesManager; - private final ProfileRules rulesLookup; private final System2 system; public QProfileActiveRuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, QProfileLookup profileLookup, RuleRegistry ruleRegistry, - ProfilesManager profilesManager, ProfileRules rulesLookup) { - this(myBatis, activeRuleDao, ruleDao, profileLookup, ruleRegistry, profilesManager, rulesLookup, System2.INSTANCE); + ProfilesManager profilesManager) { + this(myBatis, activeRuleDao, ruleDao, profileLookup, ruleRegistry, profilesManager, System2.INSTANCE); } @VisibleForTesting QProfileActiveRuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, QProfileLookup profileLookup, RuleRegistry ruleRegistry, - ProfilesManager profilesManager, ProfileRules rulesLookup, System2 system) { + ProfilesManager profilesManager, System2 system) { this.myBatis = myBatis; this.activeRuleDao = activeRuleDao; this.ruleDao = ruleDao; this.profileLookup = profileLookup; this.ruleRegistry = ruleRegistry; this.profilesManager = profilesManager; - this.rulesLookup = rulesLookup; this.system = system; } - public QProfileRule activateRule(int profileId, int ruleId, String severity, UserSession userSession) { + public void activateRule(int profileId, int ruleId, String severity, UserSession userSession) { validatePermission(userSession); validateSeverity(severity); QProfile profile = findProfileNotNull(profileId); - QProfileRule rule = findRuleNotNull(ruleId); + RuleDto rule = findRuleNotNull(ruleId); ActiveRuleDto activeRule = findActiveRule(profileId, ruleId); if (activeRule == null) { - activeRule = createActiveRule(profile, rule, severity, userSession); + createActiveRule(profile.id(), rule.getId(), severity, userSession); } else { updateSeverity(activeRule, severity, userSession); } - return rulesLookup.findByActiveRuleId(activeRule.getId()); } - private ActiveRuleDto createActiveRule(QProfile profile, QProfileRule rule, String severity, UserSession userSession) { + private ActiveRuleDto createActiveRule(int profileId, int ruleId, String severity, UserSession userSession) { SqlSession session = myBatis.openSession(); try { ActiveRuleDto activeRule = new ActiveRuleDto() - .setProfileId(profile.id()) - .setRuleId(rule.id()) + .setProfileId(profileId) + .setRuleId(ruleId) .setSeverity(getSeverityOrdinal(severity)); activeRuleDao.insert(activeRule, session); - List ruleParams = ruleDao.selectParameters(rule.id(), session); + List ruleParams = ruleDao.selectParameters(ruleId, session); List activeRuleParams = newArrayList(); for (RuleParamDto ruleParam : ruleParams) { ActiveRuleParamDto activeRuleParam = new ActiveRuleParamDto() @@ -120,7 +117,7 @@ public class QProfileActiveRuleOperations implements ServerComponent { } session.commit(); - ProfilesManager.RuleInheritanceActions actions = profilesManager.activated(profile.id(), activeRule.getId(), userSession.name()); + ProfilesManager.RuleInheritanceActions actions = profilesManager.activated(profileId, activeRule.getId(), userSession.name()); reindexInheritanceResult(actions, session); return activeRule; @@ -143,12 +140,11 @@ public class QProfileActiveRuleOperations implements ServerComponent { } } - public QProfileRule deactivateRule(int profileId, int ruleId, UserSession userSession) { + public void deactivateRule(int profileId, int ruleId, UserSession userSession) { validatePermission(userSession); ActiveRuleDto activeRule = findActiveRule(profileId, ruleId); deactivateRule(activeRule, userSession); - return rulesLookup.findByRuleId(ruleId); } private void deactivateRule(ActiveRuleDto activeRule, UserSession userSession) { @@ -167,7 +163,7 @@ public class QProfileActiveRuleOperations implements ServerComponent { } } - public QProfileRule updateActiveRuleParam(int activeRuleId, String key, @Nullable String value, UserSession userSession) { + public void updateActiveRuleParam(int activeRuleId, String key, @Nullable String value, UserSession userSession) { validatePermission(userSession); String sanitizedValue = Strings.emptyToNull(value); ActiveRuleParamDto activeRuleParam = findActiveRuleParam(activeRuleId, key); @@ -180,8 +176,6 @@ public class QProfileActiveRuleOperations implements ServerComponent { updateActiveRuleParam(activeRule, activeRuleParam, value, userSession); } // If no active rule param and no value -> do nothing - - return rulesLookup.findByActiveRuleId(activeRuleId); } private void createActiveRuleParam(ActiveRuleDto activeRule, String key, String value, UserSession userSession) { @@ -232,12 +226,11 @@ public class QProfileActiveRuleOperations implements ServerComponent { } } - public QProfileRule revertActiveRule(int activeRuleId, UserSession userSession) { + public void revertActiveRule(int activeRuleId, UserSession userSession) { validatePermission(userSession); ActiveRuleDto activeRule = findActiveRuleNotNull(activeRuleId); revertActiveRule(activeRule, userSession); - return rulesLookup.findByActiveRuleId(activeRule.getId()); } private void revertActiveRule(ActiveRuleDto activeRule, UserSession userSession) { @@ -437,8 +430,8 @@ public class QProfileActiveRuleOperations implements ServerComponent { return profile; } - private QProfileRule findRuleNotNull(int ruleId) { - QProfileRule rule = rulesLookup.findByRuleId(ruleId); + private RuleDto findRuleNotNull(int ruleId) { + RuleDto rule = ruleDao.selectById(ruleId); QProfileValidations.checkRuleIsNotNull(rule); return rule; } diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java index bfba5b2701b..9f26cf0641d 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java @@ -194,6 +194,18 @@ public class QProfiles implements ServerComponent { // PROFILE RULES + public QProfileRule findByRule(int ruleId) { + return rules.findByRuleId(ruleId); + } + + public QProfileRule findByActiveRuleId(int activeRuleId) { + return rules.findByActiveRuleId(activeRuleId); + } + + public QProfileRule findByProfileAndRule(int profileId, int ruleId) { + return rules.findByProfileIdAndRuleId(profileId, ruleId); + } + public ProfileRules.QProfileRuleResult searchProfileRules(ProfileRuleQuery query, Paging paging) { return rules.search(query, paging); } @@ -218,20 +230,20 @@ public class QProfiles implements ServerComponent { return rules.countProfileRules(ProfileRuleQuery.create(profile.id()).setInheritance(QProfileRule.OVERRIDES)); } - public QProfileRule activateRule(int profileId, int ruleId, String severity) { - return activeRuleOperations.activateRule(profileId, ruleId, severity, UserSession.get()); + public void activateRule(int profileId, int ruleId, String severity) { + activeRuleOperations.activateRule(profileId, ruleId, severity, UserSession.get()); } - public QProfileRule deactivateRule(int profileId, int ruleId) { - return activeRuleOperations.deactivateRule(profileId, ruleId, UserSession.get()); + public void deactivateRule(int profileId, int ruleId) { + activeRuleOperations.deactivateRule(profileId, ruleId, UserSession.get()); } - public QProfileRule updateActiveRuleParam(int activeRuleId, String key, @Nullable String value) { - return activeRuleOperations.updateActiveRuleParam(activeRuleId, key, value, UserSession.get()); + public void updateActiveRuleParam(int activeRuleId, String key, @Nullable String value) { + activeRuleOperations.updateActiveRuleParam(activeRuleId, key, value, UserSession.get()); } - public QProfileRule revertActiveRule(int activeRuleId) { - return activeRuleOperations.revertActiveRule(activeRuleId, UserSession.get()); + public void revertActiveRule(int activeRuleId) { + activeRuleOperations.revertActiveRule(activeRuleId, UserSession.get()); } public QProfileRule updateActiveRuleNote(int activeRuleId, String note) { diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java b/sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java index 2026bf23ae1..ff49bb71fab 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java @@ -79,6 +79,24 @@ public class ProfileRules implements ServerExtension { return null; } + @CheckForNull + public QProfileRule findByProfileIdAndRuleId(int profileId, int ruleId) { + Map ruleSource = index.client().prepareGet(INDEX_RULES, TYPE_RULE, Integer.toString(ruleId)) + .execute().actionGet().getSourceAsMap(); + if (ruleSource != null) { + SearchHits activeRuleHits = searchActiveRules(ProfileRuleQuery.create(profileId), newArrayList(ruleId), FIELD_SOURCE, FIELD_PARENT); + long resultSize = activeRuleHits.totalHits(); + if (resultSize > 0) { + if (resultSize == 1) { + return new QProfileRule(ruleSource, activeRuleHits.getAt(0).sourceAsMap()); + } else { + throw new IllegalStateException("There is more than one result."); + } + } + } + return null; + } + @CheckForNull public QProfileRule findByRuleId(int ruleId) { Map ruleSource = index.client().prepareGet(INDEX_RULES, TYPE_RULE, Integer.toString(ruleId)) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb index 415bb2113e6..be5f69479b7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb @@ -119,14 +119,17 @@ class NewRulesConfigurationController < ApplicationController rule = nil profile_id = params[:id].to_i + rule_id = params[:rule_id].to_i call_backend do severity = params[:level] if severity.blank? # deactivate the rule - rule = Internal.quality_profiles.deactivateRule(profile_id, params[:rule_id].to_i) + Internal.quality_profiles.deactivateRule(profile_id, rule_id) + rule = Internal.quality_profiles.findByRule(rule_id) else # activate the rule - rule = Internal.quality_profiles.activateRule(profile_id, params[:rule_id].to_i, severity) + Internal.quality_profiles.activateRule(profile_id, rule_id, severity) + rule = Internal.quality_profiles.findByProfileAndRule(profile_id, rule_id) end end @@ -286,11 +289,14 @@ class NewRulesConfigurationController < ApplicationController require_parameters :param_id, :active_rule_id, :profile_id rule = nil + profile_id = params[:profile_id].to_i + active_rule_id = params[:active_rule_id].to_i call_backend do - rule = Internal.quality_profiles.updateActiveRuleParam(params[:active_rule_id].to_i, params[:param_id], params[:value]) + Internal.quality_profiles.updateActiveRuleParam(active_rule_id, params[:param_id], params[:value]) + rule = Internal.quality_profiles.findByActiveRuleId(active_rule_id) end - profile = Internal.quality_profiles.profile(params[:profile_id].to_i) + profile = Internal.quality_profiles.profile(profile_id) parent_profile = Internal.quality_profiles.parent(profile) render :partial => 'rule', :locals => {:rule => rule, :profile => profile, :parent_profile => parent_profile} end diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperationsTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperationsTest.java index a1488d115f5..ad48b14d8bc 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperationsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperationsTest.java @@ -40,11 +40,11 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDao; import org.sonar.core.qualityprofile.db.ActiveRuleDto; import org.sonar.core.qualityprofile.db.ActiveRuleParamDto; import org.sonar.core.rule.RuleDao; +import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleParamDto; import org.sonar.server.configuration.ProfilesManager; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; -import org.sonar.server.rule.ProfileRules; import org.sonar.server.rule.RuleRegistry; import org.sonar.server.user.MockUserSession; import org.sonar.server.user.UserSession; @@ -85,9 +85,6 @@ public class QProfileActiveRuleOperationsTest { @Mock ProfilesManager profilesManager; - @Mock - ProfileRules rulesLookup; - @Mock System2 system; @@ -112,16 +109,13 @@ public class QProfileActiveRuleOperationsTest { } }).when(activeRuleDao).insert(any(ActiveRuleDto.class), any(SqlSession.class)); - operations = new QProfileActiveRuleOperations(myBatis, activeRuleDao, ruleDao, profileLookup, ruleRegistry, profilesManager, rulesLookup, system); + operations = new QProfileActiveRuleOperations(myBatis, activeRuleDao, ruleDao, profileLookup, ruleRegistry, profilesManager, system); } @Test public void fail_to_activate_rule_without_profile_admin_permission() throws Exception { QProfile profile = new QProfile().setId(1).setName("Default").setLanguage("java"); when(profileLookup.profile(1)).thenReturn(profile); - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); try { operations.activateRule(1, 10, Severity.CRITICAL, unauthorizedUserSession); @@ -135,11 +129,8 @@ public class QProfileActiveRuleOperationsTest { @Test public void activate_rule() throws Exception { - QProfile profile = new QProfile().setId(1).setName("Default").setLanguage("java"); - when(profileLookup.profile(1)).thenReturn(profile); - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); + when(profileLookup.profile(1)).thenReturn(new QProfile().setId(1).setName("Default").setLanguage("java")); + when(ruleDao.selectById(10)).thenReturn(new RuleDto().setId(10)); when(ruleDao.selectParameters(eq(10), eq(session))).thenReturn(newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10"))); final int idActiveRuleToUpdate = 42; @@ -169,11 +160,8 @@ public class QProfileActiveRuleOperationsTest { @Test public void update_severity() throws Exception { - QProfile profile = new QProfile().setId(1).setName("Default").setLanguage("java"); - when(profileLookup.profile(1)).thenReturn(profile); - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); + when(profileLookup.profile(1)).thenReturn(new QProfile().setId(1).setName("Default").setLanguage("java")); + when(ruleDao.selectById(10)).thenReturn(new RuleDto().setId(10)); ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); when(activeRuleDao.selectByProfileAndRule(1, 10)).thenReturn(activeRule); @@ -190,11 +178,8 @@ public class QProfileActiveRuleOperationsTest { @Test public void fail_to_update_severity_on_invalid_severity() throws Exception { - QProfile profile = new QProfile().setId(1).setName("Default").setLanguage("java"); - when(profileLookup.profile(1)).thenReturn(profile); - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); + when(profileLookup.profile(1)).thenReturn(new QProfile().setId(1).setName("Default").setLanguage("java")); + when(ruleDao.selectById(10)).thenReturn(new RuleDto().setId(10)); ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); when(activeRuleDao.selectByProfileAndRule(1, 10)).thenReturn(activeRule); @@ -210,11 +195,8 @@ public class QProfileActiveRuleOperationsTest { @Test public void deactivate_rule() throws Exception { - QProfile profile = new QProfile().setId(1).setName("Default").setLanguage("java"); - when(profileLookup.profile(1)).thenReturn(profile); - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); + when(profileLookup.profile(1)).thenReturn(new QProfile().setId(1).setName("Default").setLanguage("java")); + when(ruleDao.selectById(10)).thenReturn(new RuleDto().setId(10)); ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); when(activeRuleDao.selectByProfileAndRule(1, 10)).thenReturn(activeRule); when(profilesManager.deactivated(eq(1), anyInt(), eq("Nicolas"))).thenReturn(new ProfilesManager.RuleInheritanceActions()); @@ -231,9 +213,6 @@ public class QProfileActiveRuleOperationsTest { @Test public void create_active_rule_param() throws Exception { - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); when(activeRuleDao.selectById(5)).thenReturn(activeRule); RuleParamDto ruleParam = new RuleParamDto().setRuleId(10).setName("max").setDefaultValue("20").setType(PropertyType.INTEGER.name()); @@ -256,9 +235,6 @@ public class QProfileActiveRuleOperationsTest { @Test public void fail_to_create_active_rule_if_no_rule_param() throws Exception { - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); when(activeRuleDao.selectById(5)).thenReturn(activeRule); when(ruleDao.selectParamByRuleAndKey(10, "max", session)).thenReturn(null); @@ -275,9 +251,6 @@ public class QProfileActiveRuleOperationsTest { @Test public void fail_to_create_active_rule_if_type_is_invalid() throws Exception { - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); when(activeRuleDao.selectById(5)).thenReturn(activeRule); RuleParamDto ruleParam = new RuleParamDto().setRuleId(10).setName("max").setDefaultValue("20").setType(PropertyType.INTEGER.name()); @@ -295,9 +268,6 @@ public class QProfileActiveRuleOperationsTest { @Test public void update_active_rule_param() throws Exception { - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); when(activeRuleDao.selectById(5)).thenReturn(activeRule); RuleParamDto ruleParam = new RuleParamDto().setRuleId(10).setName("max").setDefaultValue("20").setType(PropertyType.INTEGER.name()); @@ -322,9 +292,6 @@ public class QProfileActiveRuleOperationsTest { @Test public void remove_active_rule_param() throws Exception { - QProfileRule rule = mock(QProfileRule.class); - when(rule.id()).thenReturn(10); - when(rulesLookup.findByRuleId(10)).thenReturn(rule); ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1); when(activeRuleDao.selectById(5)).thenReturn(activeRule); RuleParamDto ruleParam = new RuleParamDto().setRuleId(10).setName("max").setDefaultValue("20").setType(PropertyType.INTEGER.name()); diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java index 14bf2e185c4..9f6ccc1803c 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java @@ -300,6 +300,24 @@ public class QProfilesTest { verify(rules, never()).findByActiveRuleId(anyInt()); } + @Test + public void find_by_rule() throws Exception { + qProfiles.findByRule(1); + verify(rules).findByRuleId(1); + } + + @Test + public void find_by_active_rule() throws Exception { + qProfiles.findByActiveRuleId(1); + verify(rules).findByActiveRuleId(1); + } + + @Test + public void find_by_profile_an_rule() throws Exception { + qProfiles.findByProfileAndRule(1, 2); + verify(rules).findByProfileIdAndRuleId(1, 2); + } + @Test public void search_active_rules() throws Exception { final int profileId = 42; diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ProfileRulesTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ProfileRulesTest.java index d65a7275095..ac2ffe92dd9 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule/ProfileRulesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule/ProfileRulesTest.java @@ -97,6 +97,21 @@ public class ProfileRulesTest { assertThat(profileRules.findByActiveRuleId(9999)).isNull(); } + @Test + public void find_by_profile_id_and_rule_id() { + // Rules on profiles + QProfileRule rule = profileRules.findByProfileIdAndRuleId(1, 759); + assertThat(rule).isNotNull(); + assertThat(rule.key()).isEqualTo("UnusedNullCheckInEquals"); + assertThat(rule.severity()).isEqualTo(Severity.MAJOR); + + // Rules on no profiles + assertThat(profileRules.findByProfileIdAndRuleId(1, 944)).isNull(); + + // Not existing rule + assertThat(profileRules.findByProfileIdAndRuleId(1, 99999)).isNull(); + } + @Test public void find_profile_rules() { Paging paging = Paging.create(10, 1); -- 2.39.5