rhoconnect 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (361) hide show
  1. data/CHANGELOG +208 -0
  2. data/CREDITS +38 -0
  3. data/Gemfile +18 -0
  4. data/Gemfile.lock +97 -0
  5. data/LICENSE +75 -0
  6. data/README.md +10 -0
  7. data/Rakefile +82 -0
  8. data/bench/bench +7 -0
  9. data/bench/bench_runner.rb +112 -0
  10. data/bench/benchapp/Gemfile +21 -0
  11. data/bench/benchapp/Gemfile.lock +76 -0
  12. data/bench/benchapp/Rakefile +22 -0
  13. data/bench/benchapp/application.rb +39 -0
  14. data/bench/benchapp/config.ru +36 -0
  15. data/bench/benchapp/settings/license.key +1 -0
  16. data/bench/benchapp/settings/settings.yml +20 -0
  17. data/bench/benchapp/sources/mock_adapter.rb +55 -0
  18. data/bench/benchapp/sources/queue_mock_adapter.rb +2 -0
  19. data/bench/benchapp/spec/sources/mock_adapter_spec.rb +25 -0
  20. data/bench/benchapp/spec/sources/queue_mock_adapter_spec.rb +25 -0
  21. data/bench/benchapp/spec/spec_helper.rb +42 -0
  22. data/bench/blobapp/Gemfile +31 -0
  23. data/bench/blobapp/Gemfile.lock +103 -0
  24. data/bench/blobapp/Rakefile +25 -0
  25. data/bench/blobapp/application.rb +44 -0
  26. data/bench/blobapp/config.ru +36 -0
  27. data/bench/blobapp/settings/license.key +1 -0
  28. data/bench/blobapp/settings/settings.yml +16 -0
  29. data/bench/blobapp/sources/blob_adapter.rb +71 -0
  30. data/bench/blobapp/spec/sources/blob_adapter_spec.rb +25 -0
  31. data/bench/blobapp/spec/spec_helper.rb +42 -0
  32. data/bench/lib/bench/cli.rb +16 -0
  33. data/bench/lib/bench/logging.rb +13 -0
  34. data/bench/lib/bench/mock_client.rb +41 -0
  35. data/bench/lib/bench/result.rb +50 -0
  36. data/bench/lib/bench/runner.rb +107 -0
  37. data/bench/lib/bench/session.rb +67 -0
  38. data/bench/lib/bench/statistics.rb +56 -0
  39. data/bench/lib/bench/test_data.rb +98 -0
  40. data/bench/lib/bench/timer.rb +10 -0
  41. data/bench/lib/bench/utils.rb +49 -0
  42. data/bench/lib/bench.rb +129 -0
  43. data/bench/lib/testdata/100-data.txt +148 -0
  44. data/bench/lib/testdata/5-data.txt +9 -0
  45. data/bench/lib/testdata/images/icon.ico +0 -0
  46. data/bench/lib/testdata/images/icon.png +0 -0
  47. data/bench/lib/testdata/images/loading-Landscape.png +0 -0
  48. data/bench/lib/testdata/images/loading-LandscapeLeft.png +0 -0
  49. data/bench/lib/testdata/images/loading-LandscapeRight.png +0 -0
  50. data/bench/lib/testdata/images/loading-Portrait.png +0 -0
  51. data/bench/lib/testdata/images/loading-PortraitUpsideDown.png +0 -0
  52. data/bench/lib/testdata/images/loading.png +0 -0
  53. data/bench/lib/testdata/images/loading@2x.png +0 -0
  54. data/bench/run_bench.sh +42 -0
  55. data/bench/run_blob_script.sh +3 -0
  56. data/bench/run_cud_script.sh +3 -0
  57. data/bench/run_query_md_script.sh +3 -0
  58. data/bench/run_query_only_script.sh +3 -0
  59. data/bench/run_query_script.sh +3 -0
  60. data/bench/scripts/blob_cud_script.rb +98 -0
  61. data/bench/scripts/cud_script.rb +92 -0
  62. data/bench/scripts/helpers.rb +101 -0
  63. data/bench/scripts/query_md_script.rb +45 -0
  64. data/bench/scripts/query_only_script.rb +51 -0
  65. data/bench/scripts/query_script.rb +45 -0
  66. data/bench/spec/bench_spec_helper.rb +33 -0
  67. data/bench/spec/logging_spec.rb +15 -0
  68. data/bench/spec/mock_adapter_spec.rb +61 -0
  69. data/bench/spec/mock_client_spec.rb +65 -0
  70. data/bench/spec/result_spec.rb +61 -0
  71. data/bench/spec/utils_spec.rb +36 -0
  72. data/bin/rhoconnect +34 -0
  73. data/bin/rhoconnect-setup +84 -0
  74. data/doc/async-jobs.txt +69 -0
  75. data/doc/authentication.txt +76 -0
  76. data/doc/benchmarks.txt +168 -0
  77. data/doc/blob-sync.txt +130 -0
  78. data/doc/bulk-sync.txt +102 -0
  79. data/doc/client.txt +432 -0
  80. data/doc/command-line.txt +210 -0
  81. data/doc/contributing.txt +60 -0
  82. data/doc/deploying.txt +82 -0
  83. data/doc/install.txt +28 -0
  84. data/doc/introduction.txt +20 -0
  85. data/doc/licensing.txt +18 -0
  86. data/doc/metadata.txt +458 -0
  87. data/doc/migration.txt +182 -0
  88. data/doc/public/css/print.css +29 -0
  89. data/doc/public/css/screen.css +257 -0
  90. data/doc/public/css/style.css +20 -0
  91. data/doc/push.txt +135 -0
  92. data/doc/release.txt +41 -0
  93. data/doc/rest-api.txt +367 -0
  94. data/doc/source-adapters.txt +325 -0
  95. data/doc/stats-middleware.txt +69 -0
  96. data/doc/testing.txt +222 -0
  97. data/doc/tutorial.txt +315 -0
  98. data/doc/web-console.txt +35 -0
  99. data/examples/simple/Rakefile +14 -0
  100. data/examples/simple/application.rb +27 -0
  101. data/examples/simple/config.ru +49 -0
  102. data/examples/simple/settings/license.key +1 -0
  103. data/examples/simple/settings/settings.yml +23 -0
  104. data/examples/simple/sources/sample_adapter.rb +5 -0
  105. data/examples/simple/sources/simple_adapter.rb +5 -0
  106. data/generators/rhoconnect.rb +119 -0
  107. data/generators/templates/application/Gemfile +21 -0
  108. data/generators/templates/application/Rakefile +22 -0
  109. data/generators/templates/application/application.rb +39 -0
  110. data/generators/templates/application/config.ru +36 -0
  111. data/generators/templates/application/settings/license.key +1 -0
  112. data/generators/templates/application/settings/settings.yml +14 -0
  113. data/generators/templates/application/spec/spec_helper.rb +42 -0
  114. data/generators/templates/source/source_adapter.rb +47 -0
  115. data/generators/templates/source/source_spec.rb +25 -0
  116. data/install.sh +408 -0
  117. data/installer/unix-like/rho_connect_install_checkers.rb +140 -0
  118. data/installer/unix-like/rho_connect_install_constants.rb +51 -0
  119. data/installer/unix-like/rho_connect_install_debian.rb +63 -0
  120. data/installer/unix-like/rho_connect_install_dnd.rb +58 -0
  121. data/installer/unix-like/rho_connect_install_get_params.rb +30 -0
  122. data/installer/unix-like/rho_connect_install_installers.rb +142 -0
  123. data/installer/unix-like/rho_connect_install_utilities.rb +85 -0
  124. data/installer/unix-like/rho_connect_install_yum.rb +63 -0
  125. data/installer/unix-like/rhoinstaller.rb +89 -0
  126. data/installer/utils/create_texts.rb +366 -0
  127. data/installer/utils/install_test.rb +140 -0
  128. data/installer/windows/EnvVarUpdate.nsh +328 -0
  129. data/installer/windows/ServiceLib.nsh +369 -0
  130. data/installer/windows/configUi.ini +44 -0
  131. data/installer/windows/icon.ico +0 -0
  132. data/installer/windows/rhosync.nsi +418 -0
  133. data/installer/windows/uninstall.bat +7 -0
  134. data/lib/rhoconnect/api/admin/get_api_token.rb +14 -0
  135. data/lib/rhoconnect/api/admin/get_license_info.rb +8 -0
  136. data/lib/rhoconnect/api/admin/login.rb +6 -0
  137. data/lib/rhoconnect/api/admin/reset.rb +10 -0
  138. data/lib/rhoconnect/api/admin/stats.rb +21 -0
  139. data/lib/rhoconnect/api/application/bulk_data.rb +7 -0
  140. data/lib/rhoconnect/api/application/clientcreate.rb +8 -0
  141. data/lib/rhoconnect/api/application/clientlogin.rb +6 -0
  142. data/lib/rhoconnect/api/application/clientregister.rb +6 -0
  143. data/lib/rhoconnect/api/application/clientreset.rb +6 -0
  144. data/lib/rhoconnect/api/application/query.rb +7 -0
  145. data/lib/rhoconnect/api/application/queue_updates.rb +6 -0
  146. data/lib/rhoconnect/api/application/search.rb +6 -0
  147. data/lib/rhoconnect/api/client/create_client.rb +3 -0
  148. data/lib/rhoconnect/api/client/delete_client.rb +5 -0
  149. data/lib/rhoconnect/api/client/get_client_params.rb +3 -0
  150. data/lib/rhoconnect/api/client/list_client_docs.rb +12 -0
  151. data/lib/rhoconnect/api/client/list_clients.rb +3 -0
  152. data/lib/rhoconnect/api/client/ping.rb +7 -0
  153. data/lib/rhoconnect/api/source/get_adapter.rb +3 -0
  154. data/lib/rhoconnect/api/source/get_db_doc.rb +7 -0
  155. data/lib/rhoconnect/api/source/get_source_params.rb +3 -0
  156. data/lib/rhoconnect/api/source/list_source_docs.rb +10 -0
  157. data/lib/rhoconnect/api/source/list_sources.rb +15 -0
  158. data/lib/rhoconnect/api/source/push_deletes.rb +8 -0
  159. data/lib/rhoconnect/api/source/push_objects.rb +8 -0
  160. data/lib/rhoconnect/api/source/save_adapter.rb +3 -0
  161. data/lib/rhoconnect/api/source/set_db_doc.rb +8 -0
  162. data/lib/rhoconnect/api/source/set_refresh_time.rb +8 -0
  163. data/lib/rhoconnect/api/source/upload_file.rb +4 -0
  164. data/lib/rhoconnect/api/user/create_user.rb +7 -0
  165. data/lib/rhoconnect/api/user/delete_user.rb +9 -0
  166. data/lib/rhoconnect/api/user/list_users.rb +3 -0
  167. data/lib/rhoconnect/api/user/update_user.rb +4 -0
  168. data/lib/rhoconnect/api_token.rb +19 -0
  169. data/lib/rhoconnect/app.rb +76 -0
  170. data/lib/rhoconnect/bulk_data/bulk_data.rb +88 -0
  171. data/lib/rhoconnect/bulk_data/syncdb.index.schema +4 -0
  172. data/lib/rhoconnect/bulk_data/syncdb.schema +41 -0
  173. data/lib/rhoconnect/bulk_data.rb +2 -0
  174. data/lib/rhoconnect/client.rb +96 -0
  175. data/lib/rhoconnect/client_sync.rb +412 -0
  176. data/lib/rhoconnect/console/app/helpers/auth_helper.rb +22 -0
  177. data/lib/rhoconnect/console/app/helpers/extensions.rb +19 -0
  178. data/lib/rhoconnect/console/app/helpers/helpers.rb +57 -0
  179. data/lib/rhoconnect/console/app/public/ThickBox.css +649 -0
  180. data/lib/rhoconnect/console/app/public/home.css +438 -0
  181. data/lib/rhoconnect/console/app/public/images/foot_logo_rhoconnect.png +0 -0
  182. data/lib/rhoconnect/console/app/public/images/header_halo.jpg +0 -0
  183. data/lib/rhoconnect/console/app/public/images/land_separator.gif +0 -0
  184. data/lib/rhoconnect/console/app/public/images/landing_header.jpg +0 -0
  185. data/lib/rhoconnect/console/app/public/images/logo_rhoconnect.png +0 -0
  186. data/lib/rhoconnect/console/app/public/images/rhomobile_rhohub_logo.png +0 -0
  187. data/lib/rhoconnect/console/app/public/images/tabs_separator.png +0 -0
  188. data/lib/rhoconnect/console/app/public/jqplot/excanvas.min.js +35 -0
  189. data/lib/rhoconnect/console/app/public/jqplot/jqplot.barRenderer.min.js +34 -0
  190. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisLabelRenderer.js +187 -0
  191. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisTickRenderer.js +226 -0
  192. data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasTextRenderer.js +408 -0
  193. data/lib/rhoconnect/console/app/public/jqplot/jqplot.categoryAxisRenderer.min.js +34 -0
  194. data/lib/rhoconnect/console/app/public/jqplot/jqplot.cursor.js +952 -0
  195. data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.js +313 -0
  196. data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.min.js +34 -0
  197. data/lib/rhoconnect/console/app/public/jqplot/jqplot.pointLabels.min.js +34 -0
  198. data/lib/rhoconnect/console/app/public/jqplot/jquery-1.4.2.min.js +154 -0
  199. data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.css +1 -0
  200. data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.js +34 -0
  201. data/lib/rhoconnect/console/app/public/main.css +7 -0
  202. data/lib/rhoconnect/console/app/public/reset.css +76 -0
  203. data/lib/rhoconnect/console/app/public/style.css +2201 -0
  204. data/lib/rhoconnect/console/app/public/text.txt +0 -0
  205. data/lib/rhoconnect/console/app/routes/adapter.rb +28 -0
  206. data/lib/rhoconnect/console/app/routes/auth.rb +29 -0
  207. data/lib/rhoconnect/console/app/routes/client.rb +31 -0
  208. data/lib/rhoconnect/console/app/routes/docs.rb +145 -0
  209. data/lib/rhoconnect/console/app/routes/heroku.rb +19 -0
  210. data/lib/rhoconnect/console/app/routes/home.rb +63 -0
  211. data/lib/rhoconnect/console/app/routes/timing.rb +242 -0
  212. data/lib/rhoconnect/console/app/routes/user.rb +117 -0
  213. data/lib/rhoconnect/console/app/views/adapter.erb +16 -0
  214. data/lib/rhoconnect/console/app/views/client.erb +30 -0
  215. data/lib/rhoconnect/console/app/views/content.erb +14 -0
  216. data/lib/rhoconnect/console/app/views/doc.erb +8 -0
  217. data/lib/rhoconnect/console/app/views/docdata.erb +28 -0
  218. data/lib/rhoconnect/console/app/views/docs.erb +30 -0
  219. data/lib/rhoconnect/console/app/views/edituser.erb +13 -0
  220. data/lib/rhoconnect/console/app/views/headermenu.erb +40 -0
  221. data/lib/rhoconnect/console/app/views/home.erb +24 -0
  222. data/lib/rhoconnect/console/app/views/index.erb +58 -0
  223. data/lib/rhoconnect/console/app/views/jqplot.erb +52 -0
  224. data/lib/rhoconnect/console/app/views/layout.erb +165 -0
  225. data/lib/rhoconnect/console/app/views/login.erb +26 -0
  226. data/lib/rhoconnect/console/app/views/newuser.erb +17 -0
  227. data/lib/rhoconnect/console/app/views/ping.erb +28 -0
  228. data/lib/rhoconnect/console/app/views/result.erb +11 -0
  229. data/lib/rhoconnect/console/app/views/rightboxlinks.erb +15 -0
  230. data/lib/rhoconnect/console/app/views/select_doc.erb +17 -0
  231. data/lib/rhoconnect/console/app/views/upload_doc.erb +23 -0
  232. data/lib/rhoconnect/console/app/views/user.erb +29 -0
  233. data/lib/rhoconnect/console/app/views/users.erb +12 -0
  234. data/lib/rhoconnect/console/rhoconnect_api.rb +245 -0
  235. data/lib/rhoconnect/console/server.rb +32 -0
  236. data/lib/rhoconnect/console.rb +3 -0
  237. data/lib/rhoconnect/cors.rb +229 -0
  238. data/lib/rhoconnect/credential.rb +9 -0
  239. data/lib/rhoconnect/db_adapter.rb +46 -0
  240. data/lib/rhoconnect/document.rb +49 -0
  241. data/lib/rhoconnect/dynamic_adapter.rb +91 -0
  242. data/lib/rhoconnect/generator.rb +1 -0
  243. data/lib/rhoconnect/jobs/bulk_data_job.rb +203 -0
  244. data/lib/rhoconnect/jobs/ping_job.rb +46 -0
  245. data/lib/rhoconnect/jobs/source_job.rb +16 -0
  246. data/lib/rhoconnect/license.rb +86 -0
  247. data/lib/rhoconnect/lock_ops.rb +11 -0
  248. data/lib/rhoconnect/model.rb +414 -0
  249. data/lib/rhoconnect/ping/android.rb +56 -0
  250. data/lib/rhoconnect/ping/apple.rb +52 -0
  251. data/lib/rhoconnect/ping/blackberry.rb +56 -0
  252. data/lib/rhoconnect/ping.rb +3 -0
  253. data/lib/rhoconnect/read_state.rb +31 -0
  254. data/lib/rhoconnect/rho_indifferent_access.rb +88 -0
  255. data/lib/rhoconnect/server/views/index.erb +13 -0
  256. data/lib/rhoconnect/server.rb +286 -0
  257. data/lib/rhoconnect/source.rb +289 -0
  258. data/lib/rhoconnect/source_adapter.rb +123 -0
  259. data/lib/rhoconnect/source_sync.rb +302 -0
  260. data/lib/rhoconnect/stats/middleware.rb +20 -0
  261. data/lib/rhoconnect/stats/record.rb +108 -0
  262. data/lib/rhoconnect/store.rb +232 -0
  263. data/lib/rhoconnect/tasks.rb +350 -0
  264. data/lib/rhoconnect/test_methods.rb +220 -0
  265. data/lib/rhoconnect/user.rb +95 -0
  266. data/lib/rhoconnect/version.rb +3 -0
  267. data/lib/rhoconnect/x_domain_session_wrapper.rb +53 -0
  268. data/lib/rhoconnect.rb +285 -0
  269. data/rhoconnect.gemspec +67 -0
  270. data/spec/api/admin/api_token_spec.rb +14 -0
  271. data/spec/api/admin/get_api_token_spec.rb +36 -0
  272. data/spec/api/admin/get_license_info_spec.rb +38 -0
  273. data/spec/api/admin/reset_spec.rb +22 -0
  274. data/spec/api/admin/stats_spec.rb +66 -0
  275. data/spec/api/api_helper.rb +21 -0
  276. data/spec/api/application/rhoconnect_api_spec.rb +548 -0
  277. data/spec/api/client/create_client_spec.rb +13 -0
  278. data/spec/api/client/delete_client_spec.rb +13 -0
  279. data/spec/api/client/get_client_params_spec.rb +18 -0
  280. data/spec/api/client/list_client_docs_spec.rb +32 -0
  281. data/spec/api/client/list_clients_spec.rb +22 -0
  282. data/spec/api/client/ping_spec.rb +23 -0
  283. data/spec/api/rhosync_api_spec.rb.orig +606 -0
  284. data/spec/api/source/adapter_spec.rb +29 -0
  285. data/spec/api/source/get_db_doc_spec.rb +21 -0
  286. data/spec/api/source/get_source_params_spec.rb +32 -0
  287. data/spec/api/source/list_source_docs_spec.rb +25 -0
  288. data/spec/api/source/list_sources_spec.rb +26 -0
  289. data/spec/api/source/push_deletes_spec.rb +18 -0
  290. data/spec/api/source/push_objects_spec.rb +27 -0
  291. data/spec/api/source/set_db_doc_spec.rb +19 -0
  292. data/spec/api/source/set_refresh_time_spec.rb +43 -0
  293. data/spec/api/source/upload_file_spec.rb +26 -0
  294. data/spec/api/user/create_user_spec.rb +16 -0
  295. data/spec/api/user/delete_user_spec.rb +36 -0
  296. data/spec/api/user/list_users_spec.rb +30 -0
  297. data/spec/api/user/update_user_spec.rb +31 -0
  298. data/spec/api_token_spec.rb +14 -0
  299. data/spec/app_spec.rb +18 -0
  300. data/spec/apps/emptyapp/application.rb +27 -0
  301. data/spec/apps/emptyapp/settings/license.key +1 -0
  302. data/spec/apps/emptyapp/settings/settings.yml +14 -0
  303. data/spec/apps/rhotestapp/Rakefile +1 -0
  304. data/spec/apps/rhotestapp/application.rb +19 -0
  305. data/spec/apps/rhotestapp/config.ru +1 -0
  306. data/spec/apps/rhotestapp/settings/apple_fake_cert.pem +1 -0
  307. data/spec/apps/rhotestapp/settings/license.key +1 -0
  308. data/spec/apps/rhotestapp/settings/settings.yml +36 -0
  309. data/spec/apps/rhotestapp/sources/base_adapter.rb +9 -0
  310. data/spec/apps/rhotestapp/sources/fixed_schema_adapter.rb +28 -0
  311. data/spec/apps/rhotestapp/sources/sample_adapter.rb +71 -0
  312. data/spec/apps/rhotestapp/sources/simple_adapter.rb +41 -0
  313. data/spec/apps/rhotestapp/sources/sub_adapter.rb +7 -0
  314. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem/mygem.rb +8 -0
  315. data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem.rb +1 -0
  316. data/spec/bulk_data/bulk_data_spec.rb +97 -0
  317. data/spec/client_spec.rb +124 -0
  318. data/spec/client_sync_spec.rb +774 -0
  319. data/spec/doc/base.html +72 -0
  320. data/spec/doc/doc_spec.rb +376 -0
  321. data/spec/doc/footer.html +4 -0
  322. data/spec/doc/header.html +30 -0
  323. data/spec/document_spec.rb +31 -0
  324. data/spec/dynamic_adapter_spec.rb +43 -0
  325. data/spec/factories/factories.rb +17 -0
  326. data/spec/generator/generator_spec.rb +58 -0
  327. data/spec/generator/generator_spec_helper.rb +9 -0
  328. data/spec/jobs/bulk_data_job_spec.rb +125 -0
  329. data/spec/jobs/ping_job_spec.rb +102 -0
  330. data/spec/jobs/source_job_spec.rb +29 -0
  331. data/spec/license_spec.rb +66 -0
  332. data/spec/model_spec.rb +273 -0
  333. data/spec/perf/bulk_data_perf_spec.rb +32 -0
  334. data/spec/perf/perf_spec_helper.rb +50 -0
  335. data/spec/perf/store_perf_spec.rb +27 -0
  336. data/spec/ping/android_spec.rb +91 -0
  337. data/spec/ping/apple_spec.rb +70 -0
  338. data/spec/ping/blackberry_spec.rb +62 -0
  339. data/spec/read_state_spec.rb +35 -0
  340. data/spec/rhosync_spec.rb +75 -0
  341. data/spec/server/cors_spec.rb +287 -0
  342. data/spec/server/server_spec.rb +470 -0
  343. data/spec/server/x_domain_session_wrapper_spec.rb +150 -0
  344. data/spec/source_adapter_spec.rb +125 -0
  345. data/spec/source_spec.rb +114 -0
  346. data/spec/source_sync_spec.rb +328 -0
  347. data/spec/spec.opts +4 -0
  348. data/spec/spec_helper.rb +231 -0
  349. data/spec/stats/middleware_spec.rb +53 -0
  350. data/spec/stats/record_spec.rb +92 -0
  351. data/spec/store_spec.rb +251 -0
  352. data/spec/support/shared_examples.rb +168 -0
  353. data/spec/sync_states_spec.rb +72 -0
  354. data/spec/test_methods_spec.rb +134 -0
  355. data/spec/testdata/1000-data.txt +1414 -0
  356. data/spec/testdata/compressed/compress-data.txt +1 -0
  357. data/spec/testdata/upload1.txt +1 -0
  358. data/spec/testdata/upload2.txt +1 -0
  359. data/spec/user_spec.rb +139 -0
  360. data/tasks/redis.rake +206 -0
  361. metadata +706 -0
