]> source.dussan.org Git - sonarqube.git/commitdiff
Improve unit test on RuleShowWs
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 24 Jan 2014 12:56:57 +0000 (13:56 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 24 Jan 2014 12:56:57 +0000 (13:56 +0100)
sonar-server/src/main/java/org/sonar/server/rule/ws/RuleShowWsHandler.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RuleShowWsHandlerTest.java
sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleShowWsHandlerTest/show_rule.json
sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleShowWsHandlerTest/show_rule_with_dates.json
sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleShowWsHandlerTest/show_rule_with_note.json
sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleShowWsHandlerTest/show_rule_with_tags.json

index e4485bdc3bbef5545793fdff25c3507ac524117b..0025f68de0bd9d752128d95bd55e1592a12b644f 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.sonar.server.rule.ws;
 
+import com.google.common.base.Strings;
 import org.sonar.api.i18n.I18n;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.ws.Request;
@@ -76,7 +77,7 @@ public class RuleShowWsHandler implements RequestHandler {
   }
 
   private void addNote(Rule rule, JsonWriter json) {
-    if (rule.ruleNote() != null && rule.ruleNote().data() != null) {
+    if (rule.ruleNote() != null && !Strings.isNullOrEmpty(rule.ruleNote().data())) {
       json.prop("noteRaw", rule.ruleNote().data())
         .prop("noteHtml", Markdown.convertToHtml(rule.ruleNote().data()));
     }
index 55d1b0c0fc700f66cfcbfeb6a15ec14b0ebab037..759f83278df476b6f7e09ad9db4b4d63f8505069 100644 (file)
@@ -88,6 +88,33 @@ public class RuleShowWsHandlerTest {
     request.execute().assertJson(getClass(), "show_rule_with_dates.json");
   }
 
+  @Test
+  public void show_rule_with_note() throws Exception {
+    Rule rule = createStandardRule();
+    RuleNote note = mock(RuleNote.class);
+    when(note.data()).thenReturn("*Extended rule description*");
+    when(rule.ruleNote()).thenReturn(note);
+
+    when(rules.findByKey(RuleKey.of("squid", "AvoidCycle"))).thenReturn(rule);
+
+    MockUserSession.set();
+    WsTester.TestRequest request = tester.newRequest("show").setParam("key", rule.ruleKey().toString());
+    request.execute().assertJson(getClass(), "show_rule_with_note.json");
+  }
+
+  @Test
+  public void show_rule_with_tags() throws Exception {
+    Rule rule = createStandardRule();
+    when(rule.adminTags()).thenReturn(ImmutableList.of("complexity"));
+    when(rule.systemTags()).thenReturn(ImmutableList.of("security"));
+
+    when(rules.findByKey(RuleKey.of("squid", "AvoidCycle"))).thenReturn(rule);
+
+    MockUserSession.set();
+    WsTester.TestRequest request = tester.newRequest("show").setParam("key", rule.ruleKey().toString());
+    request.execute().assertJson(getClass(), "show_rule_with_tags.json");
+  }
+
   private Rule create(String repoKey, String key, String name, String description) {
     Rule mockRule = mock(Rule.class);
     when(mockRule.repositoryKey()).thenReturn(repoKey);
@@ -95,11 +122,6 @@ public class RuleShowWsHandlerTest {
     when(mockRule.ruleKey()).thenReturn(RuleKey.of(repoKey, key));
     when(mockRule.name()).thenReturn(name);
     when(mockRule.description()).thenReturn(description);
-    when(mockRule.adminTags()).thenReturn(ImmutableList.of("complexity"));
-    when(mockRule.systemTags()).thenReturn(ImmutableList.of("security"));
-    RuleNote note = mock(RuleNote.class);
-    when(note.data()).thenReturn("*Extended rule description*");
-    when(mockRule.ruleNote()).thenReturn(note);
     return mockRule;
   }
 
index eb2a91294c058c51fd44db84ca45dd6d51799848..0dc7c76bbc22dd1c63634a4a104f92756d4f0f85 100644 (file)
@@ -3,9 +3,7 @@
     "key": "squid:AvoidCycle",
     "name": "Avoid cycle",
     "description": "Avoid cycle between packages",
-    "noteRaw": "*Extended rule description*",
-    "noteHtml": "<em>Extended rule description</em>",
-    "tags": ["complexity"],
-    "sysTags": ["security"]
+    "tags": [],
+    "sysTags": []
   }
 }
index 123118673fae522a3cd6e2ac93502f4e43d258af..da3388c39372d8cc68a7536ae7179bec480568c8 100644 (file)
@@ -3,13 +3,11 @@
     "key": "squid:AvoidCycle",
     "name": "Avoid cycle",
     "description": "Avoid cycle between packages",
-    "noteRaw": "*Extended rule description*",
-    "noteHtml": "<em>Extended rule description</em>",
     "createdAt": "2014-01-22T19:10:03+0100",
     "fCreatedAt": "Jan 22, 2014 10:03 AM",
     "updatedAt": "2014-01-23T19:10:03+0100",
     "fUpdatedAt": "Jan 23, 2014 10:03 AM",
-    "tags": ["complexity"],
-    "sysTags": ["security"]
+    "tags": [],
+    "sysTags": []
   }
 }
index 44911576d459de26ae4620f9ad97d8eedd2c74e1..68f69c10fdf0e3744176e4a43fdcc2a16db2f9c9 100644 (file)
@@ -5,7 +5,7 @@
     "description": "Avoid cycle between packages",
     "noteRaw": "*Extended rule description*",
     "noteHtml": "<em>Extended rule description</em>",
-    "tags": ["Complexity"],
-    "sysTags": ["Security"]
+    "tags": [],
+    "sysTags": []
   }
 }
index 44911576d459de26ae4620f9ad97d8eedd2c74e1..545f7c8638dbcac9cd76d2e17d15bc29688d0b3b 100644 (file)
@@ -3,9 +3,7 @@
     "key": "squid:AvoidCycle",
     "name": "Avoid cycle",
     "description": "Avoid cycle between packages",
-    "noteRaw": "*Extended rule description*",
-    "noteHtml": "<em>Extended rule description</em>",
-    "tags": ["Complexity"],
-    "sysTags": ["Security"]
+    "tags": ["complexity"],
+    "sysTags": ["security"]
   }
 }