rhoconnect 3.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,548 @@
1
+ require File.join(File.dirname(__FILE__),'..','..','..','lib','rhoconnect','console','rhoconnect_api.rb')
2
+ require File.join(File.dirname(__FILE__),'..','api_helper')
3
+
4
+ describe "RhoconnectApi" do
5
+ it_should_behave_like "ApiHelper" do
6
+
7
+ before(:each) do
8
+ @s = Source.load(@s_fields[:name],@s_params)
9
+ end
10
+
11
+ it "should return api token using direct api call" do
12
+ RhoconnectApi::get_token('','rhoadmin','').should == @api_token
13
+ end
14
+
15
+ it "should get adapter using direct api call" do
16
+ RhoconnectApi::get_adapter('',@api_token)
17
+ Rhoconnect.appserver.should == "http://test.rhoconnect.com"
18
+ end
19
+
20
+ it "should get adapter using rest call" do
21
+ res = mock('HttpResponse')
22
+ res.stub!(:body).and_return(["http://test.rhoconnect.com"].to_json)
23
+ RestClient.stub(:post).and_return(res)
24
+ RestClient.should_receive(:post).once
25
+ RhoconnectApi::get_adapter('some_url',@api_token).should == ["http://test.rhoconnect.com"]
26
+ end
27
+
28
+ it "should save adapter using direct api call" do
29
+ RhoconnectApi::save_adapter('',@api_token,'http://test.com')
30
+ Rhoconnect.appserver.should == 'http://test.com'
31
+ end
32
+
33
+ it "should save adapter using rest call" do
34
+ RestClient.stub(:post).and_return("adpater url saved")
35
+ RestClient.should_receive(:post).once
36
+ RhoconnectApi::save_adapter('some_url',@api_token,'http://test.com').should == "adpater url saved"
37
+ end
38
+
39
+ it "should return api token using rest call" do
40
+ res = mock('HttpResponse')
41
+ res.stub!(:body).and_return(@api_token)
42
+ RestClient.stub(:post).and_return(res)
43
+ RestClient.should_receive(:post).once
44
+ RhoconnectApi::get_token('some_url','rhoadmin','').should == @api_token
45
+ end
46
+
47
+ it "should list users using direct api call" do
48
+ RhoconnectApi::list_users('',@api_token).should == ['testuser']
49
+ end
50
+
51
+ it "should list users using rect call" do
52
+ res = mock('HttpResponse')
53
+ res.stub!(:body).and_return(['testuser'].to_json)
54
+ RestClient.stub(:post).and_return(res)
55
+ RestClient.should_receive(:post).once
56
+ RhoconnectApi::list_users('some_url',@api_token).should == ['testuser']
57
+ end
58
+
59
+ it "should create user using direct api call" do
60
+ RhoconnectApi::create_user('',@api_token,'testuser1','testpass1')
61
+ User.load('testuser1').login.should == 'testuser1'
62
+ User.authenticate('testuser1','testpass1').login.should == 'testuser1'
63
+ @a.users.members.sort.should == [@u.login, 'testuser1']
64
+ end
65
+
66
+ it "should create user using rect call" do
67
+ RestClient.stub(:post).and_return("User created")
68
+ RestClient.should_receive(:post).once
69
+ RhoconnectApi::create_user('some_url',@api_token,'testuser1','testpass1').should == "User created"
70
+ end
71
+
72
+ it "should update user using direct api call" do
73
+ RhoconnectApi::update_user('',@api_token, {:new_password => '123'})
74
+ User.authenticate('rhoadmin','123').login.should == 'rhoadmin'
75
+ end
76
+
77
+ it "should delete user using rect call" do
78
+ RestClient.stub(:post).and_return("User deleted")
79
+ RestClient.should_receive(:post).once
80
+ RhoconnectApi::delete_user('some_url',@api_token,'testuser1').should == "User deleted"
81
+ end
82
+
83
+ it "should list clients using direct api call" do
84
+ res = RhoconnectApi::list_clients('',@api_token,@u_fields[:login])
85
+ res.is_a?(Array).should == true
86
+ res.size.should == 1
87
+ res[0].is_a?(String) == true
88
+ res[0].length.should == 32
89
+ end
90
+
91
+ it "should handle empty client's list" do
92
+ @u.clients.delete(@c.id)
93
+ RhoconnectApi::list_clients('',@api_token,@u_fields[:login]).should == []
94
+ end
95
+
96
+ it "should create user using rect call" do
97
+ res = mock('HttpResponse')
98
+ res.stub!(:body).and_return(["21325fd9911044c6ad974785bf23c173"].to_json)
99
+ RestClient.stub(:post).and_return(res)
100
+ RestClient.should_receive(:post).once
101
+ RhoconnectApi::list_clients('some_url',@api_token,'testuser1').should == ["21325fd9911044c6ad974785bf23c173"]
102
+ end
103
+
104
+ it "should create client for a user using direct api call" do
105
+ RhoconnectApi::create_client('',@api_token,@u_fields[:login])
106
+ clients = User.load(@u_fields[:login]).clients.members
107
+ clients.size.should == 2
108
+ end
109
+
110
+ it "should create client using rect call" do
111
+ res = mock('HttpResponse')
112
+ res.stub!(:body).and_return("")
113
+ RestClient.stub(:post).and_return(res)
114
+ RestClient.should_receive(:post).once
115
+ RhoconnectApi::create_client('some_url',@api_token,'testuser1')
116
+ end
117
+
118
+ it "should delete client using direct api call" do
119
+ RhoconnectApi::delete_client('',@api_token,@u_fields[:login],@c.id).should == "Client deleted"
120
+ Client.is_exist?(@c.id).should == false
121
+ User.load(@u_fields[:login]).clients.members.should == []
122
+ end
123
+
124
+ it "should delete client using rect call" do
125
+ RestClient.stub(:post).and_return("Client deleted")
126
+ RestClient.should_receive(:post).once
127
+ RhoconnectApi::delete_client('some_url',@api_token,@u_fields[:login],@c.id).should == "Client deleted"
128
+ end
129
+
130
+ it "should list client attributes using direct api call" do
131
+ res = RhoconnectApi::get_client_params('',@api_token,@c.id)
132
+ res.delete_if { |attrib| attrib['name'] == 'rho__id' || attrib['name'] == 'last_sync'}
133
+ res.sort{|x,y| x['name']<=>y['name']}.should == [
134
+ {"name"=>"device_type", "value"=>"Apple", "type"=>"string"},
135
+ {"name"=>"device_pin", "value"=>"abcd", "type"=>"string"},
136
+ {"name"=>"device_port", "value"=>"3333", "type"=>"string"},
137
+ {"name"=>"user_id", "value"=>"testuser", "type"=>"string"},
138
+ {"name"=>"phone_id", "value"=>nil, "type"=>"string"},
139
+ {"name"=>"app_id", "value"=>"application", "type"=>"string"}].sort{|x,y| x['name']<=>y['name']}
140
+ end
141
+
142
+ it "should list client attributes using rest call" do
143
+ res = mock('HttpResponse')
144
+ res.stub!(:body).and_return(["blah"].to_json)
145
+ RestClient.stub(:post).and_return(res)
146
+ RestClient.should_receive(:post).once
147
+ RhoconnectApi::get_client_params('some_url',@api_token,'client_id')
148
+ end
149
+
150
+ it "should list all application sources using direct api call" do
151
+ RhoconnectApi::list_sources('',@api_token).sort.should ==
152
+ ["SimpleAdapter", "SampleAdapter", "FixedSchemaAdapter"].sort
153
+ end
154
+
155
+ it "should list all application sources using rest call" do
156
+ res = mock('HttpResponse')
157
+ res.stub!(:body).and_return(["SimpleAdapter", "SampleAdapter", "FixedSchemaAdapter"].to_json)
158
+ RestClient.stub(:post).and_return(res)
159
+ RestClient.should_receive(:post).once
160
+ RhoconnectApi::list_sources('some_url',@api_token)
161
+ end
162
+
163
+ it "should list source attributes using direct api call" do
164
+ result = RhoconnectApi::get_source_params(
165
+ '',@api_token,"SampleAdapter").sort {|x,y| x["name"] <=> y["name"] }
166
+ result.should == [
167
+ {"name"=>"rho__id", "value"=>"SampleAdapter", "type"=>"string"},
168
+ {"name"=>"source_id", "value"=>nil, "type"=>"integer"},
169
+ {"name"=>"name", "value"=>"SampleAdapter", "type"=>"string"},
170
+ {"name"=>"url", "value"=>"http://example.com", "type"=>"string"},
171
+ {"name"=>"login", "value"=>"testuser", "type"=>"string"},
172
+ {"name"=>"password", "value"=>"testpass", "type"=>"string"},
173
+ {"name"=>"priority", "value"=>3, "type"=>"integer"},
174
+ {"name"=>"callback_url", "value"=>nil, "type"=>"string"},
175
+ {"name"=>"poll_interval", "value"=>300, "type"=>"integer"},
176
+ {"name"=>"partition_type", "value"=>"user", "type"=>"string"},
177
+ {"name"=>"sync_type", "value"=>"incremental", "type"=>"string"},
178
+ {"name"=>"belongs_to", "type"=>"string", "value"=>nil},
179
+ {"name"=>"has_many", "type"=>"string", "value"=>"FixedSchemaAdapter,brand"},
180
+ {"name"=>"id", "value"=>"SampleAdapter", "type"=>"string"},
181
+ {"name"=>"queue", "value"=>nil, "type"=>"string"},
182
+ {"name"=>"query_queue", "value"=>nil, "type"=>"string"},
183
+ {"name"=>"cud_queue", "value"=>nil, "type"=>"string"},
184
+ {"name"=>"pass_through", "value"=>nil, "type"=>"string"}].sort {|x,y| x["name"] <=> y["name"] }
185
+ end
186
+
187
+ it "should list source attributes using rest call" do
188
+ res = mock('HttpResponse')
189
+ res.stub!(:body).and_return(["SimpleAdapter"].to_json)
190
+ RestClient.stub(:post).and_return(res)
191
+ RestClient.should_receive(:post).once
192
+ RhoconnectApi::get_source_params('some_url',@api_token,"SimpleAdapter")
193
+ end
194
+
195
+ it "should list of shared source documents using direct api call" do
196
+ RhoconnectApi::list_source_docs('',@api_token,"SimpleAdapter","*").sort.should == {
197
+ "md"=>"source:application:__shared__:SimpleAdapter:md",
198
+ "errors"=>"source:application:__shared__:SimpleAdapter:errors",
199
+ "md_size"=>"source:application:__shared__:SimpleAdapter:md_size",
200
+ "md_copy"=>"source:application:__shared__:SimpleAdapter:md_copy"}.sort
201
+ end
202
+
203
+ it "should list of shared source documents using rest call" do
204
+ res = mock('HttpResponse')
205
+ res.stub!(:body).and_return(["SimpleAdapter"].to_json)
206
+ RestClient.stub(:post).and_return(res)
207
+ RestClient.should_receive(:post).once
208
+ RhoconnectApi::list_source_docs('some_url',@api_token,"SimpleAdapter",'*')
209
+ end
210
+
211
+ it "should list client documents using direct api call" do
212
+ RhoconnectApi::list_client_docs('',@api_token,"SimpleAdapter",@c.id).should == {
213
+ "cd"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd",
214
+ "cd_size"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd_size",
215
+ "create"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create",
216
+ "update"=>"client:application:testuser:#{@c.id}:SimpleAdapter:update",
217
+ "delete"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete",
218
+
219
+ "page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:page",
220
+ "page_token"=>"client:application:testuser:#{@c.id}:SimpleAdapter:page_token",
221
+ "delete_page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete_page",
222
+ "create_links"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_links",
223
+ "create_links_page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_links_page",
224
+
225
+ "delete_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete_errors",
226
+ "login_error"=>"client:application:testuser:#{@c.id}:SimpleAdapter:login_error",
227
+ "create_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_errors",
228
+ "update_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:update_errors",
229
+ "logoff_error"=>"client:application:testuser:#{@c.id}:SimpleAdapter:logoff_error",
230
+
231
+ "search"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search",
232
+ "search_token"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search_token",
233
+ "search_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search_errors"}
234
+ end
235
+
236
+ it "should list users using direct api call" do
237
+ RhoconnectApi::list_users('',@api_token).should == ['testuser']
238
+ end
239
+
240
+ it "should list users using rect call" do
241
+ res = mock('HttpResponse')
242
+ res.stub!(:body).and_return(['testuser'].to_json)
243
+ RestClient.stub(:post).and_return(res)
244
+ RestClient.should_receive(:post).once
245
+ RhoconnectApi::list_users('some_url',@api_token).should == ['testuser']
246
+ end
247
+
248
+ it "should create user using direct api call" do
249
+ RhoconnectApi::create_user('',@api_token,'testuser1','testpass1')
250
+ User.load('testuser1').login.should == 'testuser1'
251
+ User.authenticate('testuser1','testpass1').login.should == 'testuser1'
252
+ @a.users.members.sort.should == [@u.login, 'testuser1']
253
+ end
254
+
255
+ it "should create user using rect call" do
256
+ RestClient.stub(:post).and_return("User created")
257
+ RestClient.should_receive(:post).once
258
+ RhoconnectApi::create_user('some_url',@api_token,'testuser1','testpass1').should == "User created"
259
+ end
260
+
261
+ it "should update user using direct api call" do
262
+ RhoconnectApi::update_user('',@api_token, {:new_password => '123'})
263
+ User.authenticate('rhoadmin','123').login.should == 'rhoadmin'
264
+ end
265
+
266
+ it "should update user using rest call" do
267
+ RestClient.stub(:post)
268
+ RestClient.should_receive(:post).once
269
+ RhoconnectApi::update_user('some_url',@api_token, {:new_password => '123'})
270
+ end
271
+
272
+ it "should delete user direct api call" do
273
+ RhoconnectApi::create_user('',@api_token,'testuser1','testpass1').should == "User created"
274
+ User.is_exist?('testuser1').should == true
275
+ RhoconnectApi::delete_user('',@api_token,'testuser1').should == "User deleted"
276
+ User.is_exist?('testuser1').should == false
277
+ App.load(test_app_name).users.members.should == ["testuser"]
278
+ end
279
+
280
+ it "should delete user using rect call" do
281
+ RestClient.stub(:post).and_return("User deleted")
282
+ RestClient.should_receive(:post).once
283
+ RhoconnectApi::delete_user('some_url',@api_token,'testuser1').should == "User deleted"
284
+ end
285
+
286
+ it "should list clients using direct api call" do
287
+ res = RhoconnectApi::list_clients('',@api_token,@u_fields[:login])
288
+ res.is_a?(Array).should == true
289
+ res.size.should == 1
290
+ res[0].is_a?(String) == true
291
+ res[0].length.should == 32
292
+ end
293
+
294
+ it "should handle empty client's list" do
295
+ @u.clients.delete(@c.id)
296
+ RhoconnectApi::list_clients('',@api_token,@u_fields[:login]).should == []
297
+ end
298
+
299
+ it "should create user using rect call" do
300
+ res = mock('HttpResponse')
301
+ res.stub!(:body).and_return(["21325fd9911044c6ad974785bf23c173"].to_json)
302
+ RestClient.stub(:post).and_return(res)
303
+ RestClient.should_receive(:post).once
304
+ RhoconnectApi::list_clients('some_url',@api_token,'testuser1').should == ["21325fd9911044c6ad974785bf23c173"]
305
+ end
306
+
307
+ it "should create client for a user using direct api call" do
308
+ RhoconnectApi::create_client('',@api_token,@u_fields[:login])
309
+ clients = User.load(@u_fields[:login]).clients.members
310
+ clients.size.should == 2
311
+ end
312
+
313
+ it "should create client using rect call" do
314
+ res = mock('HttpResponse')
315
+ res.stub!(:body).and_return("")
316
+ RestClient.stub(:post).and_return(res)
317
+ RestClient.should_receive(:post).once
318
+ RhoconnectApi::create_client('some_url',@api_token,'testuser1')
319
+ end
320
+
321
+ it "should delete client using direct api call" do
322
+ RhoconnectApi::delete_client('',@api_token,@u_fields[:login],@c.id).should == "Client deleted"
323
+ Client.is_exist?(@c.id).should == false
324
+ User.load(@u_fields[:login]).clients.members.should == []
325
+ end
326
+
327
+ it "should delete client using rect call" do
328
+ RestClient.stub(:post).and_return("Client deleted")
329
+ RestClient.should_receive(:post).once
330
+ RhoconnectApi::delete_client('some_url',@api_token,@u_fields[:login],@c.id).should == "Client deleted"
331
+ end
332
+
333
+ it "should list client attributes using direct api call" do
334
+ res = RhoconnectApi::get_client_params('',@api_token,@c.id)
335
+ res.delete_if { |attrib| attrib['name'] == 'rho__id' || attrib['name'] == 'last_sync'}
336
+ res.sort{|x,y| x['name']<=>y['name']}.should == [
337
+ {"name"=>"device_type", "value"=>"Apple", "type"=>"string"},
338
+ {"name"=>"device_pin", "value"=>"abcd", "type"=>"string"},
339
+ {"name"=>"device_port", "value"=>"3333", "type"=>"string"},
340
+ {"name"=>"user_id", "value"=>"testuser", "type"=>"string"},
341
+ {"name"=>"phone_id", "value"=>nil, "type"=>"string"},
342
+ {"name"=>"app_id", "value"=>"application", "type"=>"string"}].sort{|x,y| x['name']<=>y['name']}
343
+ end
344
+
345
+ it "should list client attributes using rest call" do
346
+ res = mock('HttpResponse')
347
+ res.stub!(:body).and_return(["blah"].to_json)
348
+ RestClient.stub(:post).and_return(res)
349
+ RestClient.should_receive(:post).once
350
+ RhoconnectApi::get_client_params('some_url',@api_token,'client_id')
351
+ end
352
+
353
+ it "should list all application sources using direct api call" do
354
+ RhoconnectApi::list_sources('',@api_token).sort.should ==
355
+ ["SimpleAdapter", "SampleAdapter", "FixedSchemaAdapter"].sort
356
+ end
357
+
358
+ it "should list all application sources using rest call" do
359
+ res = mock('HttpResponse')
360
+ res.stub!(:body).and_return(["SimpleAdapter", "SampleAdapter", "FixedSchemaAdapter"].to_json)
361
+ RestClient.stub(:post).and_return(res)
362
+ RestClient.should_receive(:post).once
363
+ RhoconnectApi::list_sources('some_url',@api_token)
364
+ end
365
+
366
+ it "should list source attributes using direct api call" do
367
+ result = RhoconnectApi::get_source_params(
368
+ '',@api_token,"SampleAdapter").sort{|x,y| x['name']<=>y['name']}
369
+ result.should == [
370
+ {"name"=>"rho__id", "value"=>"SampleAdapter", "type"=>"string"},
371
+ {"name"=>"source_id", "value"=>nil, "type"=>"integer"},
372
+ {"name"=>"name", "value"=>"SampleAdapter", "type"=>"string"},
373
+ {"name"=>"url", "value"=>"http://example.com", "type"=>"string"},
374
+ {"name"=>"login", "value"=>"testuser", "type"=>"string"},
375
+ {"name"=>"password", "value"=>"testpass", "type"=>"string"},
376
+ {"name"=>"priority", "value"=>3, "type"=>"integer"},
377
+ {"name"=>"callback_url", "value"=>nil, "type"=>"string"},
378
+ {"name"=>"poll_interval", "value"=>300, "type"=>"integer"},
379
+ {"name"=>"partition_type", "value"=>"user", "type"=>"string"},
380
+ {"name"=>"sync_type", "value"=>"incremental", "type"=>"string"},
381
+ {"name"=>"belongs_to", "type"=>"string", "value"=>nil},
382
+ {"name"=>"has_many", "type"=>"string", "value"=>"FixedSchemaAdapter,brand"},
383
+ {"name"=>"id", "value"=>"SampleAdapter", "type"=>"string"},
384
+ {"name"=>"queue", "value"=>nil, "type"=>"string"},
385
+ {"name"=>"query_queue", "value"=>nil, "type"=>"string"},
386
+ {"name"=>"cud_queue", "value"=>nil, "type"=>"string"},
387
+ {"name"=>"pass_through", "value"=>nil, "type"=>"string"}].sort {|x,y| x["name"] <=> y["name"] }
388
+ end
389
+
390
+ it "should list source attributes using rest call" do
391
+ res = mock('HttpResponse')
392
+ res.stub!(:body).and_return(["SimpleAdapter"].to_json)
393
+ RestClient.stub(:post).and_return(res)
394
+ RestClient.should_receive(:post).once
395
+ RhoconnectApi::get_source_params('some_url',@api_token,"SimpleAdapter")
396
+ end
397
+
398
+ it "should list of shared source documents using direct api call" do
399
+ RhoconnectApi::list_source_docs('',@api_token,"SimpleAdapter","*").sort.should == {
400
+ "md"=>"source:application:__shared__:SimpleAdapter:md",
401
+ "errors"=>"source:application:__shared__:SimpleAdapter:errors",
402
+ "md_size"=>"source:application:__shared__:SimpleAdapter:md_size",
403
+ "md_copy"=>"source:application:__shared__:SimpleAdapter:md_copy"}.sort
404
+ end
405
+
406
+ it "should list of shared source documents using rest call" do
407
+ res = mock('HttpResponse')
408
+ res.stub!(:body).and_return(["SimpleAdapter"].to_json)
409
+ RestClient.stub(:post).and_return(res)
410
+ RestClient.should_receive(:post).once
411
+ RhoconnectApi::list_source_docs('some_url',@api_token,"SimpleAdapter",'*')
412
+ end
413
+
414
+ it "should list client documents using direct api call" do
415
+ RhoconnectApi::list_client_docs('',@api_token,"SimpleAdapter",@c.id).should == {
416
+ "cd"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd",
417
+ "cd_size"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd_size",
418
+ "create"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create",
419
+ "update"=>"client:application:testuser:#{@c.id}:SimpleAdapter:update",
420
+ "delete"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete",
421
+
422
+ "page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:page",
423
+ "page_token"=>"client:application:testuser:#{@c.id}:SimpleAdapter:page_token",
424
+ "delete_page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete_page",
425
+ "create_links"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_links",
426
+ "create_links_page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_links_page",
427
+
428
+ "delete_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete_errors",
429
+ "login_error"=>"client:application:testuser:#{@c.id}:SimpleAdapter:login_error",
430
+ "create_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_errors",
431
+ "update_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:update_errors",
432
+ "logoff_error"=>"client:application:testuser:#{@c.id}:SimpleAdapter:logoff_error",
433
+
434
+ "search"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search",
435
+ "search_token"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search_token",
436
+ "search_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search_errors"}
437
+ end
438
+
439
+ it "should list client documents using rest call" do
440
+ res = mock('HttpResponse')
441
+ res.stub!(:body).and_return(["SimpleAdapter"].to_json)
442
+ RestClient.stub(:post).and_return(res)
443
+ RestClient.should_receive(:post).once
444
+ RhoconnectApi::list_client_docs('some_url',@api_token,"SimpleAdapter",'*')
445
+ end
446
+
447
+ it "should return db document by name using direct api call" do
448
+ data = {'1' => {'foo' => 'bar'}}
449
+ set_state('abc:abc' => data)
450
+ RhoconnectApi::get_db_doc('',@api_token,'abc:abc').should == data
451
+ end
452
+
453
+ it "should return db document by name and data_type using direct api call" do
454
+ data = 'some string'
455
+ set_state('abc:abc' => data)
456
+ RhoconnectApi::get_db_doc('',@api_token,'abc:abc','string').should == data
457
+ end
458
+
459
+ it "should return db document using rest call" do
460
+ data = 'some string'
461
+ res = mock('HttpResponse')
462
+ res.stub!(:body).and_return(data)
463
+ RestClient.stub(:post).and_return(res)
464
+ RestClient.should_receive(:post).once
465
+ RhoconnectApi::get_db_doc('some_url',@api_token,'abc:abc','string').should == data
466
+ end
467
+
468
+ it "should set db document by doc name and data using direct api call" do
469
+ data = {'1' => {'foo' => 'bar'}}
470
+ RhoconnectApi::set_db_doc('',@api_token,'abc:abc',data)
471
+ verify_result('abc:abc' => data)
472
+ end
473
+
474
+ it "should set db document by doc name, data type, and data using direct api call" do
475
+ data = 'some string'
476
+ RhoconnectApi::set_db_doc('',@api_token,'abc:abc:str',data,'string')
477
+ verify_result('abc:abc:str' => data)
478
+ end
479
+
480
+ it "should set db document using rest call" do
481
+ data = 'some string'
482
+ RestClient.stub(:post)
483
+ RestClient.should_receive(:post).once
484
+ RhoconnectApi::set_db_doc('some_url',@api_token,'abc:abc:str',data,'string')
485
+ end
486
+
487
+ it "should reset and re-create rhoadmin user with bootstrap using direct api call" do
488
+ # Store.put_data('somedoc',{'foo'=>'bar'})
489
+ Store.put_data('somedoc',{'1' => {'foo'=>'bar'}})
490
+ RhoconnectApi::reset('',@api_token).should == "DB reset"
491
+ App.is_exist?(test_app_name).should == true
492
+ Store.get_data('somedoc').should == {}
493
+ User.authenticate('rhoadmin','').should_not be_nil
494
+ end
495
+
496
+ it "should reset db using rest call" do
497
+ RestClient.stub(:post).and_return("DB reset")
498
+ RestClient.should_receive(:post).once
499
+ RhoconnectApi::reset('some_url',@api_token).should == "DB reset"
500
+ end
501
+
502
+ it "should do ping asynchronously using direct api call" do
503
+ params = {"user_id" => @u.id, "api_token" => @api_token,
504
+ "async" => "true","sources" => [@s.name], "message" => 'hello world',
505
+ "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
506
+ PingJob.should_receive(:enqueue).once.with(params)
507
+ RhoconnectApi::ping('',@api_token,@u.id,params)
508
+ end
509
+
510
+ it "should do ping using rest call" do
511
+ RestClient.stub(:post)
512
+ RestClient.should_receive(:post).once
513
+ RhoconnectApi::ping('some_url',@api_token,@u.id,{})
514
+ end
515
+
516
+ it "should get license info using direct api call" do
517
+ RhoconnectApi::get_license_info('',@api_token).should == {
518
+ "available" => 9,
519
+ "issued" => "Fri Apr 23 17:20:13 -0700 2010",
520
+ "seats" => 10,
521
+ "rhoconnect_version" => "Version 1",
522
+ "licensee" => "Rhomobile" }
523
+ end
524
+
525
+ it "should get license info using rest call" do
526
+ res = mock('HttpResponse')
527
+ res.stub!(:body).and_return(['data'].to_json)
528
+ RestClient.stub(:post).and_return(res)
529
+ RestClient.should_receive(:post).once
530
+ RhoconnectApi::get_license_info('some_url',@api_token)
531
+ end
532
+
533
+ it "should get stats using direct api call" do
534
+ Rhoconnect.stats = true
535
+ Store.set_value('stat:foo','bar')
536
+ RhoconnectApi::stats('',@api_token,:metric => 'foo').should == 'bar'
537
+ Rhoconnect.stats = false
538
+ end
539
+
540
+ it "should get stats using rest call" do
541
+ res = mock('HttpResponse')
542
+ res.stub!(:body).and_return('bar')
543
+ RestClient.stub(:post).and_return(res)
544
+ RestClient.should_receive(:post).once.and_return(res)
545
+ RhoconnectApi::stats('some_url',@api_token,:metric => 'foo')
546
+ end
547
+ end
548
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__),'..','api_helper')
2
+
3
+ describe "RhoconnectApiCreateUser" do
4
+ it_should_behave_like "ApiHelper" do
5
+ it "should create client for a user" do
6
+ post "/api/client/create_client", {:api_token => @api_token, :user_id => @u_fields[:login]}
7
+ last_response.should be_ok
8
+ clients = User.load(@u_fields[:login]).clients.members
9
+ clients.size.should == 2
10
+ clients.include?(last_response.body).should == true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__),'..','api_helper')
2
+
3
+ describe "RhoconnectApiDeleteUser" do
4
+ it_should_behave_like "ApiHelper" do
5
+ it "should delete client" do
6
+ post "/api/client/delete_client", {:api_token => @api_token,
7
+ :user_id => @u_fields[:login], :client_id => @c.id}
8
+ last_response.should be_ok
9
+ Client.is_exist?(@c.id).should == false
10
+ User.load(@u_fields[:login]).clients.members.should == []
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require File.join(File.dirname(__FILE__),'..','api_helper')
2
+
3
+ describe "RhoconnectApiGetClientParams" do
4
+ it_should_behave_like "ApiHelper" do
5
+ it "should list client attributes" do
6
+ post "/api/client/get_client_params", {:api_token => @api_token, :client_id =>@c.id}
7
+ res = JSON.parse(last_response.body)
8
+ res.delete_if { |attrib| attrib['name'] == 'rho__id' || attrib['name'] == 'last_sync'}
9
+ res.sort{|x,y| x['name']<=>y['name']}.should == [
10
+ {"name"=>"device_type", "value"=>"Apple", "type"=>"string"},
11
+ {"name"=>"device_pin", "value"=>"abcd", "type"=>"string"},
12
+ {"name"=>"device_port", "value"=>"3333", "type"=>"string"},
13
+ {"name"=>"user_id", "value"=>"testuser", "type"=>"string"},
14
+ {"name"=>"phone_id", "value"=>nil, "type"=>"string"},
15
+ {"name"=>"app_id", "value"=>"application", "type"=>"string"}].sort{|x,y| x['name']<=>y['name']}
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__),'..','api_helper')
2
+
3
+ describe "RhoconnectApiListClientDocs" do
4
+ it_should_behave_like "ApiHelper" do
5
+ it "should list client documents" do
6
+ post "/api/client/list_client_docs", {:api_token => @api_token,
7
+ :source_id => "SimpleAdapter", :client_id => @c.id}
8
+ JSON.parse(last_response.body).should == {
9
+ "cd"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd",
10
+ "cd_size"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd_size",
11
+ "create"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create",
12
+ "update"=>"client:application:testuser:#{@c.id}:SimpleAdapter:update",
13
+ "delete"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete",
14
+
15
+ "page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:page",
16
+ "page_token"=>"client:application:testuser:#{@c.id}:SimpleAdapter:page_token",
17
+ "delete_page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete_page",
18
+ "create_links"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_links",
19
+ "create_links_page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_links_page",
20
+
21
+ "delete_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete_errors",
22
+ "login_error"=>"client:application:testuser:#{@c.id}:SimpleAdapter:login_error",
23
+ "create_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_errors",
24
+ "update_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:update_errors",
25
+ "logoff_error"=>"client:application:testuser:#{@c.id}:SimpleAdapter:logoff_error",
26
+
27
+ "search"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search",
28
+ "search_token"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search_token",
29
+ "search_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search_errors"}
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(__FILE__),'..','api_helper')
2
+
3
+ describe "RhoconnectApiListUsers" do
4
+ it_should_behave_like "ApiHelper" do
5
+ it "should list clients" do
6
+ post "/api/client/list_clients", {:api_token => @api_token,
7
+ :user_id => @u_fields[:login]}
8
+ res = JSON.parse(last_response.body)
9
+ res.is_a?(Array).should == true
10
+ res.size.should == 1
11
+ res[0].is_a?(String) == true
12
+ res[0].length.should == 32
13
+ end
14
+
15
+ it "should handle empty client's list" do
16
+ @u.clients.delete(@c.id)
17
+ post "/api/client/list_clients", {:api_token => @api_token,
18
+ :user_id => @u_fields[:login]}
19
+ JSON.parse(last_response.body).should == []
20
+ end
21
+ end
22
+ end