@@ -0,0 +1,774 @@
1
+ require File.join(File.dirname(__FILE__),'spec_helper')
2
+ require File.join(File.dirname(__FILE__), 'support', 'shared_examples')
3
+
4
+
5
+ describe "ClientSync" do
6
+ it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do
7
+ it "should raise Argument error if no client is provided" do
8
+ lambda { ClientSync.new(@s,nil,2) }.should raise_error(ArgumentError,'Unknown client')
9
+ end
10
+
11
+ it "should handle receive cud for dymanic adapter" do
12
+ params = {'create'=>{'1'=>@product1}}
13
+ @c.source_name = 'Product2'
14
+ @cs1 = ClientSync.new(@s2,@c,2)
15
+ stub_request(:post, "http://test.rhoconnect.com/rhoconnect/authenticate")
16
+ stub_request(:post, "http://test.rhoconnect.com/rhoconnect/create").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5})
17
+ @cs1.receive_cud(params)
18
+ verify_result(@cs1.client.docname(:create) => {},
19
+ @cs1.client.docname(:update) => {},
20
+ @cs1.client.docname(:delete) => {})
21
+ end
22
+
23
+ it "should handle send cud for dynamic adapter" do
24
+ data = {'1'=>@product1}
25
+ expected = {'insert'=>data}
26
+ stub_request(:post, "http://test.rhoconnect.com/rhoconnect/authenticate")
27
+ stub_request(:post, "http://test.rhoconnect.com/rhoconnect/query").with(:headers => {'Content-Type' => 'application/json'}).to_return(:status => 200, :body => data.to_json)
28
+
29
+ @c.source_name = 'Product'
30
+ @cs1 = ClientSync.new(@s2,@c,2)
31
+
32
+ @cs1.send_cud.should == [{'version'=>ClientSync::VERSION},
33
+ {'token'=>@c.get_value(:page_token)},
34
+ {'count'=>data.size},{'progress_count'=>0},
35
+ {'total_count'=>data.size},expected]
36
+
37
+ verify_result(@cs1.client.docname(:page) => data,
38
+ @cs1.client.docname(:delete_page) => {},
39
+ @cs1.client.docname(:cd) => data)
40
+ end
41
+
42
+ let(:mock_schema) { {"property" => { "name" => "string", "brand" => "string" }, "version" => "1.0"} }
43
+ let(:sha1) { get_sha1(mock_schema.to_json) }
44
+
45
+ before(:each) do
46
+ @s = Source.load(@s_fields[:name],@s_params)
47
+ @cs = ClientSync.new(@s,@c,2)
48
+ end
49
+
50
+ it "should handle receive cud" do
51
+ params = {'create'=>{'1'=>@product1},'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
52
+ @cs.receive_cud(params)
53
+ verify_result(@cs.client.docname(:create) => {},
54
+ @cs.client.docname(:update) => {},
55
+ @cs.client.docname(:delete) => {})
56
+ end
57
+
58
+ it "should handle receive cud with pass through" do
59
+ params = {'create'=>{'1'=>@product1},'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
60
+ @s.pass_through = 'true'
61
+ @cs.receive_cud(params)
62
+ verify_result(@cs.client.docname(:create) => {},
63
+ @cs.client.docname(:update) => {},
64
+ @cs.client.docname(:delete) => {})
65
+ end
66
+
67
+ it "should handle exeptions in receive cud with pass through" do
68
+ params = {'create'=>{'1'=>@error},'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
69
+ @s.pass_through = 'true'
70
+ @cs.receive_cud(params)
71
+ verify_result(@cs.client.docname(:create) => {},
72
+ @cs.client.docname(:update) => {},
73
+ @cs.client.docname(:delete) => {})
74
+ end
75
+
76
+ it "should handle send cud" do
77
+ data = {'1'=>@product1,'2'=>@product2}
78
+ expected = {'insert'=>data}
79
+ set_test_data('test_db_storage',data)
80
+
81
+ @cs.send_cud.should == [{'version'=>ClientSync::VERSION},
82
+ {'token'=>@c.get_value(:page_token)},
83
+ {'count'=>data.size},{'progress_count'=>0},
84
+ {'total_count'=>data.size},expected]
85
+ verify_result(@cs.client.docname(:page) => data,
86
+ @cs.client.docname(:delete_page) => {},
87
+ @cs.client.docname(:cd) => data)
88
+ end
89
+
90
+ it "should handle send cud with pass_through" do
91
+ data = {'1'=>@product1,'2'=>@product2}
92
+ expected = {'insert'=>data}
93
+ set_test_data('test_db_storage',data)
94
+ @s.pass_through = 'true'
95
+ @cs.send_cud.should == [{'version'=>ClientSync::VERSION},
96
+ {'token'=>@c.get_value(:page_token)},
97
+ {'count'=>data.size},{'progress_count'=>0},
98
+ {'total_count'=>data.size},expected]
99
+ verify_result(@cs.client.docname(:page) => {},
100
+ @cs.client.docname(:cd) => {})
101
+ end
102
+
103
+ it "should handle send cud if with pass_through no data" do
104
+ data = {}
105
+ expected = {}
106
+ #set_test_data('test_db_storage',data)
107
+ @s.pass_through = 'true'
108
+ @cs.send_cud.should == [{'version'=>ClientSync::VERSION},
109
+ {'token'=>""},
110
+ {'count'=>data.size},{'progress_count'=>0},
111
+ {'total_count'=>data.size},expected]
112
+ verify_result(@cs.client.docname(:page) => {},
113
+ @cs.client.docname(:cd) => {})
114
+ end
115
+
116
+ it "should return read errors in send cud" do
117
+ msg = "Error during query"
118
+ data = {'1'=>@product1,'2'=>@product2}
119
+ set_test_data('test_db_storage',data,msg,'query error')
120
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},
121
+ {"token"=>""}, {"count"=>0}, {"progress_count"=>0},{"total_count"=>0},
122
+ {"source-error"=>{"query-error"=>{"message"=>msg}}}]
123
+ end
124
+
125
+ it "should return login errors in send cud" do
126
+ @u.login = nil
127
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},{"token"=>""},
128
+ {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
129
+ {'source-error'=>{"login-error"=>{"message"=>"Error logging in"}}}]
130
+ end
131
+
132
+ it "should return logoff errors in send cud" do
133
+ msg = "Error logging off"
134
+ set_test_data('test_db_storage',{},msg,'logoff error')
135
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},
136
+ {"token"=>@c.get_value(:page_token)},
137
+ {"count"=>1}, {"progress_count"=>0}, {"total_count"=>1},
138
+ {"source-error"=>{"logoff-error"=>{"message"=>msg}},
139
+ "insert"=>{ERROR=>{"name"=>"logoff error", "an_attribute"=>msg}}}]
140
+ end
141
+
142
+ describe "send errors in send_cud" do
143
+ it "should handle create errors" do
144
+ receive_and_send_cud('create')
145
+ end
146
+
147
+ it "should handle send cud" do
148
+ data = {'1'=>@product1,'2'=>@product2}
149
+ expected = {'insert'=>data}
150
+ set_test_data('test_db_storage',data)
151
+ @cs.send_cud.should == [{'version'=>ClientSync::VERSION},
152
+ {'token'=>@c.get_value(:page_token)},
153
+ {'count'=>data.size},{'progress_count'=>0},
154
+ {'total_count'=>data.size},expected]
155
+ verify_result(@cs.client.docname(:page) => data,
156
+ @cs.client.docname(:delete_page) => {},
157
+ @cs.client.docname(:cd) => data)
158
+ end
159
+
160
+ it "should return read errors in send cud" do
161
+ msg = "Error during query"
162
+ data = {'1'=>@product1,'2'=>@product2}
163
+ set_test_data('test_db_storage',data,msg,'query error')
164
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},
165
+ {"token"=>""}, {"count"=>0}, {"progress_count"=>0},{"total_count"=>0},
166
+ {"source-error"=>{"query-error"=>{"message"=>msg}}}]
167
+ end
168
+
169
+ it "should return login errors in send cud" do
170
+ @u.login = nil
171
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},{"token"=>""},
172
+ {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
173
+ {'source-error'=>{"login-error"=>{"message"=>"Error logging in"}}}]
174
+ end
175
+
176
+ it "should return logoff errors in send cud" do
177
+ msg = "Error logging off"
178
+ set_test_data('test_db_storage',{},msg,'logoff error')
179
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},
180
+ {"token"=>@c.get_value(:page_token)},
181
+ {"count"=>1}, {"progress_count"=>0}, {"total_count"=>1},
182
+ {"source-error"=>{"logoff-error"=>{"message"=>msg}},
183
+ "insert"=>{ERROR=>{"name"=>"logoff error", "an_attribute"=>msg}}}]
184
+ end
185
+
186
+ describe "send errors in send_cud" do
187
+ it "should handle create errors" do
188
+ receive_and_send_cud('create')
189
+ end
190
+
191
+ it "should handle update errors" do
192
+ broken_object = { ERROR => { 'price' => '99.99' } }
193
+ set_state(@c.docname(:cd) => broken_object)
194
+ set_test_data('test_db_storage',broken_object)
195
+ receive_and_send_cud('update')
196
+ end
197
+
198
+ it "should handle delete errors" do
199
+ msg = "Error delete record"
200
+ error_objs = add_error_object({},"Error delete record")
201
+ op_data = {'delete'=>error_objs}
202
+ @cs.receive_cud(op_data)
203
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},
204
+ {"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
205
+ {"delete-error"=>{"#{ERROR}-error"=>{"message"=>msg},ERROR=>error_objs[ERROR]}}]
206
+ end
207
+
208
+ it "should send cud errors only once" do
209
+ msg = "Error delete record"
210
+ error_objs = add_error_object({},"Error delete record")
211
+ op_data = {'delete'=>error_objs}
212
+ @cs.receive_cud(op_data)
213
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},
214
+ {"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
215
+ {"delete-error"=>{"#{ERROR}-error"=>{"message"=>msg},ERROR=>error_objs[ERROR]}}]
216
+ verify_result(@c.docname(:delete_errors) => {})
217
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},
218
+ {"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},{}]
219
+ end
220
+
221
+
222
+ end
223
+
224
+ it "should handle receive_cud" do
225
+ set_state(@s.docname(:md) => {'3'=>@product3},
226
+ @c.docname(:cd) => {'3'=>@product3})
227
+ params = {'create'=>{'1'=>@product1},
228
+ 'update'=>{'2'=>@product2},'delete'=>{'3'=>@product3}}
229
+ @cs.receive_cud(params)
230
+ verify_result(@cs.client.docname(:create) => {},
231
+ @cs.client.docname(:update) => {},
232
+ @cs.client.docname(:delete) => {},
233
+ @s.docname(:md) => {},
234
+ @c.docname(:cd) => {})
235
+ end
236
+
237
+ it "should handle blob upload in receive_cud" do
238
+ pending
239
+ end
240
+
241
+ it "should handle send_cud with query_params" do
242
+ expected = {'1'=>@product1}
243
+ set_state('test_db_storage' => {'1'=>@product1,'2'=>@product2,'4'=>@product4})
244
+ params = {'name' => 'iPhone'}
245
+ @cs.send_cud(nil,params)
246
+ verify_result(@s.docname(:md) => expected,
247
+ @cs.client.docname(:page) => expected)
248
+ end
249
+ end
250
+
251
+ describe "reset" do
252
+ it "should handle reset" do
253
+ set_state(@c.docname(:cd) => @data)
254
+ ClientSync.reset(@c)
255
+ verify_result(@c.docname(:cd) => {})
256
+ Client.load(@c.id,{:source_name => @s.name}).should_not be_nil
257
+ end
258
+
259
+ it "should handle reset on individual source adapters" do
260
+ @c.source_name = 'SampleAdapter'
261
+ set_state(@c.docname(:cd) => @data)
262
+ verify_result(@c.docname(:cd) => @data)
263
+
264
+ @c.source_name = 'SimpleAdapter'
265
+ set_state(@c.docname(:cd) => @data)
266
+ verify_result(@c.docname(:cd) => @data)
267
+
268
+ sources = [{'name'=>'SimpleAdapter'}]
269
+ ClientSync.reset(@c, {:sources => sources})
270
+
271
+ @c.source_name = 'SampleAdapter'
272
+ verify_result(@c.docname(:cd) => @data)
273
+ @c.source_name = 'SimpleAdapter'
274
+ verify_result(@c.docname(:cd) => {})
275
+ end
276
+ end
277
+
278
+ describe "search" do
279
+ before(:each) do
280
+ @s_fields[:name] = 'SimpleAdapter'
281
+ @c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
282
+ @s1 = Source.create(@s_fields,@s_params)
283
+ @cs1 = ClientSync.new(@s1,@c1,2)
284
+ end
285
+
286
+ def search_and_verify_res(params)
287
+ res = @cs.search(params)
288
+ token = @c.get_value(:search_token)
289
+ res[0]['version'].should == ClientSync::VERSION
290
+ res[1]['token'].should == token
291
+ res[2]['source'].should == @s.name
292
+ res[3]['count'].should == 1
293
+ res[4]['insert']
294
+ end
295
+
296
+ it "should handle search" do
297
+ params = {:search => {'name' => 'iPhone'}}
298
+ set_state('test_db_storage' => @data)
299
+ res = @cs.search(params)
300
+ token = @c.get_value(:search_token)
301
+ res.should == [{'version'=>ClientSync::VERSION},{'token'=>token},
302
+ {'source'=>@s.name},{'count'=>1},{'insert'=>{'1'=>@product1}}]
303
+ verify_result(@c.docname(:search) => {'1'=>@product1},
304
+ @c.docname(:search_errors) => {})
305
+ end
306
+
307
+ it "should handle search with no params" do
308
+ @cs.p_size = @data.size
309
+ set_state('test_db_storage' => @data)
310
+ res = @cs.search(nil)
311
+ token = @c.get_value(:search_token)
312
+ res.should == [{'version'=>ClientSync::VERSION},{'token'=>token},
313
+ {'source'=>@s.name},{'count'=>@data.size},{'insert'=>@data}]
314
+ verify_result(@c.docname(:search) => @data,
315
+ @c.docname(:search_errors) => {})
316
+ end
317
+
318
+ it "should handle search with more than one page" do
319
+ @cs.p_size = 1
320
+ params = {:search => {'name' => 'iPhone'}}
321
+ product4 = {'name' => 'iPhone', 'price' => '99.99'}
322
+ @data['4'] = product4
323
+ set_state('test_db_storage' => @data)
324
+ inserts = search_and_verify_res(params)
325
+ verify_result(@c.docname(:search) => {'1'=>@product1,'4'=>product4},
326
+ @c.docname(:cd_size) => '1',
327
+ @s.docname(:md_size) => '1',
328
+ @c.docname(:cd) => @c.get_data(:search_page),
329
+ @s.docname(:md) => @c.get_data(:search_page),
330
+ @c.docname(:search_errors) => {})
331
+
332
+ # ack the token
333
+ params[:token] = @c.get_value(:search_token)
334
+ new_inserts = search_and_verify_res(params)
335
+ inserts.merge!(new_inserts)
336
+ verify_result(@c.docname(:search) => {'1'=>@product1,'4'=>product4},
337
+ @c.docname(:cd) => inserts,
338
+ @s.docname(:md) => inserts,
339
+ @c.docname(:search_errors) => {})
340
+ @c.get_data(:search_page).size.should == 1
341
+
342
+ # ack the last token
343
+ params[:token] = @c.get_value(:search_token)
344
+ @cs.search(params).should == []
345
+ verify_result(@c.docname(:search) => {},
346
+ @c.docname(:cd) => inserts,
347
+ @s.docname(:md) => inserts,
348
+ @c.docname(:search_errors) => {},
349
+ @c.docname(:search_page) => {},
350
+ @cs.client.docname(:search_token) => nil)
351
+ end
352
+
353
+ it "should handle search with nil result" do
354
+ params = {:search => {'name' => 'foo'}}
355
+ set_state('test_db_storage' => @data)
356
+ @cs.search(params).should == []
357
+ verify_result(@c.docname(:search) => {},
358
+ @c.docname(:search_errors) => {})
359
+ end
360
+
361
+ it "should resend search by search_token" do
362
+ @source = @s
363
+ set_state({@c.docname(:search_page) => {'1'=>@product1}})
364
+ token = compute_token @cs.client.docname(:search_token)
365
+ @cs.search({:resend => true,:token => token}).should == [{'version'=>ClientSync::VERSION},
366
+ {'token'=>token},{'source'=>@s.name},{'count'=>1},{'insert'=>{'1'=>@product1}}]
367
+ verify_result(@c.docname(:search_page) => {'1'=>@product1},
368
+ @c.docname(:search_errors) => {},
369
+ @cs.client.docname(:search_token) => token)
370
+ end
371
+
372
+ it "should handle search ack" do
373
+ @source = @s
374
+ set_state({@c.docname(:search) => {'1'=>@product1}})
375
+ set_state({@c.docname(:cd) => {'1'=>@product1}})
376
+ token = compute_token @cs.client.docname(:search_token)
377
+ @cs.search({:token => token}).should == []
378
+ verify_result(@c.docname(:search) => {},
379
+ @c.docname(:search_errors) => {},
380
+ @cs.client.docname(:search_token) => nil)
381
+ end
382
+
383
+ it "should return error on invalid ack token" do
384
+ set_state({@c.docname(:search_page) => {'1'=>@product1}})
385
+ set_state({@c.docname(:search_token) => 'validtoken'})
386
+ @cs.search(
387
+ {:token => 'abc',
388
+ :search => {'name' => 'iPhone'}}
389
+ ).should == [{'version'=>ClientSync::VERSION},
390
+ {'source'=>@s.name},{'search-error'=>{'search-error'=>
391
+ {'message'=>"Search error - invalid token"}}}]
392
+ verify_result(@c.docname(:search) => {},
393
+ @c.docname(:search_errors) => {},
394
+ @cs.client.docname(:search_token) => nil)
395
+ end
396
+
397
+ it "should handle search all" do
398
+ sources = [{'name'=>'SampleAdapter'}]
399
+ set_state('test_db_storage' => @data)
400
+ res = ClientSync.search_all(@c,{:sources => sources,:search => {'name' => 'iPhone'}})
401
+ token = Store.get_value(@cs.client.docname(:search_token))
402
+ res.should == [[{'version'=>ClientSync::VERSION},{'token'=>token},
403
+ {'source'=>sources[0]['name']},{'count'=>1},{'insert'=>{'1'=>@product1}}]]
404
+ verify_result(@c.docname(:search) => {'1'=>@product1},
405
+ @c.docname(:search_errors) => {})
406
+ end
407
+
408
+ it "should handle search all for pass through" do
409
+ sources = [{'name'=>'SampleAdapter'}]
410
+ set_state('test_db_storage' => @data)
411
+ @s.pass_through = 'true'
412
+ res = ClientSync.search_all(@c,{:sources => sources,:search => {'name' => 'iPhone'}})
413
+ token = Store.get_value(@cs.client.docname(:search_token))
414
+ res.should == [[{'version'=>ClientSync::VERSION},{'token'=>token},
415
+ {'source'=>sources[0]['name']},{'count'=>1},{'insert'=>{'1'=>@product1}}]]
416
+ verify_result(@c.docname(:search) => {},
417
+ @c.docname(:search_errors) => {})
418
+ end
419
+
420
+ it "should handle search all error" do
421
+ sources = [{'name'=>'SampleAdapter'}]
422
+ msg = "Error during search"
423
+ error = set_test_data('test_db_storage',@data,msg,'search error')
424
+ res = ClientSync.search_all(@c,{:sources => sources,:search => {'name' => 'iPhone'}})
425
+ token = Store.get_value(@cs.client.docname(:search_token))
426
+ res.should == [[{'version'=>ClientSync::VERSION},
427
+ {'source'=>sources[0]['name']},{'search-error'=>{'search-error'=>{'message'=>msg}}}]]
428
+ verify_result(@c.docname(:search) => {})
429
+ end
430
+
431
+ it "should handle search all login error" do
432
+ @u.login = nil
433
+ sources = [{'name'=>'SampleAdapter'}]
434
+ msg = "Error logging in"
435
+ error = set_test_data('test_db_storage',@data,msg,'search error')
436
+ ClientSync.search_all(@c,{:sources => sources,:search => {'name' => 'iPhone'}}).should == [
437
+ [{'version'=>ClientSync::VERSION},{'source'=>sources[0]['name']},
438
+ {'search-error'=>{'login-error'=>{'message'=>msg}}}]]
439
+ verify_result(@c.docname(:search) => {},
440
+ @c.docname(:search_token) => nil)
441
+ end
442
+
443
+ it "should handle multiple source search all" do
444
+ set_test_data('test_db_storage',@data)
445
+ sources = [{'name'=>'SimpleAdapter'},{'name'=>'SampleAdapter'}]
446
+ res = ClientSync.search_all(@c,{:sources => sources,:search => {'name' => 'iPhone'}})
447
+ @c.source_name = 'SampleAdapter'
448
+ token = Store.get_value(@c.docname(:search_token))
449
+ res.sort.should == [[{"version"=>ClientSync::VERSION},{'token'=>token},
450
+ {"source"=>"SampleAdapter"},{"count"=>1},{"insert"=>{'1'=>@product1}}],[]].sort
451
+ end
452
+
453
+ it "should handle search and accumulate params" do
454
+ set_test_data('test_db_storage',@data)
455
+ sources = [{'name'=>'SimpleAdapter'},{'name'=>'SampleAdapter'}]
456
+ res = ClientSync.search_all(@c,{:sources => sources,:search => {'search'=>'bar'}})
457
+ @c.source_name = 'SimpleAdapter'
458
+ token = Store.get_value(@c.docname(:search_token))
459
+ @c.source_name = 'SampleAdapter'
460
+ token1 = Store.get_value(@c.docname(:search_token))
461
+ res.should == [[{"version"=>ClientSync::VERSION}, {'token'=>token},
462
+ {"source"=>"SimpleAdapter"},{"count"=>1},{"insert"=>{'obj'=>{'foo'=>'bar'}}}],
463
+ [{"version"=>ClientSync::VERSION},{'token'=>token1},{"source"=>"SampleAdapter"},
464
+ {"count"=>1}, {"insert"=>{'1'=>@product1}}]]
465
+ end
466
+
467
+ it "should handle search and ack of search results" do
468
+ set_test_data('test_db_storage',@data)
469
+ sources = [{'name'=>'SimpleAdapter'},{'name'=>'SampleAdapter'}]
470
+ ClientSync.search_all(@c,{:sources => sources,:search => {'search'=>'bar'}})
471
+ @c.source_name = 'SimpleAdapter'
472
+ token = Store.get_value(@c.docname(:search_token))
473
+ token.should_not be_nil
474
+ sources[0]['token'] = token
475
+ Store.get_data(@c.docname(:search)).should == {'obj'=>{'foo'=>'bar'}}
476
+ @c.source_name = 'SampleAdapter'
477
+ token1 = Store.get_value(@c.docname(:search_token))
478
+ token1.should_not be_nil
479
+ sources[1]['token'] = token1
480
+ Store.get_data(@c.docname(:search)).should == {'1'=>@product1}
481
+ # do ack on multiple sources
482
+ res = ClientSync.search_all(@c,{:sources => sources,:search => {'search'=>'bar'}})
483
+ @c.source_name = 'SimpleAdapter'
484
+ token = Store.get_value(@c.docname(:search_token))
485
+ token.should be_nil
486
+ Store.get_data(@c.docname(:search)).should == {}
487
+ @c.source_name = 'SampleAdapter'
488
+ token1 = Store.get_value(@c.docname(:search_token))
489
+ token1.should be_nil
490
+ Store.get_data(@c.docname(:search)).should == {}
491
+ end
492
+
493
+ end
494
+
495
+ describe "page methods" do
496
+ it "should return diffs between master documents and client documents limited by page size" do
497
+ Store.put_data(@s.docname(:md),@data).should == true
498
+ Store.get_data(@s.docname(:md)).should == @data
499
+ Store.put_value(@s.docname(:md_size),@data.size)
500
+ @expected = {'1'=>@product1,'2'=>@product2}
501
+ @cs.compute_page.should == [0,3,@expected]
502
+ Store.get_value(@cs.client.docname(:cd_size)).to_i.should == 0
503
+ Store.get_data(@cs.client.docname(:page)).should == @expected
504
+ end
505
+
506
+ it "appends diff to the client document" do
507
+ @cd = {'3'=>@product3}
508
+ Store.put_data(@c.docname(:cd),@cd)
509
+ Store.get_data(@c.docname(:cd)).should == @cd
510
+
511
+ @page = {'1'=>@product1,'2'=>@product2}
512
+ @expected = {'1'=>@product1,'2'=>@product2,'3'=>@product3}
513
+
514
+ Store.put_data(@c.docname(:cd),@page,true).should == true
515
+ Store.get_data(@c.docname(:cd)).should == @expected
516
+ end
517
+
518
+ it "should return deleted objects in the client document" do
519
+ Store.put_data(@s.docname(:md),@data).should == true
520
+ Store.get_data(@s.docname(:md)).should == @data
521
+
522
+ @cd = {'1'=>@product1,'2'=>@product2,'3'=>@product3,'4'=>@product4}
523
+ Store.put_data(@cs.client.docname(:cd),@cd)
524
+ Store.get_data(@cs.client.docname(:cd)).should == @cd
525
+
526
+ @expected = {'4'=>@product4}
527
+ @cs.compute_deleted_page.should == @expected
528
+ Store.get_data(@cs.client.docname(:delete_page)).should == @expected
529
+ end
530
+
531
+ it "should delete objects from client document" do
532
+ Store.put_data(@s.docname(:md),@data).should == true
533
+ Store.get_data(@s.docname(:md)).should == @data
534
+
535
+ @cd = {'1'=>@product1,'2'=>@product2,'3'=>@product3,'4'=>@product4}
536
+ Store.put_data(@cs.client.docname(:cd),@cd)
537
+ Store.get_data(@cs.client.docname(:cd)).should == @cd
538
+
539
+ Store.delete_data(@cs.client.docname(:cd),@cs.compute_deleted_page).should == true
540
+ Store.get_data(@cs.client.docname(:cd)).should == @data
541
+ end
542
+
543
+ it "should resend page if page exists and no token provided" do
544
+ expected = {'1'=>@product1}
545
+ set_test_data('test_db_storage',{'1'=>@product1,'2'=>@product2,'4'=>@product4})
546
+ params = {'name' => 'iPhone'}
547
+ @cs.send_cud(nil,params)
548
+ token = @c.get_value(:page_token)
549
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},{"token"=>token},
550
+ {"count"=>1}, {"progress_count"=>0},{"total_count"=>1},{'insert' => expected}]
551
+ @cs.send_cud(token).should == [{"version"=>ClientSync::VERSION},{"token"=>""},
552
+ {"count"=>0}, {"progress_count"=>1}, {"total_count"=>1}, {}]
553
+ Store.get_data(@cs.client.docname(:page)).should == {}
554
+ @c.get_value(:page_token).should be_nil
555
+ end
556
+
557
+ it "should send metadata with page" do
558
+ expected = {'1'=>@product1}
559
+ set_state('test_db_storage' => expected)
560
+ metadata = "{\"foo\":\"bar\"}"
561
+ mock_metadata_method([SampleAdapter]) do
562
+ result = @cs.send_cud
563
+ token = @c.get_value(:page_token)
564
+ result.should == [{"version"=>ClientSync::VERSION},{"token"=>token},
565
+ {"count"=>1}, {"progress_count"=>0},{"total_count"=>1},
566
+ {'metadata'=>metadata,'insert'=>expected}]
567
+ @c.get_value(:metadata_page).should == metadata
568
+ end
569
+ end
570
+
571
+ it "should send metadata with resend page" do
572
+ expected = {'1'=>@product1}
573
+ set_state('test_db_storage' => expected)
574
+ mock_metadata_method([SampleAdapter]) do
575
+ result = @cs.send_cud
576
+ token = @c.get_value(:page_token)
577
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},{"token"=>token},
578
+ {"count"=>1}, {"progress_count"=>0},{"total_count"=>1},
579
+ {'metadata'=>"{\"foo\":\"bar\"}",'insert'=>expected}]
580
+ end
581
+ end
582
+
583
+ it "should ack metadata page with ack token" do
584
+ expected = {'1'=>@product1}
585
+ set_state('test_db_storage' => expected)
586
+ mock_metadata_method([SampleAdapter]) do
587
+ result = @cs.send_cud
588
+ token = @c.get_value(:page_token)
589
+ @cs.send_cud(token).should == [{"version"=>ClientSync::VERSION},{"token"=>""},
590
+ {"count"=>0}, {"progress_count"=>1},{"total_count"=>1},{}]
591
+ @c.get_value(:metadata_page).should be_nil
592
+ end
593
+ end
594
+
595
+ it "shouldn't send schema-changed if client schema sha1 is nil" do
596
+ expected = {'1'=>@product1}
597
+ set_state('test_db_storage' => expected)
598
+ mock_schema_method([SampleAdapter]) do
599
+ result = @cs.send_cud
600
+ token = @c.get_value(:page_token)
601
+ result.should == [{"version"=>ClientSync::VERSION},{"token"=>token},
602
+ {"count"=>1}, {"progress_count"=>0},{"total_count"=>1},{'insert'=>expected}]
603
+ @c.get_value(:schema_sha1).should == sha1
604
+ end
605
+ end
606
+
607
+ it "should send schema-changed instead of page" do
608
+ mock_schema_method([SampleAdapter]) do
609
+ @c.put_value(:schema_sha1,'foo')
610
+ result = @cs.send_cud
611
+ token = @c.get_value(:page_token)
612
+ result.should == [{"version"=>ClientSync::VERSION},{"token"=>token},
613
+ {"count"=>0}, {"progress_count"=>0},{"total_count"=>0},{'schema-changed'=>'true'}]
614
+ @c.get_value(:schema_page).should == sha1
615
+ @c.get_value(:schema_sha1).should == sha1
616
+ end
617
+ end
618
+
619
+ it "should re-send schema-changed if no token sent" do
620
+ mock_schema_method([SampleAdapter]) do
621
+ @c.put_value(:schema_sha1,'foo')
622
+ result = @cs.send_cud
623
+ token = @c.get_value(:page_token)
624
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},{"token"=>token},
625
+ {"count"=>0}, {"progress_count"=>0},{"total_count"=>0},{'schema-changed'=>'true'}]
626
+ @c.get_value(:schema_page).should == sha1
627
+ @c.get_value(:schema_sha1).should == sha1
628
+ end
629
+ end
630
+
631
+ it "should ack schema-changed with token" do
632
+ mock_schema_method([SampleAdapter]) do
633
+ @c.put_value(:schema_sha1,'foo')
634
+ result = @cs.send_cud
635
+ token = @c.get_value(:page_token)
636
+ @cs.send_cud(token).should == [{"version"=>ClientSync::VERSION},{"token"=>""},
637
+ {"count"=>0}, {"progress_count"=>0},{"total_count"=>0},{}]
638
+ @c.get_value(:schema_page).should be_nil
639
+ @c.get_value(:schema_sha1).should == sha1
640
+ end
641
+ end
642
+
643
+ it "should expire bulk data if schema changed" do
644
+ docname = bulk_data_docname(@a.id,@u.id)
645
+ data = BulkData.create(:name => docname,
646
+ :state => :inprogress,
647
+ :app_id => @a.id,
648
+ :user_id => @u.id,
649
+ :sources => [@s_fields[:name]])
650
+ data.refresh_time = Time.now.to_i + 600
651
+ mock_schema_method([SampleAdapter]) do
652
+ @c.put_value(:schema_sha1,'foo')
653
+ result = @cs.send_cud
654
+ token = @c.get_value(:page_token)
655
+ @cs.send_cud(token).should == [{"version"=>ClientSync::VERSION},{"token"=>""},
656
+ {"count"=>0}, {"progress_count"=>0},{"total_count"=>0},{}]
657
+ @c.get_value(:schema_page).should be_nil
658
+ @c.get_value(:schema_sha1).should == sha1
659
+ data = BulkData.load(docname)
660
+ data.refresh_time.should <= Time.now.to_i
661
+ end
662
+ end
663
+ end
664
+
665
+ describe "bulk data" do
666
+ after(:each) do
667
+ delete_data_directory
668
+ end
669
+
670
+ it "should create bulk data job user parition if none exists" do
671
+ ClientSync.bulk_data(:user,@c).should == {:result => :wait}
672
+ Resque.peek(:bulk_data).should == {"args"=>
673
+ [{"data_name"=>File.join(@a_fields[:name],@u_fields[:login],@u_fields[:login])}],
674
+ "class"=>"Rhoconnect::BulkDataJob"}
675
+ end
676
+
677
+ it "should create bulk data job app partition if none exists and no partition sources" do
678
+ @s2.delete
679
+ @a.sources.delete("SimpleAdapter")
680
+ ClientSync.bulk_data(:app,@c).should == {:result => :nop}
681
+ Resque.peek(:bulk_data).should == nil
682
+ end
683
+
684
+ it "should create bulk data job app partition with partition sources" do
685
+ @s.partition = :app
686
+ ClientSync.bulk_data(:app,@c).should == {:result => :wait}
687
+ Resque.peek(:bulk_data).should == {"args"=>
688
+ [{"data_name"=>File.join(@a_fields[:name],@a_fields[:name])}],
689
+ "class"=>"Rhoconnect::BulkDataJob"}
690
+ end
691
+
692
+ it "should return bulk data url for completed bulk data user partition" do
693
+ set_state('test_db_storage' => @data)
694
+ ClientSync.bulk_data(:user,@c)
695
+ BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
696
+ ClientSync.bulk_data(:user,@c).should == {:result => :url,
697
+ :url => BulkData.load(bulk_data_docname(@a.id,@u.id)).url}
698
+ verify_result(
699
+ "client:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@c.id}:#{@s_fields[:name]}:cd" => @data,
700
+ "source:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@s_fields[:name]}:md" => @data,
701
+ "source:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@s_fields[:name]}:md_copy" => @data)
702
+ end
703
+
704
+ it "should escape bulk data url" do
705
+ name = 'a b'
706
+ data = BulkData.create(:name => bulk_data_docname(@a.id,name),
707
+ :state => :inprogress,
708
+ :app_id => @a.id,
709
+ :user_id => name,
710
+ :sources => [@s_fields[:name]])
711
+ BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,name))
712
+ data = BulkData.load(bulk_data_docname(@a.id,name))
713
+ data.url.should match /a%20b/
714
+ data.delete
715
+ end
716
+
717
+ it "should return bulk data url for completed bulk data app partition" do
718
+ set_state('test_db_storage' => @data)
719
+ @s.partition = :app
720
+ ClientSync.bulk_data(:app,@c)
721
+ BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,"*"))
722
+ ClientSync.bulk_data(:app,@c).should == {:result => :url,
723
+ :url => BulkData.load(bulk_data_docname(@a.id,"*")).url}
724
+ verify_result(
725
+ "client:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@c.id}:#{@s_fields[:name]}:cd" => @data,
726
+ "source:#{@a_fields[:name]}:__shared__:#{@s_fields[:name]}:md" => @data,
727
+ "source:#{@a_fields[:name]}:__shared__:#{@s_fields[:name]}:md_copy" => @data)
728
+ end
729
+
730
+ it "should return bulk data url for completed bulk data with bulk_sync_only source" do
731
+ set_state('test_db_storage' => @data)
732
+ @s.sync_type = :bulk_sync_only
733
+ ClientSync.bulk_data(:user,@c)
734
+ BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
735
+ ClientSync.bulk_data(:user,@c).should == {:result => :url,
736
+ :url => BulkData.load(bulk_data_docname(@a.id,@u.id)).url}
737
+ verify_result(
738
+ "client:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@c.id}:#{@s_fields[:name]}:cd" => {},
739
+ "source:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@s_fields[:name]}:md" => @data,
740
+ "source:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@s_fields[:name]}:md_copy" => {})
741
+ end
742
+
743
+ it "should create bulk data job if no file exists" do
744
+ set_state('test_db_storage' => @data)
745
+ Rhoconnect.blackberry_bulk_sync = true
746
+ ClientSync.bulk_data(:user,@c)
747
+ BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
748
+ data = BulkData.load(bulk_data_docname(@a.id,@u.id))
749
+ ClientSync.bulk_data(:user,@c).should == {:result => :url, :url => data.url}
750
+ File.delete(data.dbfile)
751
+ ClientSync.bulk_data(:user,@c).should == {:result => :wait}
752
+ Resque.peek(:bulk_data).should == {"args"=>
753
+ [{"data_name"=>bulk_data_docname(@a.id,@u.id)}], "class"=>"Rhoconnect::BulkDataJob"}
754
+ end
755
+ end
756
+ end
757
+ def receive_and_send_cud(operation)
758
+ msg = "Error #{operation} record"
759
+ op_data = {operation=>{ERROR=>{'an_attribute'=>msg,'name'=>'wrongname'}}}
760
+ @cs.receive_cud(op_data)
761
+ if operation == 'update'
762
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},
763
+ {"token"=>""}, {"count"=>0}, {"progress_count"=>1}, {"total_count"=>1},
764
+ {
765
+ "update-rollback"=>{"0_broken_object_id"=>{"price"=>"99.99"}},
766
+ "#{operation}-error"=>{"#{ERROR}-error"=>{"message"=>msg},ERROR=>op_data[operation][ERROR]}
767
+ }]
768
+ else
769
+ @cs.send_cud.should == [{"version"=>ClientSync::VERSION},
770
+ {"token"=>""}, {"count"=>0}, {"progress_count"=>0}, {"total_count"=>0},
771
+ {"#{operation}-error"=>{"#{ERROR}-error"=>{"message"=>msg},ERROR=>op_data[operation][ERROR]}}]
772
+ end
773
+ end
774
+ end