From 937a8f396dce8402fd5662f05489ec5a3c654f95 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 22 Jan 2014 20:36:55 +0100 Subject: [PATCH] IssueShowWS : Complte comments --- .../sonar/server/issue/ws/IssueShowWsHandler.java | 12 +++++++++--- .../server/issue/ws/IssueShowWsHandlerTest.java | 14 ++++++++++++-- .../show_issue_with_comments.json | 4 +++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java index 93ff74bafbf..5e3bd854c0d 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java @@ -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(); diff --git a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java index 7b92002787e..a802f65d499 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java @@ -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 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("My comment"); + MockUserSession.set(); SimpleRequest request = new SimpleRequest().setParam("key", issue.key()); tester.execute("show", request).assertJson(getClass(), "show_issue_with_comments.json"); diff --git a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json index b4f1160655a..fbbe26f0e31 100644 --- a/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json +++ b/sonar-server/src/test/resources/org/sonar/server/issue/ws/IssueShowWsHandlerTest/show_issue_with_comments.json @@ -12,7 +12,9 @@ { "key": "COMMENT-ABCD", "userLogin": "john", - "userName": "John" + "userName": "John", + "html": "My comment", + "creationDate": "2014-01-23T19:10:03+0100" } ] } -- 2.39.5