]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4923 QProfileActiveRuleOperations do not reload the rule -> it's the responsabi...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 14 Jan 2014 10:08:24 +0000 (11:08 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 14 Jan 2014 10:08:24 +0000 (11:08 +0100)
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperations.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
sonar-server/src/main/java/org/sonar/server/rule/ProfileRules.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileActiveRuleOperationsTest.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java
sonar-server/src/test/java/org/sonar/server/rule/ProfileRulesTest.java

index ceed9901163bd64efd63e6fbcafc803cb934792f..e604ce0bc6032ef12bbbdea2a71ab5d9cdabefed 100644 (file)
@@ -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<RuleParamDto> ruleParams = ruleDao.selectParameters(rule.id(), session);
+      List<RuleParamDto> ruleParams = ruleDao.selectParameters(ruleId, session);
       List<ActiveRuleParamDto> 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;
   }
index bfba5b2701bb8ded7ee1a51966d88332c50e160c..9f26cf0641dd7259093cff4e92092ced7f47f75a 100644 (file)
@@ -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) {
index 2026bf23ae19eb6a1bb218d01871dd41203aaf1f..ff49bb71fab4a45947b0edf14422c77c9f456310 100644 (file)
@@ -79,6 +79,24 @@ public class ProfileRules implements ServerExtension {
     return null;
   }
 
+  @CheckForNull
+  public QProfileRule findByProfileIdAndRuleId(int profileId, int ruleId) {
+    Map<String, Object> 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<String, Object> ruleSource = index.client().prepareGet(INDEX_RULES, TYPE_RULE, Integer.toString(ruleId))
index 415bb2113e6f3ec03518cbd12e4219f1286d9a65..be5f69479b79a7d9ddbee50af6240ff46f7a1d54 100644 (file)
@@ -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
index a1488d115f580e7f89f8d4a66bf25d7f36914be7..ad48b14d8bc603972c1180e5196fdad3d9dc0547 100644 (file)
@@ -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());
index 14bf2e185c41a35fececdd42a1160d27cccdcbfc..9f6ccc1803c8a8c024337cf34d71b921447d3917 100644 (file)
@@ -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;
index d65a72750954645975f7abd3e6ad18c14c786f56..ac2ffe92dd98e6739438b9dbd5a3df87ddd0f870 100644 (file)
@@ -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);