diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-03-02 14:54:04 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-03-02 16:54:55 +0100 |
commit | 1231f960588cb3370443815ceb6215688041e66f (patch) | |
tree | 32b8f4c022b73211047065b2943b8b6b80f98065 | |
parent | b12c36e294f93b101d2c8cca94bd5dc4d0903c50 (diff) | |
download | sonarqube-1231f960588cb3370443815ceb6215688041e66f.tar.gz sonarqube-1231f960588cb3370443815ceb6215688041e66f.zip |
Add search the ability to search for rules by profiles in RubyRuleService
Needed to fix SQALE-269
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java | 5 | ||||
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java | 16 |
2 files changed, 21 insertions, 0 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java index 29d6ef12df3..c90d6c71819 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java @@ -83,6 +83,11 @@ public class RubyRuleService implements ServerComponent, Startable { query.setDebtCharacteristics(RubyUtils.toStrings(params.get("debtCharacteristics"))); query.setHasDebtCharacteristic(RubyUtils.toBoolean(params.get("hasDebtCharacteristic"))); query.setSortField(RuleNormalizer.RuleField.NAME); + String profile = Strings.emptyToNull((String) params.get("profile")); + if (profile != null) { + query.setQProfileKey(profile); + query.setActivation(true); + } QueryContext options = new QueryContext(); Integer pageSize = RubyUtils.toInteger(params.get("pageSize")); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java index 62cb7da516a..777f540f15d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java @@ -103,12 +103,28 @@ public class RubyRuleServiceTest { assertThat(ruleQueryCaptor.getValue().getTags()).containsOnly("tag1", "tag2"); assertThat(ruleQueryCaptor.getValue().getDebtCharacteristics()).containsOnly("char1", "char2"); assertThat(ruleQueryCaptor.getValue().getHasDebtCharacteristic()).isTrue(); + assertThat(ruleQueryCaptor.getValue().getQProfileKey()).isNull(); + assertThat(ruleQueryCaptor.getValue().getActivation()).isNull(); assertThat(optionsCaptor.getValue().getLimit()).isEqualTo(40); assertThat(optionsCaptor.getValue().getOffset()).isEqualTo(0); } @Test + public void search_rules_activated_on_a_profile() throws Exception { + when(ruleService.search(any(RuleQuery.class), any(QueryContext.class))).thenReturn(mock(Result.class)); + + HashMap<String, Object> params = newHashMap(); + params.put("profile", "xoo-profile"); + service.find(params); + + verify(ruleService).search(ruleQueryCaptor.capture(), optionsCaptor.capture()); + + assertThat(ruleQueryCaptor.getValue().getQProfileKey()).isEqualTo("xoo-profile"); + assertThat(ruleQueryCaptor.getValue().getActivation()).isTrue(); + } + + @Test public void search_rules_without_page_size_param() throws Exception { when(ruleService.search(any(RuleQuery.class), any(QueryContext.class))).thenReturn(mock(Result.class)); |