]> source.dussan.org Git - sonarqube.git/commitdiff
IssueShowWS : Complte comments
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 22 Jan 2014 19:36:55 +0000 (20:36 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 22 Jan 2014 19:36:55 +0000 (20:36 +0100)
sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java
sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java
sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json

index 93ff74bafbf16ae0e38d32388f1a94b04f2fdf4d..5e3bd854c0d58cd828dbaa06c4877f026f113c69 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.issue.ActionService;
 import org.sonar.server.issue.IssueService;
 import org.sonar.server.technicaldebt.InternalRubyTechnicalDebtService;
+import org.sonar.server.text.RubyTextService;
 import org.sonar.server.user.UserSession;
 
 import java.util.Arrays;
@@ -47,12 +48,15 @@ public class IssueShowWsHandler implements RequestHandler {
   private final IssueService issueService;
   private final ActionService actionService;
   private final InternalRubyTechnicalDebtService technicalDebtService;
+  private final RubyTextService textService;
 
-  public IssueShowWsHandler(IssueFinder issueFinder, IssueService issueService, ActionService actionService, InternalRubyTechnicalDebtService technicalDebtService) {
+  public IssueShowWsHandler(IssueFinder issueFinder, IssueService issueService, ActionService actionService,
+                            InternalRubyTechnicalDebtService technicalDebtService, RubyTextService textService) {
     this.issueFinder = issueFinder;
     this.issueService = issueService;
     this.actionService = actionService;
     this.technicalDebtService = technicalDebtService;
+    this.textService = textService;
   }
 
   @Override
@@ -150,8 +154,10 @@ public class IssueShowWsHandler implements RequestHandler {
         .prop("key", comment.key())
         .prop("userLogin", userLogin)
         .prop("userName", userLogin != null ? queryResult.user(userLogin).name() : null)
-          // TODO convert markdown to HTML
-          // TODO add date
+        .prop("html", textService.markdownToHtml(comment.markdownText()))
+        // add markdownText ?
+        .prop("creationDate", DateUtils.formatDateTime(comment.createdAt()))
+          // TODO add formatted date
         .endObject();
     }
     json.endArray();
index 7b92002787e9384bea9fcbbab92002de86d69dbe..a802f65d4994316fcf4e81c324a64db8f0f5757f 100644 (file)
@@ -46,6 +46,7 @@ import org.sonar.core.user.DefaultUser;
 import org.sonar.server.issue.ActionService;
 import org.sonar.server.issue.IssueService;
 import org.sonar.server.technicaldebt.InternalRubyTechnicalDebtService;
+import org.sonar.server.text.RubyTextService;
 import org.sonar.server.user.MockUserSession;
 import org.sonar.server.user.UserSession;
 import org.sonar.server.ws.WsTester;
@@ -74,6 +75,9 @@ public class IssueShowWsHandlerTest {
   @Mock
   InternalRubyTechnicalDebtService technicalDebtService;
 
+  @Mock
+  RubyTextService textService;
+
   List<Issue> issues;
   DefaultIssueQueryResult result;
 
@@ -89,7 +93,7 @@ public class IssueShowWsHandlerTest {
     result.addRules(newArrayList(Rule.create("squid", "AvoidCycle").setName("Avoid cycle")));
     when(issueFinder.find(any(IssueQuery.class))).thenReturn(result);
 
-    tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, actionService, technicalDebtService)));
+    tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, actionService, technicalDebtService, textService)));
   }
 
   @Test
@@ -178,11 +182,17 @@ public class IssueShowWsHandlerTest {
   public void show_issue_with_comments() throws Exception {
     Issue issue = createStandardIssue()
       .addComment(
-        new DefaultIssueComment().setKey("COMMENT-ABCD").setMarkdownText("My comment").setUserLogin("john")
+        new DefaultIssueComment()
+          .setKey("COMMENT-ABCD")
+          .setMarkdownText("*My comment*")
+          .setUserLogin("john")
+          .setCreatedAt(DateUtils.parseDateTime("2014-01-23T19:10:03+0100"))
       );
     issues.add(issue);
     result.addUsers(newArrayList((User) new DefaultUser().setLogin("john").setName("John")));
 
+    when(textService.markdownToHtml("*My comment*")).thenReturn("<b>My comment</b>");
+
     MockUserSession.set();
     SimpleRequest request = new SimpleRequest().setParam("key", issue.key());
     tester.execute("show", request).assertJson(getClass(), "show_issue_with_comments.json");
index b4f1160655a7bde2e086c5f42a9d6294f09de043..fbbe26f0e31bd7e0922d6bc1cbf806f96e8499c2 100644 (file)
@@ -12,7 +12,9 @@
       {
         "key": "COMMENT-ABCD",
         "userLogin": "john",
-        "userName": "John"
+        "userName": "John",
+        "html": "<b>My comment</b>",
+        "creationDate": "2014-01-23T19:10:03+0100"
       }
     ]
   }