]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5885 Fix mapping of htmlDesc attribute to fetch correct fields in ES 96/head
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 18 Feb 2015 09:59:57 +0000 (10:59 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 19 Feb 2015 08:11:23 +0000 (09:11 +0100)
server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWebServiceMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_2_rules_fields.json [new file with mode: 0644]

index b32dcbe9281b1f66015c8fb1db243803a7192cd7..edb54625e5e2a1660cbaa78d0b483351def7ab58 100644 (file)
@@ -78,7 +78,7 @@ public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> {
   }
 
   private void mapDescriptionFields(final MacroInterpreter macroInterpreter) {
-    map("htmlDesc", new Mapper<RuleDoc, RuleMappingContext>() {
+    map("htmlDesc", new IndexMapper<RuleDoc, RuleMappingContext>(RuleNormalizer.RuleField.MARKDOWN_DESCRIPTION.field(), RuleNormalizer.RuleField.HTML_DESCRIPTION.field()) {
       @Override
       public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) {
         if (rule.markdownDescription() != null) {
index 2a72939689214860b6ed21724cdca78c16703526..eca79f58f1c76cb955f99575099465f6422074cd 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.server.rule.ws;
 
+import org.sonar.core.rule.RuleDto.Format;
+
 import com.google.common.collect.ImmutableSet;
 import org.junit.After;
 import org.junit.Before;
@@ -178,6 +180,19 @@ public class RulesWebServiceMediumTest {
     result.assertJson(getClass(), "search_2_rules.json", false);
   }
 
+  @Test
+  public void search_2_rules_with_field_selection() throws Exception {
+    ruleDao.insert(session, RuleTesting.newXooX1());
+    ruleDao.insert(session, RuleTesting.newXooX2().setDescription("A *Xoo* rule").setDescriptionFormat(Format.MARKDOWN));
+    session.commit();
+
+    MockUserSession.set();
+    WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(SearchOptions.PARAM_FIELDS, "name,htmlDesc,mdDesc");
+    WsTester.Result result = request.execute();
+
+    result.assertJson(getClass(), "search_2_rules_fields.json", false);
+  }
+
   @Test
   public void search_debt_rules() throws Exception {
     insertDebtCharacteristics(session);
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_2_rules_fields.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_2_rules_fields.json
new file mode 100644 (file)
index 0000000..6be0655
--- /dev/null
@@ -0,0 +1,15 @@
+{
+  "total": 2, "p": 1, "ps": 100,
+  "rules": [
+    {
+      "key": "xoo:x2",
+      "name": "Rule x2",
+      "mdDesc": "A *Xoo* rule",
+      "htmlDesc": "A <em>Xoo</em> rule"
+    },
+    {
+      "key": "xoo:x1",
+      "name": "Rule x1",
+      "htmlDesc": "Description x1",
+    }
+  ]}