]> source.dussan.org Git - sonarqube.git/commitdiff
Add search the ability to search for rules by profiles in RubyRuleService 127/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 2 Mar 2015 13:54:04 +0000 (14:54 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 2 Mar 2015 15:54:55 +0000 (16:54 +0100)
Needed to fix SQALE-269

server/sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java
server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java

index 29d6ef12df31752a71e6f78dfd303b12accb5727..c90d6c718193e9ca7abb5f154bbdeed176fd35ad 100644 (file)
@@ -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"));
index 62cb7da516a9981b05009436c355572a82378800..777f540f15d3168c0ad5dff7048333a0870f7c9b 100644 (file)
@@ -103,11 +103,27 @@ 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));