{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/52442179","id":52442179,"diff_hunk":"@@ -0,0 +1,163 @@\n+/*\n+ * Licensed to Elasticsearch under one or more contributor\n+ * license agreements. See the NOTICE file distributed with\n+ * this work for additional information regarding copyright\n+ * ownership. Elasticsearch licenses this file to you under\n+ * the Apache License, Version 2.0 (the \"License\"); you may\n+ * not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package org.elasticsearch.search.sort;\n+\n+import org.elasticsearch.common.io.stream.BytesStreamOutput;\n+import org.elasticsearch.common.io.stream.NamedWriteable;\n+import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;\n+import org.elasticsearch.common.io.stream.NamedWriteableRegistry;\n+import org.elasticsearch.common.io.stream.StreamInput;\n+import org.elasticsearch.common.settings.Settings;\n+import org.elasticsearch.common.xcontent.ToXContent;\n+import org.elasticsearch.common.xcontent.XContentBuilder;\n+import org.elasticsearch.common.xcontent.XContentFactory;\n+import org.elasticsearch.common.xcontent.XContentHelper;\n+import org.elasticsearch.common.xcontent.XContentParser;\n+import org.elasticsearch.common.xcontent.XContentType;\n+import org.elasticsearch.index.query.QueryParseContext;\n+import org.elasticsearch.indices.query.IndicesQueriesRegistry;\n+import org.elasticsearch.search.SearchModule;\n+import org.elasticsearch.test.ESTestCase;\n+import org.junit.AfterClass;\n+import org.junit.BeforeClass;\n+\n+import java.io.IOException;\n+\n+import static org.hamcrest.Matchers.*;\n+\n+public abstract class AbstractSearchSourceItemTestCase<T extends SortBuilderTemp<T>> extends ESTestCase {\n+\n+    protected static NamedWriteableRegistry namedWriteableRegistry;\n+\n+    private static final int NUMBER_OF_TESTBUILDERS = 20;\n+    static IndicesQueriesRegistry indicesQueriesRegistry;\n+\n+    @BeforeClass\n+    public static void init() {\n+        namedWriteableRegistry = new NamedWriteableRegistry();\n+        namedWriteableRegistry.registerPrototype(FieldSortBuilder.class, FieldSortBuilder.PROTOTYPE);\n+        indicesQueriesRegistry = new SearchModule(Settings.EMPTY, namedWriteableRegistry).buildQueryParserRegistry();\n+    }\n+\n+    @AfterClass\n+    public static void afterClass() throws Exception {\n+        namedWriteableRegistry = null;\n+    }\n+\n+    /** Returns random sort that is put under test */\n+    protected abstract T createTestItem();\n+\n+    /** Returns mutated version of original so the returned sort is different in terms of equals/hashcode */\n+    protected abstract T mutate(T original) throws IOException;\n+\n+    /**\n+     * Test that creates new sort from a random test sort and checks both for equality\n+     */\n+    public void testFromXContent() throws IOException {\n+        for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {\n+            T testItem = createTestItem();\n+\n+            XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));\n+            if (randomBoolean()) {\n+                builder.prettyPrint();\n+            }\n+            builder.startObject();\n+            testItem.toXContent(builder, ToXContent.EMPTY_PARAMS);\n+            builder.endObject();\n+\n+            XContentParser itemParser = XContentHelper.createParser(builder.bytes());\n+            itemParser.nextToken();\n+            \n+            /*\n+             * filter out name of sort, or field name to sort on for element fieldSort \n+             */\n+            itemParser.nextToken();\n+            String elementName = itemParser.currentName();\n+            itemParser.nextToken();\n+\n+            QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);\n+            context.reset(itemParser);\n+            NamedWriteable<T> parsedItem = testItem.fromXContent(context, elementName);","path":"core/src/test/java/org/elasticsearch/search/sort/AbstractSearchSourceItemTestCase.java","position":97,"original_position":97,"commit_id":"313cdc045d046ab88374e6bfa91c4ddd0a167f34","original_commit_id":"313cdc045d046ab88374e6bfa91c4ddd0a167f34","user":{"login":"MaineC","id":70953,"avatar_url":"https://avatars.githubusercontent.com/u/70953?v=3","gravatar_id":"","url":"https://api.github.com/users/MaineC","html_url":"https://github.com/MaineC","followers_url":"https://api.github.com/users/MaineC/followers","following_url":"https://api.github.com/users/MaineC/following{/other_user}","gists_url":"https://api.github.com/users/MaineC/gists{/gist_id}","starred_url":"https://api.github.com/users/MaineC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaineC/subscriptions","organizations_url":"https://api.github.com/users/MaineC/orgs","repos_url":"https://api.github.com/users/MaineC/repos","events_url":"https://api.github.com/users/MaineC/events{/privacy}","received_events_url":"https://api.github.com/users/MaineC/received_events","type":"User","site_admin":false},"body":"+1","created_at":"2016-02-10T10:53:30Z","updated_at":"2016-02-10T10:53:30Z","html_url":"https://github.com/elastic/elasticsearch/pull/16127#discussion_r52442179","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/16127","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/52442179"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/16127#discussion_r52442179"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/16127"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/16127","id":56618389,"html_url":"https://github.com/elastic/elasticsearch/pull/16127","diff_url":"https://github.com/elastic/elasticsearch/pull/16127.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/16127.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/16127","number":16127,"state":"open","locked":false,"title":"Refactor FieldSortBuilder","user":{"login":"MaineC","id":70953,"avatar_url":"https://avatars.githubusercontent.com/u/70953?v=3","gravatar_id":"","url":"https://api.github.com/users/MaineC","html_url":"https://github.com/MaineC","followers_url":"https://api.github.com/users/MaineC/followers","following_url":"https://api.github.com/users/MaineC/following{/other_user}","gists_url":"https://api.github.com/users/MaineC/gists{/gist_id}","starred_url":"https://api.github.com/users/MaineC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaineC/subscriptions","organizations_url":"https://api.github.com/users/MaineC/orgs","repos_url":"https://api.github.com/users/MaineC/repos","events_url":"https://api.github.com/users/MaineC/events{/privacy}","received_events_url":"https://api.github.com/users/MaineC/received_events","type":"User","site_admin":false},"body":"* adds json parsing,\r\n* refactors json serialisation,\r\n* adds writable parsing and serialisation,\r\n* adds json and writable roundtrip test\r\n\r\nThis relates to #15178\r\n\r\nCaveat: Tests are still running locally, so expect changes to fix any failures to come.","created_at":"2016-01-20T14:59:11Z","updated_at":"2016-02-10T10:53:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a04c9860b885ae7e7c57cfbcf71e6e54ca18f39c","assignee":{"login":"MaineC","id":70953,"avatar_url":"https://avatars.githubusercontent.com/u/70953?v=3","gravatar_id":"","url":"https://api.github.com/users/MaineC","html_url":"https://github.com/MaineC","followers_url":"https://api.github.com/users/MaineC/followers","following_url":"https://api.github.com/users/MaineC/following{/other_user}","gists_url":"https://api.github.com/users/MaineC/gists{/gist_id}","starred_url":"https://api.github.com/users/MaineC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaineC/subscriptions","organizations_url":"https://api.github.com/users/MaineC/orgs","repos_url":"https://api.github.com/users/MaineC/repos","events_url":"https://api.github.com/users/MaineC/events{/privacy}","received_events_url":"https://api.github.com/users/MaineC/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/16127/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/16127/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/16127/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/313cdc045d046ab88374e6bfa91c4ddd0a167f34","head":{"label":"MaineC:enhancement/15178-sort-fieldsortbuilder","ref":"enhancement/15178-sort-fieldsortbuilder","sha":"313cdc045d046ab88374e6bfa91c4ddd0a167f34","user":{"login":"MaineC","id":70953,"avatar_url":"https://avatars.githubusercontent.com/u/70953?v=3","gravatar_id":"","url":"https://api.github.com/users/MaineC","html_url":"https://github.com/MaineC","followers_url":"https://api.github.com/users/MaineC/followers","following_url":"https://api.github.com/users/MaineC/following{/other_user}","gists_url":"https://api.github.com/users/MaineC/gists{/gist_id}","starred_url":"https://api.github.com/users/MaineC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaineC/subscriptions","organizations_url":"https://api.github.com/users/MaineC/orgs","repos_url":"https://api.github.com/users/MaineC/repos","events_url":"https://api.github.com/users/MaineC/events{/privacy}","received_events_url":"https://api.github.com/users/MaineC/received_events","type":"User","site_admin":false},"repo":{"id":14859176,"name":"elasticsearch","full_name":"MaineC/elasticsearch","owner":{"login":"MaineC","id":70953,"avatar_url":"https://avatars.githubusercontent.com/u/70953?v=3","gravatar_id":"","url":"https://api.github.com/users/MaineC","html_url":"https://github.com/MaineC","followers_url":"https://api.github.com/users/MaineC/followers","following_url":"https://api.github.com/users/MaineC/following{/other_user}","gists_url":"https://api.github.com/users/MaineC/gists{/gist_id}","starred_url":"https://api.github.com/users/MaineC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaineC/subscriptions","organizations_url":"https://api.github.com/users/MaineC/orgs","repos_url":"https://api.github.com/users/MaineC/repos","events_url":"https://api.github.com/users/MaineC/events{/privacy}","received_events_url":"https://api.github.com/users/MaineC/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MaineC/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/MaineC/elasticsearch","forks_url":"https://api.github.com/repos/MaineC/elasticsearch/forks","keys_url":"https://api.github.com/repos/MaineC/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MaineC/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MaineC/elasticsearch/teams","hooks_url":"https://api.github.com/repos/MaineC/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/MaineC/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/MaineC/elasticsearch/events","assignees_url":"https://api.github.com/repos/MaineC/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/MaineC/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/MaineC/elasticsearch/tags","blobs_url":"https://api.github.com/repos/MaineC/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MaineC/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MaineC/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/MaineC/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MaineC/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/MaineC/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/MaineC/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/MaineC/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/MaineC/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/MaineC/elasticsearch/subscription","commits_url":"https://api.github.com/repos/MaineC/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/MaineC/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/MaineC/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/MaineC/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/MaineC/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/MaineC/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MaineC/elasticsearch/merges","archive_url":"https://api.github.com/repos/MaineC/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MaineC/elasticsearch/downloads","issues_url":"https://api.github.com/repos/MaineC/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/MaineC/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/MaineC/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/MaineC/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MaineC/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/MaineC/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/MaineC/elasticsearch/deployments","created_at":"2013-12-02T10:17:35Z","updated_at":"2015-05-06T09:43:46Z","pushed_at":"2016-02-10T10:21:52Z","git_url":"git://github.com/MaineC/elasticsearch.git","ssh_url":"git@github.com:MaineC/elasticsearch.git","clone_url":"https://github.com/MaineC/elasticsearch.git","svn_url":"https://github.com/MaineC/elasticsearch","homepage":"http://elasticsearch.org","size":168747,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"elastic:master","ref":"master","sha":"4decc72da6abc426b97789ad149b31eef9aad583","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/elasticsearch/deployments","created_at":"2010-02-08T13:20:56Z","updated_at":"2016-02-10T09:31:11Z","pushed_at":"2016-02-10T10:52:01Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":288352,"stargazers_count":15535,"watchers_count":15535,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4980,"mirror_url":null,"open_issues_count":1162,"forks":4980,"open_issues":1162,"watchers":15535,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/16127"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/16127"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/16127"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/16127/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/16127/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/16127/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/313cdc045d046ab88374e6bfa91c4ddd0a167f34"}}}}