|
| 1 | +package test_locally.api.model; |
| 2 | + |
| 3 | +import com.slack.api.model.File; |
| 4 | +import org.junit.Test; |
| 5 | +import test_locally.unit.GsonFactory; |
| 6 | + |
| 7 | +import static org.hamcrest.CoreMatchers.is; |
| 8 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 9 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 10 | + |
| 11 | +public class FileTest { |
| 12 | + |
| 13 | + String ISSUE_1426_JSON = "{\n" + |
| 14 | + " \"id\": \"F08AF7HUWQL\",\n" + |
| 15 | + " \"created\": 1737949586,\n" + |
| 16 | + " \"timestamp\": 1737949586,\n" + |
| 17 | + " \"name\": \"sample.txt\",\n" + |
| 18 | + " \"title\": \"sample.txt\",\n" + |
| 19 | + " \"mimetype\": \"text/plain\",\n" + |
| 20 | + " \"filetype\": \"text\",\n" + |
| 21 | + " \"pretty_type\": \"Plain Text\",\n" + |
| 22 | + " \"user\": \"U8P5K48E6\",\n" + |
| 23 | + " \"user_team\": \"T03E94MJU\",\n" + |
| 24 | + " \"editable\": true,\n" + |
| 25 | + " \"size\": 57,\n" + |
| 26 | + " \"mode\": \"snippet\",\n" + |
| 27 | + " \"is_external\": false,\n" + |
| 28 | + " \"external_type\": \"\",\n" + |
| 29 | + " \"is_public\": true,\n" + |
| 30 | + " \"public_url_shared\": false,\n" + |
| 31 | + " \"display_as_bot\": false,\n" + |
| 32 | + " \"username\": \"\",\n" + |
| 33 | + " \"url_private\": \"https://files.slack.com/files-pri/T03E94MJU-F08AF7HUWQL/sample.txt\",\n" + |
| 34 | + " \"url_private_download\": \"https://files.slack.com/files-pri/T03E94MJU-F08AF7HUWQL/download/sample.txt\",\n" + |
| 35 | + " \"permalink\": \"https://seratch.slack.com/files/U8P5K48E6/F08AF7HUWQL/sample.txt\",\n" + |
| 36 | + " \"permalink_public\": \"https://slack-files.com/T03E94MJU-F08AF7HUWQL-9d27bd3319\",\n" + |
| 37 | + " \"edit_link\": \"https://seratch.slack.com/files/U8P5K48E6/F08AF7HUWQL/sample.txt/edit\",\n" + |
| 38 | + " \"preview\": \"Hello, World!!!!!\\n\\nThis is a sample text file.\\n\\n日本語\",\n" + |
| 39 | + " \"preview_highlight\": \"\\u003cdiv class\\u003d\\\"CodeMirror cm-s-default CodeMirrorServer\\\"\\u003e\\n\\u003cdiv class\\u003d\\\"CodeMirror-code\\\"\\u003e\\n\\u003cdiv\\u003e\\u003cpre\\u003eHello, World!!!!!\\u003c/pre\\u003e\\u003c/div\\u003e\\n\\u003cdiv\\u003e\\u003cpre\\u003e\\u003c/pre\\u003e\\u003c/div\\u003e\\n\\u003cdiv\\u003e\\u003cpre\\u003eThis is a sample text file.\\u003c/pre\\u003e\\u003c/div\\u003e\\n\\u003cdiv\\u003e\\u003cpre\\u003e\\u003c/pre\\u003e\\u003c/div\\u003e\\n\\u003cdiv\\u003e\\u003cpre\\u003e日本語\\u003c/pre\\u003e\\u003c/div\\u003e\\n\\u003c/div\\u003e\\n\\u003c/div\\u003e\\n\",\n" + |
| 40 | + " \"lines\": 5,\n" + |
| 41 | + " \"lines_more\": 0,\n" + |
| 42 | + " \"preview_is_truncated\": false,\n" + |
| 43 | + " \"favorites\": {},\n" + // unusual data structure here |
| 44 | + " \"is_starred\": false,\n" + |
| 45 | + " \"shares\": {\n" + |
| 46 | + " \"public\": {\n" + |
| 47 | + " \"C03E94MKU\": [\n" + |
| 48 | + " {\n" + |
| 49 | + " \"reply_users\": {},\n" + // unusual data structure here |
| 50 | + " \"reply_users_count\": 0,\n" + |
| 51 | + " \"reply_count\": 0,\n" + |
| 52 | + " \"ts\": \"1737949587.842889\",\n" + |
| 53 | + " \"channel_name\": \"random\",\n" + |
| 54 | + " \"team_id\": \"T03E94MJU\",\n" + |
| 55 | + " \"share_user_id\": \"U8P5K48E6\",\n" + |
| 56 | + " \"source\": \"UNKNOWN\"\n" + |
| 57 | + " }\n" + |
| 58 | + " ],\n" + |
| 59 | + " \"C03E94MKS\": [\n" + |
| 60 | + " {\n" + |
| 61 | + " \"reply_users\": [],\n" + |
| 62 | + " \"reply_users_count\": 0,\n" + |
| 63 | + " \"reply_count\": 0,\n" + |
| 64 | + " \"ts\": \"1737949587.678069\",\n" + |
| 65 | + " \"channel_name\": \"general\",\n" + |
| 66 | + " \"team_id\": \"T03E94MJU\",\n" + |
| 67 | + " \"share_user_id\": \"U8P5K48E6\",\n" + |
| 68 | + " \"source\": \"UNKNOWN\"\n" + |
| 69 | + " }\n" + |
| 70 | + " ]\n" + |
| 71 | + " }\n" + |
| 72 | + " },\n" + |
| 73 | + " \"channels\": {},\n" + // unusual data structure here |
| 74 | + " \"groups\": {},\n" + // unusual data structure here |
| 75 | + " \"ims\": {},\n" + // unusual data structure here |
| 76 | + " \"has_more_shares\": false,\n" + |
| 77 | + " \"has_rich_preview\": false,\n" + |
| 78 | + " \"file_access\": \"visible\",\n" + |
| 79 | + " \"comments_count\": 0\n" + |
| 80 | + "}\n"; |
| 81 | + |
| 82 | + @Test |
| 83 | + public void issue1426_parse() { |
| 84 | + // com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 65 column 14 path $.groups |
| 85 | + File file = GsonFactory.createSnakeCase().fromJson(ISSUE_1426_JSON, File.class); |
| 86 | + assertThat(file.getShares(), is(notNullValue())); |
| 87 | + } |
| 88 | +} |
0 commit comments