{"action":"created","comment":{"url":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/comments/27146079","id":27146079,"diff_hunk":"@@ -0,0 +1,127 @@\n+package jenkins.plugins.logstash.persistence;\n+\n+import org.apache.http.client.methods.CloseableHttpResponse;\n+import org.apache.http.client.methods.HttpPost;\n+import org.apache.http.entity.StringEntity;\n+import org.apache.http.impl.client.HttpClientBuilder;\n+import org.apache.http.impl.client.CloseableHttpClient;\n+import org.junit.After;\n+import org.junit.Before;\n+import org.junit.Test;\n+import org.junit.runner.RunWith;\n+import org.mockito.Matchers;\n+import org.mockito.Mock;\n+import org.mockito.runners.MockitoJUnitRunner;\n+\n+import java.io.PrintStream;\n+import java.net.SocketException;\n+\n+import static org.junit.Assert.assertEquals;\n+import static org.mockito.Mockito.*;\n+\n+@RunWith(MockitoJUnitRunner.class)\n+public class ElasticSearchDaoTest {\n+  ElasticSearchDao dao;\n+  @Mock HttpClientBuilder mockClientBuilder;\n+  @Mock CloseableHttpClient mockHttpClient;\n+  @Mock HttpPost mockPost;\n+  @Mock CloseableHttpResponse mockResponse;\n+  @Mock PrintStream mockLogger;\n+\n+  @Before\n+  public void before() throws Exception {\n+    int port = (int) (Math.random() * 1000);\n+    dao = new ElasticSearchDao(\"localhost\", port, \"logstash\", \"username\", \"password\");\n+\n+    // Note that we can't run these tests in parallel\n+    dao.clientBuilder = mockClientBuilder;\n+\n+    when(mockClientBuilder.build()).thenReturn(mockHttpClient);\n+\n+    when(mockHttpClient.execute(mockPost)).thenReturn(mockResponse);\n+  }\n+\n+  @After\n+  public void after() throws Exception {\n+    verifyNoMoreInteractions(mockClientBuilder);\n+    verifyNoMoreInteractions(mockHttpClient);\n+    verifyNoMoreInteractions(mockPost);\n+    verifyNoMoreInteractions(mockLogger);\n+  }\n+\n+  @Test(expected = IllegalArgumentException.class)\n+  public void constructorFailNullHost() throws Exception {\n+    try {\n+      new ElasticSearchDao(null, 8200, \"logstash\", \"username\", \"password\");\n+    } catch (IllegalArgumentException e) {\n+      assertEquals(\"Wrong error message was thrown\", \"host name is required\", e.getMessage());\n+      throw e;\n+    }\n+  }\n+\n+  @Test(expected = IllegalArgumentException.class)\n+  public void constructorFailEmptyHost() throws Exception {\n+    try {\n+      new ElasticSearchDao(\" \", 8200, \"logstash\", \"username\", \"password\");\n+    } catch (IllegalArgumentException e) {\n+      assertEquals(\"Wrong error message was thrown\", \"host name is required\", e.getMessage());\n+      throw e;\n+    }\n+  }\n+\n+  @Test(expected = IllegalArgumentException.class)\n+  public void constructorFailNullKey() throws Exception {\n+    try {\n+      new ElasticSearchDao(\"localhost\", 8200, null, \"username\", \"password\");\n+    } catch (IllegalArgumentException e) {\n+      assertEquals(\"Wrong error message was thrown\", \"elastic index name is required\", e.getMessage());\n+      throw e;\n+    }\n+  }\n+\n+  @Test(expected = IllegalArgumentException.class)\n+  public void constructorFailEmptyKey() throws Exception {\n+    try {\n+      new ElasticSearchDao(\"localhost\", 8200, \" \", \"username\", \"password\");\n+    } catch (IllegalArgumentException e) {\n+      assertEquals(\"Wrong error message was thrown\", \"elastic index name is required\", e.getMessage());\n+      throw e;\n+    }\n+  }\n+\n+  @Test\n+  public void constructorSuccess1() throws Exception {\n+    // Unit under test\n+    dao = new ElasticSearchDao(\"localhost\", 8200, \"logstash\", \"username\", \"password\");\n+\n+    // Verify results\n+    assertEquals(\"Wrong host name\", \"localhost\", dao.host);\n+    assertEquals(\"Wrong port\", 8200, dao.port);\n+    assertEquals(\"Wrong key\", \"logstash\", dao.key);\n+    assertEquals(\"Wrong password\", \"password\", dao.password);\n+  }\n+\n+  @Test\n+  public void constructorSuccess2() throws Exception {\n+    // Unit under test\n+    dao = new ElasticSearchDao(\"localhost\", 8200, \"jenkins/logstash\", \"username\", \"password\");\n+\n+    // Verify results\n+    assertEquals(\"Wrong host name\", \"localhost\", dao.host);\n+    assertEquals(\"Wrong port\", 8200, dao.port);\n+    assertEquals(\"Wrong key\", \"jenkins/logstash\", dao.key);\n+    assertEquals(\"Wrong password\", \"password\", dao.password);\n+  }\n+\n+  @Test\n+  public void constructorSuccess3() throws Exception {\n+    // Unit under test\n+    dao = new ElasticSearchDao(\"localhost\", 8200, \"/jenkins//logstash/\", \"username\", \"password\");\n+\n+    // Verify results\n+    assertEquals(\"Wrong host name\", \"localhost\", dao.host);\n+    assertEquals(\"Wrong port\", 8200, dao.port);\n+    assertEquals(\"Wrong key\", \"/jenkins//logstash/\", dao.key);\n+    assertEquals(\"Wrong password\", \"password\", dao.password);\n+  }\n+}","path":"src/test/java/jenkins/plugins/logstash/persistence/ElasticSearchDaoTest.java","position":127,"original_position":127,"commit_id":"504798096bebee460d3a9fbce055924e704d25de","original_commit_id":"504798096bebee460d3a9fbce055924e704d25de","user":{"login":"bitwiseman","id":1958953,"avatar_url":"https://avatars.githubusercontent.com/u/1958953?v=3","gravatar_id":"","url":"https://api.github.com/users/bitwiseman","html_url":"https://github.com/bitwiseman","followers_url":"https://api.github.com/users/bitwiseman/followers","following_url":"https://api.github.com/users/bitwiseman/following{/other_user}","gists_url":"https://api.github.com/users/bitwiseman/gists{/gist_id}","starred_url":"https://api.github.com/users/bitwiseman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitwiseman/subscriptions","organizations_url":"https://api.github.com/users/bitwiseman/orgs","repos_url":"https://api.github.com/users/bitwiseman/repos","events_url":"https://api.github.com/users/bitwiseman/events{/privacy}","received_events_url":"https://api.github.com/users/bitwiseman/received_events","type":"User","site_admin":false},"body":"I wasn't sure how to do this with the mocks.  I'll take a swing at it but you'll need to take a look when I'm done.\r\n","created_at":"2015-03-25T17:42:46Z","updated_at":"2015-03-25T17:42:46Z","html_url":"https://github.com/jenkinsci/logstash-plugin/pull/3#discussion_r27146079","pull_request_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/comments/27146079"},"html":{"href":"https://github.com/jenkinsci/logstash-plugin/pull/3#discussion_r27146079"},"pull_request":{"href":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/3","id":31867723,"html_url":"https://github.com/jenkinsci/logstash-plugin/pull/3","diff_url":"https://github.com/jenkinsci/logstash-plugin/pull/3.diff","patch_url":"https://github.com/jenkinsci/logstash-plugin/pull/3.patch","issue_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/issues/3","number":3,"state":"open","locked":false,"title":"Add ability to push logs to ElasticSearch","user":{"login":"bitwiseman","id":1958953,"avatar_url":"https://avatars.githubusercontent.com/u/1958953?v=3","gravatar_id":"","url":"https://api.github.com/users/bitwiseman","html_url":"https://github.com/bitwiseman","followers_url":"https://api.github.com/users/bitwiseman/followers","following_url":"https://api.github.com/users/bitwiseman/following{/other_user}","gists_url":"https://api.github.com/users/bitwiseman/gists{/gist_id}","starred_url":"https://api.github.com/users/bitwiseman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitwiseman/subscriptions","organizations_url":"https://api.github.com/users/bitwiseman/orgs","repos_url":"https://api.github.com/users/bitwiseman/repos","events_url":"https://api.github.com/users/bitwiseman/events{/privacy}","received_events_url":"https://api.github.com/users/bitwiseman/received_events","type":"User","site_admin":false},"body":"Log to  ElasticSearch using REST API.  Updated readme, added basic tests, could use more.","created_at":"2015-03-24T20:41:44Z","updated_at":"2015-03-25T17:42:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"02205533188aba0658f59e1ed5bddfffc0544caa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/3/commits","review_comments_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/3/comments","review_comment_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/issues/3/comments","statuses_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/statuses/504798096bebee460d3a9fbce055924e704d25de","head":{"label":"bitwiseman:elastic-1","ref":"elastic-1","sha":"504798096bebee460d3a9fbce055924e704d25de","user":{"login":"bitwiseman","id":1958953,"avatar_url":"https://avatars.githubusercontent.com/u/1958953?v=3","gravatar_id":"","url":"https://api.github.com/users/bitwiseman","html_url":"https://github.com/bitwiseman","followers_url":"https://api.github.com/users/bitwiseman/followers","following_url":"https://api.github.com/users/bitwiseman/following{/other_user}","gists_url":"https://api.github.com/users/bitwiseman/gists{/gist_id}","starred_url":"https://api.github.com/users/bitwiseman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitwiseman/subscriptions","organizations_url":"https://api.github.com/users/bitwiseman/orgs","repos_url":"https://api.github.com/users/bitwiseman/repos","events_url":"https://api.github.com/users/bitwiseman/events{/privacy}","received_events_url":"https://api.github.com/users/bitwiseman/received_events","type":"User","site_admin":false},"repo":{"id":32823073,"name":"logstash-plugin","full_name":"bitwiseman/logstash-plugin","owner":{"login":"bitwiseman","id":1958953,"avatar_url":"https://avatars.githubusercontent.com/u/1958953?v=3","gravatar_id":"","url":"https://api.github.com/users/bitwiseman","html_url":"https://github.com/bitwiseman","followers_url":"https://api.github.com/users/bitwiseman/followers","following_url":"https://api.github.com/users/bitwiseman/following{/other_user}","gists_url":"https://api.github.com/users/bitwiseman/gists{/gist_id}","starred_url":"https://api.github.com/users/bitwiseman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitwiseman/subscriptions","organizations_url":"https://api.github.com/users/bitwiseman/orgs","repos_url":"https://api.github.com/users/bitwiseman/repos","events_url":"https://api.github.com/users/bitwiseman/events{/privacy}","received_events_url":"https://api.github.com/users/bitwiseman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bitwiseman/logstash-plugin","description":"Jenkins plugin to ship the console log off to Logstash","fork":true,"url":"https://api.github.com/repos/bitwiseman/logstash-plugin","forks_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/forks","keys_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/teams","hooks_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/hooks","issue_events_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/events","assignees_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/tags","blobs_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/languages","stargazers_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/stargazers","contributors_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/contributors","subscribers_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/subscribers","subscription_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/subscription","commits_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/merges","archive_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/downloads","issues_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/labels{/name}","releases_url":"https://api.github.com/repos/bitwiseman/logstash-plugin/releases{/id}","created_at":"2015-03-24T20:24:13Z","updated_at":"2015-03-24T20:24:14Z","pushed_at":"2015-03-24T20:40:12Z","git_url":"git://github.com/bitwiseman/logstash-plugin.git","ssh_url":"git@github.com:bitwiseman/logstash-plugin.git","clone_url":"https://github.com/bitwiseman/logstash-plugin.git","svn_url":"https://github.com/bitwiseman/logstash-plugin","homepage":null,"size":440,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jenkinsci:master","ref":"master","sha":"ed434bf3d88a0f001fe317be12aa8aa5846ab146","user":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"repo":{"id":7866898,"name":"logstash-plugin","full_name":"jenkinsci/logstash-plugin","owner":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jenkinsci/logstash-plugin","description":"Jenkins plugin to ship the console log off to Logstash","fork":true,"url":"https://api.github.com/repos/jenkinsci/logstash-plugin","forks_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/forks","keys_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/teams","hooks_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/hooks","issue_events_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/events","assignees_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/tags","blobs_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/languages","stargazers_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/stargazers","contributors_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/contributors","subscribers_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/subscribers","subscription_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/subscription","commits_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/merges","archive_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/downloads","issues_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/labels{/name}","releases_url":"https://api.github.com/repos/jenkinsci/logstash-plugin/releases{/id}","created_at":"2013-01-28T09:38:33Z","updated_at":"2014-12-07T03:47:29Z","pushed_at":"2015-03-24T20:41:45Z","git_url":"git://github.com/jenkinsci/logstash-plugin.git","ssh_url":"git@github.com:jenkinsci/logstash-plugin.git","clone_url":"https://github.com/jenkinsci/logstash-plugin.git","svn_url":"https://github.com/jenkinsci/logstash-plugin","homepage":null,"size":440,"stargazers_count":11,"watchers_count":11,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":1,"forks":11,"open_issues":1,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/3"},"html":{"href":"https://github.com/jenkinsci/logstash-plugin/pull/3"},"issue":{"href":"https://api.github.com/repos/jenkinsci/logstash-plugin/issues/3"},"comments":{"href":"https://api.github.com/repos/jenkinsci/logstash-plugin/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jenkinsci/logstash-plugin/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/jenkinsci/logstash-plugin/statuses/504798096bebee460d3a9fbce055924e704d25de"}}}}