{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/javarosa/pulls/comments/46742598","id":46742598,"diff_hunk":"@@ -0,0 +1,126 @@\n+package org.javarosa.core.model.instance.test;\n+\n+import org.javarosa.core.model.FormDef;\n+import org.javarosa.core.model.FormIndex;\n+import org.javarosa.core.model.condition.EvaluationContext;\n+import org.javarosa.core.model.instance.FormInstance;\n+import org.javarosa.core.test.FormParseInit;\n+import org.javarosa.core.util.externalizable.DeserializationException;\n+import org.javarosa.core.util.externalizable.LivePrototypeFactory;\n+import org.javarosa.form.api.FormEntryController;\n+import org.javarosa.form.api.FormEntryModel;\n+import org.javarosa.test_utils.ExprEvalUtils;\n+import org.javarosa.xpath.parser.XPathSyntaxException;\n+import org.junit.Test;\n+\n+import java.io.ByteArrayInputStream;\n+import java.io.ByteArrayOutputStream;\n+import java.io.DataInputStream;\n+import java.io.DataOutputStream;\n+import java.io.IOException;\n+import java.util.Date;\n+\n+import static org.junit.Assert.assertTrue;\n+import static org.junit.Assert.fail;\n+\n+/**\n+ * @author Phillip Mates (pmates@dimagi.com).\n+ */\n+public class FormInstanceTest {\n+    private static final LivePrototypeFactory pf = new LivePrototypeFactory();\n+\n+    /**\n+     * Serialize/deserialize a form instance, ensuring the resulting roots are equal\n+     */\n+    @Test\n+    public void testInstanceSerialization() {\n+        FormParseInit fpi = new FormParseInit(\"/xform_tests/test_repeat_insert_duplicate_triggering.xml\");\n+        FormEntryController fec = fpi.getFormEntryController();\n+        fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());\n+\n+        FormDef fd = fpi.getFormDef();\n+        // run initialization to ensure xforms-ready event and binds are\n+        // triggered.\n+        fd.initialize(true, new DummyInstanceInitializationFactory());\n+\n+        FormInstance instance = fd.getMainInstance();\n+        FormInstance reSerializedInstance = reSerializeFormInstance(instance);\n+\n+        assertTrue(\"Form instance root should be same after serialization\",\n+                instance.getRoot().equals(reSerializedInstance.getRoot()));\n+    }\n+\n+    /**\n+     * serialize a form instance then return the new deserialized instance\n+     */\n+    private static FormInstance reSerializeFormInstance(FormInstance originalInstance) {\n+        FormInstance reSerializedInstance = null;\n+        try {\n+            reSerializedInstance = FormInstance.class.newInstance();\n+        } catch (InstantiationException | IllegalAccessException e) {\n+            fail(e.getMessage());\n+        }\n+        ByteArrayOutputStream baos = new ByteArrayOutputStream();\n+        DataOutputStream out = new DataOutputStream(baos);\n+\n+        try {\n+            originalInstance.writeExternal(out);\n+            out.flush();\n+            out.close();\n+        } catch (IOException e) {\n+            fail(e.getMessage());\n+        }\n+        DataInputStream instanceStream = null;\n+        try {\n+            instanceStream = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));\n+            reSerializedInstance.readExternal(instanceStream, pf);\n+        } catch (IOException | DeserializationException e) {\n+            fail(e.getMessage());\n+        } finally {\n+            if (instanceStream != null) {\n+                try {\n+                    instanceStream.close();\n+                } catch (IOException e) {\n+                    e.printStackTrace();\n+                }\n+            }\n+        }\n+        return reSerializedInstance;\n+    }\n+\n+    /**\n+     * Regression test that runs through form entry with a normally loaded\n+     * form and a form that has been serialized then deserialized and compare\n+     * answers on a question with a dateTime type.\n+     */\n+    @Test\n+    public void testFormEntryAfterSerialization() throws XPathSyntaxException {\n+        FormParseInit fpi = new FormParseInit(\"/xform_tests/test_repeat_insert_duplicate_triggering.xml\");","path":"core/src/test/java/org/javarosa/core/model/instance/test/FormInstanceTest.java","position":98,"original_position":98,"commit_id":"8941e8c54d98eb6d8dca33e4a867135c0eaf40ae","original_commit_id":"8941e8c54d98eb6d8dca33e4a867135c0eaf40ae","user":{"login":"phillipm","id":94817,"avatar_url":"https://avatars.githubusercontent.com/u/94817?v=3","gravatar_id":"","url":"https://api.github.com/users/phillipm","html_url":"https://github.com/phillipm","followers_url":"https://api.github.com/users/phillipm/followers","following_url":"https://api.github.com/users/phillipm/following{/other_user}","gists_url":"https://api.github.com/users/phillipm/gists{/gist_id}","starred_url":"https://api.github.com/users/phillipm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phillipm/subscriptions","organizations_url":"https://api.github.com/users/phillipm/orgs","repos_url":"https://api.github.com/users/phillipm/repos","events_url":"https://api.github.com/users/phillipm/events{/privacy}","received_events_url":"https://api.github.com/users/phillipm/received_events","type":"User","site_admin":false},"body":"Would be great to run this type of test on lots of different forms.","created_at":"2015-12-04T22:55:38Z","updated_at":"2015-12-04T22:55:38Z","html_url":"https://github.com/dimagi/javarosa/pull/204#discussion_r46742598","pull_request_url":"https://api.github.com/repos/dimagi/javarosa/pulls/204","_links":{"self":{"href":"https://api.github.com/repos/dimagi/javarosa/pulls/comments/46742598"},"html":{"href":"https://github.com/dimagi/javarosa/pull/204#discussion_r46742598"},"pull_request":{"href":"https://api.github.com/repos/dimagi/javarosa/pulls/204"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/javarosa/pulls/204","id":52726609,"html_url":"https://github.com/dimagi/javarosa/pull/204","diff_url":"https://github.com/dimagi/javarosa/pull/204.diff","patch_url":"https://github.com/dimagi/javarosa/pull/204.patch","issue_url":"https://api.github.com/repos/dimagi/javarosa/issues/204","number":204,"state":"open","locked":false,"title":"Serialize attributes correctly & add serialization tests","user":{"login":"phillipm","id":94817,"avatar_url":"https://avatars.githubusercontent.com/u/94817?v=3","gravatar_id":"","url":"https://api.github.com/users/phillipm","html_url":"https://github.com/phillipm","followers_url":"https://api.github.com/users/phillipm/followers","following_url":"https://api.github.com/users/phillipm/following{/other_user}","gists_url":"https://api.github.com/users/phillipm/gists{/gist_id}","starred_url":"https://api.github.com/users/phillipm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phillipm/subscriptions","organizations_url":"https://api.github.com/users/phillipm/orgs","repos_url":"https://api.github.com/users/phillipm/repos","events_url":"https://api.github.com/users/phillipm/events{/privacy}","received_events_url":"https://api.github.com/users/phillipm/received_events","type":"User","site_admin":false},"body":"Serializing TreeElement's attributes looses the data type encoded in it, causing problems with data storage, like xforrm dateTime types being treated as dates.\r\n\r\nAttribute serialization has always been broken but I think some redundancy in trigger firing has masked that fact. The issue has probably arisen now that I've optimized trigger firing.\r\n\r\nhttp://manage.dimagi.com/default.asp?188492\r\n\r\ncross-requested with https://github.com/dimagi/commcare/pull/215 and https://github.com/dimagi/commcare-odk/pull/894","created_at":"2015-12-04T21:55:50Z","updated_at":"2015-12-04T22:55:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a9c7648fec54e639ddcc7cbfaeaa4b62100207a0","assignee":null,"milestone":{"url":"https://api.github.com/repos/dimagi/javarosa/milestones/4","html_url":"https://github.com/dimagi/javarosa/milestones/commcare_2.25","labels_url":"https://api.github.com/repos/dimagi/javarosa/milestones/4/labels","id":1368197,"number":4,"title":"commcare_2.25","description":null,"creator":{"login":"phillipm","id":94817,"avatar_url":"https://avatars.githubusercontent.com/u/94817?v=3","gravatar_id":"","url":"https://api.github.com/users/phillipm","html_url":"https://github.com/phillipm","followers_url":"https://api.github.com/users/phillipm/followers","following_url":"https://api.github.com/users/phillipm/following{/other_user}","gists_url":"https://api.github.com/users/phillipm/gists{/gist_id}","starred_url":"https://api.github.com/users/phillipm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phillipm/subscriptions","organizations_url":"https://api.github.com/users/phillipm/orgs","repos_url":"https://api.github.com/users/phillipm/repos","events_url":"https://api.github.com/users/phillipm/events{/privacy}","received_events_url":"https://api.github.com/users/phillipm/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":11,"state":"open","created_at":"2015-10-21T13:19:11Z","updated_at":"2015-12-04T22:02:41Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/dimagi/javarosa/pulls/204/commits","review_comments_url":"https://api.github.com/repos/dimagi/javarosa/pulls/204/comments","review_comment_url":"https://api.github.com/repos/dimagi/javarosa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/javarosa/issues/204/comments","statuses_url":"https://api.github.com/repos/dimagi/javarosa/statuses/8941e8c54d98eb6d8dca33e4a867135c0eaf40ae","head":{"label":"dimagi:2.25/fix-attr-serialization","ref":"2.25/fix-attr-serialization","sha":"8941e8c54d98eb6d8dca33e4a867135c0eaf40ae","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":20938963,"name":"javarosa","full_name":"dimagi/javarosa","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/javarosa","description":"","fork":false,"url":"https://api.github.com/repos/dimagi/javarosa","forks_url":"https://api.github.com/repos/dimagi/javarosa/forks","keys_url":"https://api.github.com/repos/dimagi/javarosa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/javarosa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/javarosa/teams","hooks_url":"https://api.github.com/repos/dimagi/javarosa/hooks","issue_events_url":"https://api.github.com/repos/dimagi/javarosa/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/javarosa/events","assignees_url":"https://api.github.com/repos/dimagi/javarosa/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/javarosa/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/javarosa/tags","blobs_url":"https://api.github.com/repos/dimagi/javarosa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/javarosa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/javarosa/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/javarosa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/javarosa/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/javarosa/languages","stargazers_url":"https://api.github.com/repos/dimagi/javarosa/stargazers","contributors_url":"https://api.github.com/repos/dimagi/javarosa/contributors","subscribers_url":"https://api.github.com/repos/dimagi/javarosa/subscribers","subscription_url":"https://api.github.com/repos/dimagi/javarosa/subscription","commits_url":"https://api.github.com/repos/dimagi/javarosa/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/javarosa/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/javarosa/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/javarosa/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/javarosa/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/javarosa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/javarosa/merges","archive_url":"https://api.github.com/repos/dimagi/javarosa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/javarosa/downloads","issues_url":"https://api.github.com/repos/dimagi/javarosa/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/javarosa/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/javarosa/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/javarosa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/javarosa/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/javarosa/releases{/id}","created_at":"2014-06-17T20:46:39Z","updated_at":"2015-11-16T08:50:17Z","pushed_at":"2015-12-04T22:54:42Z","git_url":"git://github.com/dimagi/javarosa.git","ssh_url":"git@github.com:dimagi/javarosa.git","clone_url":"https://github.com/dimagi/javarosa.git","svn_url":"https://github.com/dimagi/javarosa","homepage":null,"size":38128,"stargazers_count":4,"watchers_count":4,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":4,"default_branch":"master"}},"base":{"label":"dimagi:commcare_2.25","ref":"commcare_2.25","sha":"a2ba48da08aa37a727be1327a4e2a501ba6ff268","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":20938963,"name":"javarosa","full_name":"dimagi/javarosa","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/javarosa","description":"","fork":false,"url":"https://api.github.com/repos/dimagi/javarosa","forks_url":"https://api.github.com/repos/dimagi/javarosa/forks","keys_url":"https://api.github.com/repos/dimagi/javarosa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/javarosa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/javarosa/teams","hooks_url":"https://api.github.com/repos/dimagi/javarosa/hooks","issue_events_url":"https://api.github.com/repos/dimagi/javarosa/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/javarosa/events","assignees_url":"https://api.github.com/repos/dimagi/javarosa/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/javarosa/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/javarosa/tags","blobs_url":"https://api.github.com/repos/dimagi/javarosa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/javarosa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/javarosa/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/javarosa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/javarosa/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/javarosa/languages","stargazers_url":"https://api.github.com/repos/dimagi/javarosa/stargazers","contributors_url":"https://api.github.com/repos/dimagi/javarosa/contributors","subscribers_url":"https://api.github.com/repos/dimagi/javarosa/subscribers","subscription_url":"https://api.github.com/repos/dimagi/javarosa/subscription","commits_url":"https://api.github.com/repos/dimagi/javarosa/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/javarosa/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/javarosa/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/javarosa/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/javarosa/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/javarosa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/javarosa/merges","archive_url":"https://api.github.com/repos/dimagi/javarosa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/javarosa/downloads","issues_url":"https://api.github.com/repos/dimagi/javarosa/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/javarosa/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/javarosa/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/javarosa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/javarosa/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/javarosa/releases{/id}","created_at":"2014-06-17T20:46:39Z","updated_at":"2015-11-16T08:50:17Z","pushed_at":"2015-12-04T22:54:42Z","git_url":"git://github.com/dimagi/javarosa.git","ssh_url":"git@github.com:dimagi/javarosa.git","clone_url":"https://github.com/dimagi/javarosa.git","svn_url":"https://github.com/dimagi/javarosa","homepage":null,"size":38128,"stargazers_count":4,"watchers_count":4,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/javarosa/pulls/204"},"html":{"href":"https://github.com/dimagi/javarosa/pull/204"},"issue":{"href":"https://api.github.com/repos/dimagi/javarosa/issues/204"},"comments":{"href":"https://api.github.com/repos/dimagi/javarosa/issues/204/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/javarosa/pulls/204/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/javarosa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/javarosa/pulls/204/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/javarosa/statuses/8941e8c54d98eb6d8dca33e4a867135c0eaf40ae"}}}}