{"action":"created","comment":{"url":"https://api.github.com/repos/kite-sdk/kite/pulls/comments/23505913","id":23505913,"diff_hunk":"@@ -15,75 +15,150 @@\n  */\n package org.kitesdk.morphline.maxmind;\n \n+import org.junit.After;\n import org.junit.Ignore;\n import org.junit.Test;\n \n import org.kitesdk.morphline.api.AbstractMorphlineTest;\n+import org.kitesdk.morphline.api.Command;\n+import org.kitesdk.morphline.api.MorphlineCompilationException;\n+import org.kitesdk.morphline.api.MorphlineContext;\n import org.kitesdk.morphline.api.Record;\n import org.kitesdk.morphline.base.Fields;\n import org.kitesdk.morphline.base.Notifications;\n+import org.kitesdk.morphline.stdlib.PipeBuilder;\n+\n+import com.fasterxml.jackson.databind.JsonNode;\n+import com.fasterxml.jackson.databind.node.ObjectNode;\n+import com.typesafe.config.Config;\n+import com.typesafe.config.ConfigFactory;\n \n public class MaxmindMorphlineTest extends AbstractMorphlineTest {\n \n+  private Command buildCommand(final String inputField, String db) {\n+    final Config config = ConfigFactory.parseString(\n+        String.format(\"inputField=%s\\ndatabase=target/test-classes/%s\\n\", inputField, db)\n+    );\n+    return new GeoIPBuilder().build(config, new RootCommand(), collector, new MorphlineContext.Builder().build());\n+  }\n+\n+  @After\n+  public void tearDown() {\n+    if (morphline != null) {\n+      Notifications.notifyShutdown(morphline);\n+      Notifications.notifyShutdown(morphline);\n+      morphline = null;\n+    }\n+  }\n+\n   @Test\n   public void testIPv4() throws Exception {\n-    morphline = createMorphline(\"test-morphlines/geoIP\");    \n-    \n-    Record record = new Record();\n-    String ip = \"128.101.101.101\";\n+    morphline = buildCommand(\"ip\", \"GeoLite2-City.mmdb\");\n+    final Record record = new Record();\n+    final String ip = \"128.101.101.101\";\n     record.put(\"ip\", ip);\n-    Record expected = new Record();\n-    expected.put(\"ip\", ip);\n-    expected.put(\"/country/iso_code\", \"US\");\n-    expected.put(\"/country/names/en\", \"United States\");\n-    expected.put(\"/country/names/zh-CN\", \"美国\");\n-    expected.put(\"/subdivisions[]/names/en\", \"Minnesota\");\n-    expected.put(\"/subdivisions[]/iso_code\", \"MN\");\n-    expected.put(\"/city/names/en\", \"Minneapolis\");\n-    expected.put(\"/postal/code\", \"55455\");\n-    expected.put(\"/location/latitude\", 44.9733);\n-    expected.put(\"/location/longitude\", -93.2323);\n-    expected.put(\"/location/latitude_longitude\", \"44.9733,-93.2323\");\n-    expected.put(\"/location/longitude_latitude\", \"-93.2323,44.9733\");\n-    \n-    processAndVerifySuccess(record, expected, false);\n-    Notifications.notifyShutdown(morphline);\n-    Notifications.notifyShutdown(morphline);\n+    processAndVerifySuccess(record, true, false, 6252001, 5037649);\n+  }\n+\n+  @Test\n+  public void testIPv4CountryOnly() throws Exception {\n+    morphline = buildCommand(\"ip\", \"GeoLite2-Country.mmdb\");\n+    final Record record = new Record();\n+    final String ip = \"128.101.101.101\";\n+    record.put(\"ip\", ip);\n+    processAndVerifySuccess(record, true, false, 6252001, null);\n+  }\n+\n+  @Test\n+  public void testNotFoundIPv4() throws Exception {\n+    morphline = buildCommand(\"ip\", \"GeoLite2-City.mmdb\");\n+    final Record record = new Record();\n+    final String ip = \"127.0.0.1\";\n+    record.put(\"ip\", ip);\n+    processAndVerifySuccess(record, false, false, null, null);\n+  }\n+\n+  @Test\n+  public void testBadData() throws Exception {\n+    morphline = buildCommand(\"ip\", \"GeoLite2-City.mmdb\");\n+    final Record record = new Record();\n+    final String ip = \"DAT DATA\";\n+    record.put(\"ip\", ip);\n+    processAndVerifySuccess(record, false, false, null, null);\n+  }\n+\n+  @Test\n+  public void testEmpty() throws Exception {\n+    morphline = buildCommand(\"ip\", \"GeoLite2-City.mmdb\");\n+    final Record record = new Record();\n+    processAndVerifySuccess(record, false, false, null, null);\n   }\n   \n   @Test\n   public void testIPv6() throws Exception {\n-    morphline = createMorphline(\"test-morphlines/geoIP\");    \n-    \n-    Record record = new Record();\n-    String ip = \"2001:620::1\";\n+    morphline = buildCommand(\"ip\", \"GeoLite2-City.mmdb\");\n+    final Record record = new Record();\n+    final String ip = \"2001:4860:4860::8844\";\n     record.put(\"ip\", ip);\n-    Record expected = new Record();\n-    expected.put(\"ip\", ip);\n-    expected.put(\"/country/iso_code\", \"CH\");\n-    expected.put(\"/country/names/en\", \"Switzerland\");\n-    expected.put(\"/country/names/zh-CN\", \"瑞士\");","path":"kite-morphlines/kite-morphlines-maxmind/src/test/java/org/kitesdk/morphline/maxmind/MaxmindMorphlineTest.java","position":118,"original_position":118,"commit_id":"c007db11e657b33026a0f0f5a5e09adc35fe0447","original_commit_id":"c007db11e657b33026a0f0f5a5e09adc35fe0447","user":{"login":"whoschek","id":919871,"avatar_url":"https://avatars.githubusercontent.com/u/919871?v=3","gravatar_id":"","url":"https://api.github.com/users/whoschek","html_url":"https://github.com/whoschek","followers_url":"https://api.github.com/users/whoschek/followers","following_url":"https://api.github.com/users/whoschek/following{/other_user}","gists_url":"https://api.github.com/users/whoschek/gists{/gist_id}","starred_url":"https://api.github.com/users/whoschek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whoschek/subscriptions","organizations_url":"https://api.github.com/users/whoschek/orgs","repos_url":"https://api.github.com/users/whoschek/repos","events_url":"https://api.github.com/users/whoschek/events{/privacy}","received_events_url":"https://api.github.com/users/whoschek/received_events","type":"User","site_admin":false},"body":"Can we keep that original unit test as well?","created_at":"2015-01-25T17:47:42Z","updated_at":"2015-01-25T17:47:42Z","html_url":"https://github.com/kite-sdk/kite/pull/291#discussion_r23505913","pull_request_url":"https://api.github.com/repos/kite-sdk/kite/pulls/291","_links":{"self":{"href":"https://api.github.com/repos/kite-sdk/kite/pulls/comments/23505913"},"html":{"href":"https://github.com/kite-sdk/kite/pull/291#discussion_r23505913"},"pull_request":{"href":"https://api.github.com/repos/kite-sdk/kite/pulls/291"}}},"pull_request":{"url":"https://api.github.com/repos/kite-sdk/kite/pulls/291","id":27862353,"html_url":"https://github.com/kite-sdk/kite/pull/291","diff_url":"https://github.com/kite-sdk/kite/pull/291.diff","patch_url":"https://github.com/kite-sdk/kite/pull/291.patch","issue_url":"https://api.github.com/repos/kite-sdk/kite/issues/291","number":291,"state":"open","locked":false,"title":"[CDK-883] geoIP throws NullPointerException when IP is not found","user":{"login":"smola","id":23248,"avatar_url":"https://avatars.githubusercontent.com/u/23248?v=3","gravatar_id":"","url":"https://api.github.com/users/smola","html_url":"https://github.com/smola","followers_url":"https://api.github.com/users/smola/followers","following_url":"https://api.github.com/users/smola/following{/other_user}","gists_url":"https://api.github.com/users/smola/gists{/gist_id}","starred_url":"https://api.github.com/users/smola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smola/subscriptions","organizations_url":"https://api.github.com/users/smola/orgs","repos_url":"https://api.github.com/users/smola/repos","events_url":"https://api.github.com/users/smola/events{/privacy}","received_events_url":"https://api.github.com/users/smola/received_events","type":"User","site_admin":false},"body":"https://issues.cloudera.org/browse/CDK-883","created_at":"2015-01-22T17:45:42Z","updated_at":"2015-01-25T17:47:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e76109cd0e8579af134bd0d8b5f232462110435b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/kite-sdk/kite/pulls/291/commits","review_comments_url":"https://api.github.com/repos/kite-sdk/kite/pulls/291/comments","review_comment_url":"https://api.github.com/repos/kite-sdk/kite/pulls/comments/{number}","comments_url":"https://api.github.com/repos/kite-sdk/kite/issues/291/comments","statuses_url":"https://api.github.com/repos/kite-sdk/kite/statuses/c007db11e657b33026a0f0f5a5e09adc35fe0447","head":{"label":"smola:CDK-883","ref":"CDK-883","sha":"c007db11e657b33026a0f0f5a5e09adc35fe0447","user":{"login":"smola","id":23248,"avatar_url":"https://avatars.githubusercontent.com/u/23248?v=3","gravatar_id":"","url":"https://api.github.com/users/smola","html_url":"https://github.com/smola","followers_url":"https://api.github.com/users/smola/followers","following_url":"https://api.github.com/users/smola/following{/other_user}","gists_url":"https://api.github.com/users/smola/gists{/gist_id}","starred_url":"https://api.github.com/users/smola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smola/subscriptions","organizations_url":"https://api.github.com/users/smola/orgs","repos_url":"https://api.github.com/users/smola/repos","events_url":"https://api.github.com/users/smola/events{/privacy}","received_events_url":"https://api.github.com/users/smola/received_events","type":"User","site_admin":false},"repo":{"id":22597937,"name":"kite","full_name":"smola/kite","owner":{"login":"smola","id":23248,"avatar_url":"https://avatars.githubusercontent.com/u/23248?v=3","gravatar_id":"","url":"https://api.github.com/users/smola","html_url":"https://github.com/smola","followers_url":"https://api.github.com/users/smola/followers","following_url":"https://api.github.com/users/smola/following{/other_user}","gists_url":"https://api.github.com/users/smola/gists{/gist_id}","starred_url":"https://api.github.com/users/smola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smola/subscriptions","organizations_url":"https://api.github.com/users/smola/orgs","repos_url":"https://api.github.com/users/smola/repos","events_url":"https://api.github.com/users/smola/events{/privacy}","received_events_url":"https://api.github.com/users/smola/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/smola/kite","description":"Kite SDK","fork":true,"url":"https://api.github.com/repos/smola/kite","forks_url":"https://api.github.com/repos/smola/kite/forks","keys_url":"https://api.github.com/repos/smola/kite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/smola/kite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/smola/kite/teams","hooks_url":"https://api.github.com/repos/smola/kite/hooks","issue_events_url":"https://api.github.com/repos/smola/kite/issues/events{/number}","events_url":"https://api.github.com/repos/smola/kite/events","assignees_url":"https://api.github.com/repos/smola/kite/assignees{/user}","branches_url":"https://api.github.com/repos/smola/kite/branches{/branch}","tags_url":"https://api.github.com/repos/smola/kite/tags","blobs_url":"https://api.github.com/repos/smola/kite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/smola/kite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/smola/kite/git/refs{/sha}","trees_url":"https://api.github.com/repos/smola/kite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/smola/kite/statuses/{sha}","languages_url":"https://api.github.com/repos/smola/kite/languages","stargazers_url":"https://api.github.com/repos/smola/kite/stargazers","contributors_url":"https://api.github.com/repos/smola/kite/contributors","subscribers_url":"https://api.github.com/repos/smola/kite/subscribers","subscription_url":"https://api.github.com/repos/smola/kite/subscription","commits_url":"https://api.github.com/repos/smola/kite/commits{/sha}","git_commits_url":"https://api.github.com/repos/smola/kite/git/commits{/sha}","comments_url":"https://api.github.com/repos/smola/kite/comments{/number}","issue_comment_url":"https://api.github.com/repos/smola/kite/issues/comments/{number}","contents_url":"https://api.github.com/repos/smola/kite/contents/{+path}","compare_url":"https://api.github.com/repos/smola/kite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/smola/kite/merges","archive_url":"https://api.github.com/repos/smola/kite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/smola/kite/downloads","issues_url":"https://api.github.com/repos/smola/kite/issues{/number}","pulls_url":"https://api.github.com/repos/smola/kite/pulls{/number}","milestones_url":"https://api.github.com/repos/smola/kite/milestones{/number}","notifications_url":"https://api.github.com/repos/smola/kite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/smola/kite/labels{/name}","releases_url":"https://api.github.com/repos/smola/kite/releases{/id}","created_at":"2014-08-04T08:55:54Z","updated_at":"2014-07-30T23:11:38Z","pushed_at":"2015-01-23T13:46:48Z","git_url":"git://github.com/smola/kite.git","ssh_url":"git@github.com:smola/kite.git","clone_url":"https://github.com/smola/kite.git","svn_url":"https://github.com/smola/kite","homepage":"http://kitesdk.org/docs/current/","size":37938,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kite-sdk:master","ref":"master","sha":"35e075790b0d0a806dfc4b18bd77fc34a10176e7","user":{"login":"kite-sdk","id":5732728,"avatar_url":"https://avatars.githubusercontent.com/u/5732728?v=3","gravatar_id":"","url":"https://api.github.com/users/kite-sdk","html_url":"https://github.com/kite-sdk","followers_url":"https://api.github.com/users/kite-sdk/followers","following_url":"https://api.github.com/users/kite-sdk/following{/other_user}","gists_url":"https://api.github.com/users/kite-sdk/gists{/gist_id}","starred_url":"https://api.github.com/users/kite-sdk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kite-sdk/subscriptions","organizations_url":"https://api.github.com/users/kite-sdk/orgs","repos_url":"https://api.github.com/users/kite-sdk/repos","events_url":"https://api.github.com/users/kite-sdk/events{/privacy}","received_events_url":"https://api.github.com/users/kite-sdk/received_events","type":"Organization","site_admin":false},"repo":{"id":14829187,"name":"kite","full_name":"kite-sdk/kite","owner":{"login":"kite-sdk","id":5732728,"avatar_url":"https://avatars.githubusercontent.com/u/5732728?v=3","gravatar_id":"","url":"https://api.github.com/users/kite-sdk","html_url":"https://github.com/kite-sdk","followers_url":"https://api.github.com/users/kite-sdk/followers","following_url":"https://api.github.com/users/kite-sdk/following{/other_user}","gists_url":"https://api.github.com/users/kite-sdk/gists{/gist_id}","starred_url":"https://api.github.com/users/kite-sdk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kite-sdk/subscriptions","organizations_url":"https://api.github.com/users/kite-sdk/orgs","repos_url":"https://api.github.com/users/kite-sdk/repos","events_url":"https://api.github.com/users/kite-sdk/events{/privacy}","received_events_url":"https://api.github.com/users/kite-sdk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kite-sdk/kite","description":"Kite SDK","fork":false,"url":"https://api.github.com/repos/kite-sdk/kite","forks_url":"https://api.github.com/repos/kite-sdk/kite/forks","keys_url":"https://api.github.com/repos/kite-sdk/kite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kite-sdk/kite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kite-sdk/kite/teams","hooks_url":"https://api.github.com/repos/kite-sdk/kite/hooks","issue_events_url":"https://api.github.com/repos/kite-sdk/kite/issues/events{/number}","events_url":"https://api.github.com/repos/kite-sdk/kite/events","assignees_url":"https://api.github.com/repos/kite-sdk/kite/assignees{/user}","branches_url":"https://api.github.com/repos/kite-sdk/kite/branches{/branch}","tags_url":"https://api.github.com/repos/kite-sdk/kite/tags","blobs_url":"https://api.github.com/repos/kite-sdk/kite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kite-sdk/kite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kite-sdk/kite/git/refs{/sha}","trees_url":"https://api.github.com/repos/kite-sdk/kite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kite-sdk/kite/statuses/{sha}","languages_url":"https://api.github.com/repos/kite-sdk/kite/languages","stargazers_url":"https://api.github.com/repos/kite-sdk/kite/stargazers","contributors_url":"https://api.github.com/repos/kite-sdk/kite/contributors","subscribers_url":"https://api.github.com/repos/kite-sdk/kite/subscribers","subscription_url":"https://api.github.com/repos/kite-sdk/kite/subscription","commits_url":"https://api.github.com/repos/kite-sdk/kite/commits{/sha}","git_commits_url":"https://api.github.com/repos/kite-sdk/kite/git/commits{/sha}","comments_url":"https://api.github.com/repos/kite-sdk/kite/comments{/number}","issue_comment_url":"https://api.github.com/repos/kite-sdk/kite/issues/comments/{number}","contents_url":"https://api.github.com/repos/kite-sdk/kite/contents/{+path}","compare_url":"https://api.github.com/repos/kite-sdk/kite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kite-sdk/kite/merges","archive_url":"https://api.github.com/repos/kite-sdk/kite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kite-sdk/kite/downloads","issues_url":"https://api.github.com/repos/kite-sdk/kite/issues{/number}","pulls_url":"https://api.github.com/repos/kite-sdk/kite/pulls{/number}","milestones_url":"https://api.github.com/repos/kite-sdk/kite/milestones{/number}","notifications_url":"https://api.github.com/repos/kite-sdk/kite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kite-sdk/kite/labels{/name}","releases_url":"https://api.github.com/repos/kite-sdk/kite/releases{/id}","created_at":"2013-11-30T22:06:02Z","updated_at":"2015-01-24T22:11:02Z","pushed_at":"2015-01-24T22:11:02Z","git_url":"git://github.com/kite-sdk/kite.git","ssh_url":"git@github.com:kite-sdk/kite.git","clone_url":"https://github.com/kite-sdk/kite.git","svn_url":"https://github.com/kite-sdk/kite","homepage":"http://kitesdk.org/docs/current/","size":72479,"stargazers_count":98,"watchers_count":98,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":79,"mirror_url":null,"open_issues_count":10,"forks":79,"open_issues":10,"watchers":98,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kite-sdk/kite/pulls/291"},"html":{"href":"https://github.com/kite-sdk/kite/pull/291"},"issue":{"href":"https://api.github.com/repos/kite-sdk/kite/issues/291"},"comments":{"href":"https://api.github.com/repos/kite-sdk/kite/issues/291/comments"},"review_comments":{"href":"https://api.github.com/repos/kite-sdk/kite/pulls/291/comments"},"review_comment":{"href":"https://api.github.com/repos/kite-sdk/kite/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/kite-sdk/kite/pulls/291/commits"},"statuses":{"href":"https://api.github.com/repos/kite-sdk/kite/statuses/c007db11e657b33026a0f0f5a5e09adc35fe0447"}}}}