{"action":"created","comment":{"url":"https://api.github.com/repos/Wikia/pandora/pulls/comments/37892975","id":37892975,"diff_hunk":"@@ -0,0 +1,310 @@\n+package com.wikia.discussionservice.resources;\n+\n+import static io.dropwizard.testing.FixtureHelpers.fixture;\n+\n+import com.wikia.discussionservice.auth.User;\n+import com.wikia.discussionservice.configuration.DiscussionServiceConfiguration;\n+import com.wikia.discussionservice.domain.Forum;\n+import com.wikia.discussionservice.domain.ForumThread;\n+import com.wikia.discussionservice.enums.ResponseGroup;\n+import com.wikia.discussionservice.enums.SortDirection;\n+import com.wikia.discussionservice.enums.SortKey;\n+import com.wikia.discussionservice.services.ThreadService;\n+\n+import io.dropwizard.testing.junit.DropwizardAppRule;\n+\n+import java.util.ArrayList;\n+import java.util.Arrays;\n+import java.util.Collections;\n+import java.util.Map;\n+\n+import javax.ws.rs.client.Client;\n+import javax.ws.rs.client.WebTarget;\n+import javax.ws.rs.core.MultivaluedHashMap;\n+import javax.ws.rs.core.MultivaluedMap;\n+import javax.ws.rs.core.Response;\n+import javax.ws.rs.core.UriBuilder;\n+\n+public class DiscussionThreadHelper {\n+\n+  private static final String FIXTURE_CREATE = \"fixtures/createThread.json\";\n+\n+  public static ForumThread createThread(DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+                                         Client client, Integer siteId, Long forumId,\n+                                         Integer userId) throws Exception {\n+    return createThread(rule, client, siteId, forumId, userId, FIXTURE_CREATE);\n+  }\n+\n+  public static ForumThread createThread(DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+                                         Client client, Integer siteId, Long forumId,\n+                                         Integer userId,\n+                                         String fixtureName) throws Exception {\n+    Integer[] expectedCodes = {Response.Status.CREATED.getStatusCode()};\n+    return createThread(rule, client, siteId, forumId, userId, expectedCodes, fixtureName);\n+  }\n+\n+  public static ForumThread createThread(DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+                                         Client client, Integer siteId, Long forumId,\n+                                         Integer userId,\n+                                         Integer[] expectedCodes) throws Exception {\n+    return createThread(rule, client, siteId, forumId, userId, expectedCodes, FIXTURE_CREATE);\n+  }\n+\n+  public static ForumThread createThread(DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+                                         Client client, Integer siteId, Long forumId,\n+                                         Integer userId, Integer[] expectedCodes,\n+                                         String fixtureName) throws Exception {\n+    UriBuilder uriBuilder = getCreateThreadResourceUrl(rule, siteId, forumId);\n+    MultivaluedMap<String, Object> headerMap = new MultivaluedHashMap<>();\n+    if (userId != null) {\n+      headerMap.put(\"X-Wikia-UserId\", Arrays.asList(userId));\n+    }\n+\n+    String createPost = fixture(fixtureName);\n+\n+    Response response =\n+        RestAssertHelper.assertPostStatus(\n+            expectedCodes, webTarget(client, uriBuilder), createPost, headerMap);\n+\n+    @SuppressWarnings(\"unchecked\")\n+    Map<String, Object> responseMap = response.readEntity(Map.class);\n+    if (responseMap.containsKey(\"id\")) {\n+      return HalResponseHelper.extractThreadFromResponseMap(responseMap);\n+    } else {\n+      return null;\n+    }\n+  }\n+\n+  public static void deleteThread(DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+                                  Client client, Integer siteId, Long threadId, Integer userId)\n+      throws Exception {\n+    Integer[] expectedCodes = {Response.Status.NO_CONTENT.getStatusCode()};\n+    deleteThread(rule, client, siteId, threadId, userId, expectedCodes);\n+  }\n+\n+  public static void deleteThread(DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+                                  Client client, Integer siteId, Long threadId, Integer userId,\n+                                  Integer[] expectedCodes) throws Exception {\n+    UriBuilder uriBuilder = getDeleteThreadResourceUrl(rule, siteId, threadId);\n+    MultivaluedMap<String, Object> headerMap = new MultivaluedHashMap<>();\n+    if (userId != null) {\n+      headerMap.put(\"X-Wikia-UserId\", Collections.singletonList(userId));\n+    }\n+\n+    RestAssertHelper.assertDeleteStatus(expectedCodes, webTarget(client, uriBuilder), headerMap);\n+  }\n+\n+  public static Forum getForum(DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+                               Client client, Integer siteId, Long forumId) {\n+    UriBuilder uriBuilder = getForumResourceUrl(rule, siteId, forumId);\n+\n+    Response response = RestAssertHelper.assertGetStatus(\n+        Response.Status.OK.getStatusCode(), webTarget(client, uriBuilder));\n+\n+    @SuppressWarnings(\"unchecked\")\n+    Map<String, Object> responseMap = response.readEntity(Map.class);\n+    return HalResponseHelper.extractForumFromResponseMap(responseMap);\n+  }\n+\n+  public static UriBuilder getThreadResourceUrl(\n+      DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+      Integer siteId, String resourceType,\n+      Long threadId, Boolean viewableOnly,\n+      String responseGroup) {\n+    return getThreadResourceUrl(rule, siteId, resourceType, threadId, viewableOnly,\n+                                ThreadService.POST_LIMIT_DEFAULT, ThreadService.POST_PAGE_DEFAULT,\n+                                null, responseGroup);\n+  }\n+\n+  public static UriBuilder getThreadResourceUrl(\n+      DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+      Integer siteId, String resourceType,\n+      Long threadId, Boolean viewableOnly,\n+      Integer limit, Integer page, Long pivotId,\n+      String responseGroup) {\n+    return getThreadResourceUrl(rule, siteId, resourceType, threadId, viewableOnly, limit, page,\n+                                pivotId,\n+                                SortKey.CREATION_DATE, SortDirection.DESCENDING, responseGroup);\n+  }\n+\n+  public static UriBuilder getThreadResourceUrl(\n+      DropwizardAppRule<DiscussionServiceConfiguration> rule,\n+      Integer siteId, String resourceType,\n+      Long threadId, Boolean viewableOnly,\n+      Integer limit, Integer page, Long pivotId,\n+      SortKey sortKey, SortDirection sortDirection,\n+      String responseGroup) {\n+    UriBuilder uriBuilder = getResourceUrl(rule).clone()\n+        .resolveTemplate(\"siteId\", siteId)","path":"service/discussion/src/test/java/com/wikia/discussionservice/resources/DiscussionThreadHelper.java","position":138,"original_position":138,"commit_id":"55101bb03e5282f1ef4f69bd335926762d41e9df","original_commit_id":"55101bb03e5282f1ef4f69bd335926762d41e9df","user":{"login":"WikiaTech","id":13279985,"avatar_url":"https://avatars.githubusercontent.com/u/13279985?v=3","gravatar_id":"","url":"https://api.github.com/users/WikiaTech","html_url":"https://github.com/WikiaTech","followers_url":"https://api.github.com/users/WikiaTech/followers","following_url":"https://api.github.com/users/WikiaTech/following{/other_user}","gists_url":"https://api.github.com/users/WikiaTech/gists{/gist_id}","starred_url":"https://api.github.com/users/WikiaTech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WikiaTech/subscriptions","organizations_url":"https://api.github.com/users/WikiaTech/orgs","repos_url":"https://api.github.com/users/WikiaTech/repos","events_url":"https://api.github.com/users/WikiaTech/events{/privacy}","received_events_url":"https://api.github.com/users/WikiaTech/received_events","type":"User","site_admin":false},"body":"![MINOR](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-minor.png) Define a constant instead of duplicating this literal \"siteId\" 4 times. [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](http://nemo.sonarqube.org/coding_rules#rule_key=squid%3AS1192)\n","created_at":"2015-08-25T17:22:27Z","updated_at":"2015-08-25T17:22:27Z","html_url":"https://github.com/Wikia/pandora/pull/409#discussion_r37892975","pull_request_url":"https://api.github.com/repos/Wikia/pandora/pulls/409","_links":{"self":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/comments/37892975"},"html":{"href":"https://github.com/Wikia/pandora/pull/409#discussion_r37892975"},"pull_request":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/409"}}},"pull_request":{"url":"https://api.github.com/repos/Wikia/pandora/pulls/409","id":43218639,"html_url":"https://github.com/Wikia/pandora/pull/409","diff_url":"https://github.com/Wikia/pandora/pull/409.diff","patch_url":"https://github.com/Wikia/pandora/pull/409.patch","issue_url":"https://api.github.com/repos/Wikia/pandora/issues/409","number":409,"state":"open","locked":false,"title":"DIS-270 Complete delete Implementation + tests","user":{"login":"armonr","id":1141431,"avatar_url":"https://avatars.githubusercontent.com/u/1141431?v=3","gravatar_id":"","url":"https://api.github.com/users/armonr","html_url":"https://github.com/armonr","followers_url":"https://api.github.com/users/armonr/followers","following_url":"https://api.github.com/users/armonr/following{/other_user}","gists_url":"https://api.github.com/users/armonr/gists{/gist_id}","starred_url":"https://api.github.com/users/armonr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/armonr/subscriptions","organizations_url":"https://api.github.com/users/armonr/orgs","repos_url":"https://api.github.com/users/armonr/repos","events_url":"https://api.github.com/users/armonr/events{/privacy}","received_events_url":"https://api.github.com/users/armonr/received_events","type":"User","site_admin":false},"body":"* Integration and service test coverage for delete\r\n* Fix problems caught by tests\r\n* Update sql for getting threads - post not visible to viewer should be filtered out on join\r\n\r\n@jimmordino @jogura ","created_at":"2015-08-24T20:36:53Z","updated_at":"2015-08-25T17:22:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a7c7e437004254d48efcb9fbe8825294b3976dfa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Wikia/pandora/pulls/409/commits","review_comments_url":"https://api.github.com/repos/Wikia/pandora/pulls/409/comments","review_comment_url":"https://api.github.com/repos/Wikia/pandora/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Wikia/pandora/issues/409/comments","statuses_url":"https://api.github.com/repos/Wikia/pandora/statuses/55101bb03e5282f1ef4f69bd335926762d41e9df","head":{"label":"Wikia:DIS-270","ref":"DIS-270","sha":"55101bb03e5282f1ef4f69bd335926762d41e9df","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":26663749,"name":"pandora","full_name":"Wikia/pandora","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/pandora","description":"API Service","fork":false,"url":"https://api.github.com/repos/Wikia/pandora","forks_url":"https://api.github.com/repos/Wikia/pandora/forks","keys_url":"https://api.github.com/repos/Wikia/pandora/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/pandora/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/pandora/teams","hooks_url":"https://api.github.com/repos/Wikia/pandora/hooks","issue_events_url":"https://api.github.com/repos/Wikia/pandora/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/pandora/events","assignees_url":"https://api.github.com/repos/Wikia/pandora/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/pandora/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/pandora/tags","blobs_url":"https://api.github.com/repos/Wikia/pandora/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/pandora/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/pandora/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/pandora/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/pandora/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/pandora/languages","stargazers_url":"https://api.github.com/repos/Wikia/pandora/stargazers","contributors_url":"https://api.github.com/repos/Wikia/pandora/contributors","subscribers_url":"https://api.github.com/repos/Wikia/pandora/subscribers","subscription_url":"https://api.github.com/repos/Wikia/pandora/subscription","commits_url":"https://api.github.com/repos/Wikia/pandora/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/pandora/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/pandora/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/pandora/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/pandora/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/pandora/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/pandora/merges","archive_url":"https://api.github.com/repos/Wikia/pandora/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/pandora/downloads","issues_url":"https://api.github.com/repos/Wikia/pandora/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/pandora/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/pandora/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/pandora/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/pandora/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/pandora/releases{/id}","created_at":"2014-11-15T00:29:06Z","updated_at":"2015-08-18T21:15:19Z","pushed_at":"2015-08-25T17:21:45Z","git_url":"git://github.com/Wikia/pandora.git","ssh_url":"git@github.com:Wikia/pandora.git","clone_url":"https://github.com/Wikia/pandora.git","svn_url":"https://github.com/Wikia/pandora","homepage":null,"size":19679,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":3,"default_branch":"master"}},"base":{"label":"Wikia:DIS-239","ref":"DIS-239","sha":"941815bd208fe0687137b4a54aedad3a360f48f1","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":26663749,"name":"pandora","full_name":"Wikia/pandora","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/pandora","description":"API Service","fork":false,"url":"https://api.github.com/repos/Wikia/pandora","forks_url":"https://api.github.com/repos/Wikia/pandora/forks","keys_url":"https://api.github.com/repos/Wikia/pandora/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/pandora/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/pandora/teams","hooks_url":"https://api.github.com/repos/Wikia/pandora/hooks","issue_events_url":"https://api.github.com/repos/Wikia/pandora/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/pandora/events","assignees_url":"https://api.github.com/repos/Wikia/pandora/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/pandora/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/pandora/tags","blobs_url":"https://api.github.com/repos/Wikia/pandora/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/pandora/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/pandora/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/pandora/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/pandora/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/pandora/languages","stargazers_url":"https://api.github.com/repos/Wikia/pandora/stargazers","contributors_url":"https://api.github.com/repos/Wikia/pandora/contributors","subscribers_url":"https://api.github.com/repos/Wikia/pandora/subscribers","subscription_url":"https://api.github.com/repos/Wikia/pandora/subscription","commits_url":"https://api.github.com/repos/Wikia/pandora/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/pandora/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/pandora/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/pandora/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/pandora/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/pandora/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/pandora/merges","archive_url":"https://api.github.com/repos/Wikia/pandora/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/pandora/downloads","issues_url":"https://api.github.com/repos/Wikia/pandora/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/pandora/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/pandora/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/pandora/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/pandora/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/pandora/releases{/id}","created_at":"2014-11-15T00:29:06Z","updated_at":"2015-08-18T21:15:19Z","pushed_at":"2015-08-25T17:21:45Z","git_url":"git://github.com/Wikia/pandora.git","ssh_url":"git@github.com:Wikia/pandora.git","clone_url":"https://github.com/Wikia/pandora.git","svn_url":"https://github.com/Wikia/pandora","homepage":null,"size":19679,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/409"},"html":{"href":"https://github.com/Wikia/pandora/pull/409"},"issue":{"href":"https://api.github.com/repos/Wikia/pandora/issues/409"},"comments":{"href":"https://api.github.com/repos/Wikia/pandora/issues/409/comments"},"review_comments":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/409/comments"},"review_comment":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/409/commits"},"statuses":{"href":"https://api.github.com/repos/Wikia/pandora/statuses/55101bb03e5282f1ef4f69bd335926762d41e9df"}}}}