rhoconnect 3.2.1 → 3.3.1.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. data/CHANGELOG.md +24 -5
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +20 -20
  4. data/bench/benchapp/Gemfile +17 -20
  5. data/bench/benchapp/config.ru +2 -2
  6. data/bench/benchapp/settings/settings.yml +3 -3
  7. data/bench/blobapp/Gemfile +16 -13
  8. data/bench/blobapp/config.ru +2 -2
  9. data/bench/blobapp/settings/settings.yml +5 -3
  10. data/bench/lib/bench.rb +35 -32
  11. data/bench/lib/bench/session.rb +9 -1
  12. data/bench/scripts/blob_cud_script.rb +13 -17
  13. data/bench/scripts/cud_script.rb +11 -12
  14. data/bench/scripts/helpers.rb +5 -7
  15. data/bench/scripts/query_md_script.rb +18 -12
  16. data/bench/scripts/query_only_script.rb +19 -11
  17. data/bench/scripts/query_script.rb +17 -13
  18. data/bench/scripts/test_query_script.rb +46 -17
  19. data/bench/scripts/test_source_script.rb +7 -7
  20. data/commands/commands/dtach_commands/dtach_install.rb +44 -16
  21. data/commands/commands/rhoconnect/spec.rb +13 -9
  22. data/commands/commands/rhoconnect/version.rb +6 -0
  23. data/commands/execute.rb +10 -6
  24. data/doc/deploying.txt +75 -13
  25. data/doc/install.txt +3 -3
  26. data/doc/push-client-setup.txt +1 -1
  27. data/doc/rest-api.txt +4 -23
  28. data/doc/rhoconnect-redis-stack.txt +26 -7
  29. data/doc/settings.txt +9 -3
  30. data/examples/simple/Gemfile +3 -1
  31. data/examples/simple/application.rb +5 -0
  32. data/examples/simple/config.ru +3 -2
  33. data/examples/simple/my_server.rb +14 -0
  34. data/examples/simple/settings/settings.yml +1 -0
  35. data/generators/templates/application/Gemfile +4 -4
  36. data/generators/templates/application/application.rb +4 -0
  37. data/generators/templates/application/settings/settings.yml +4 -1
  38. data/installer/unix-like/create_texts.rb +39 -1
  39. data/installer/unix-like/rho_connect_install_constants.rb +1 -1
  40. data/installer/utils/package_upload/repos.rake +7 -5
  41. data/lib/rhoconnect.rb +3 -2
  42. data/lib/rhoconnect/api/app/ans_login.rb +3 -0
  43. data/lib/rhoconnect/api/app/bulk_data.rb +6 -0
  44. data/lib/rhoconnect/api/{source → app}/fast_delete.rb +1 -1
  45. data/lib/rhoconnect/api/{source → app}/fast_insert.rb +2 -2
  46. data/lib/rhoconnect/api/{source → app}/fast_update.rb +2 -2
  47. data/lib/rhoconnect/api/app/login.rb +5 -0
  48. data/lib/rhoconnect/api/{source → app}/push_deletes.rb +1 -1
  49. data/lib/rhoconnect/api/{source → app}/push_objects.rb +1 -1
  50. data/lib/rhoconnect/api/app/query.rb +4 -0
  51. data/lib/rhoconnect/api/app/queue_updates.rb +94 -0
  52. data/lib/rhoconnect/api/app/search.rb +4 -0
  53. data/lib/rhoconnect/api/client/client_get_db_doc.rb +5 -0
  54. data/lib/rhoconnect/api/client/client_set_db_doc.rb +8 -0
  55. data/lib/rhoconnect/api/client/create.rb +7 -0
  56. data/lib/rhoconnect/api/client/get_client_params.rb +2 -1
  57. data/lib/rhoconnect/api/client/list_client_docs.rb +2 -1
  58. data/lib/rhoconnect/api/client/register.rb +12 -0
  59. data/lib/rhoconnect/api/client/reset.rb +5 -0
  60. data/lib/rhoconnect/api/{source → readstate}/set_refresh_time.rb +2 -1
  61. data/lib/rhoconnect/api/source/get_source_params.rb +3 -2
  62. data/lib/rhoconnect/api/source/list_sources.rb +2 -1
  63. data/lib/rhoconnect/api/source/update_source_params.rb +3 -3
  64. data/lib/rhoconnect/api/store/get_db_doc.rb +4 -0
  65. data/lib/rhoconnect/api/store/set_db_doc.rb +7 -0
  66. data/lib/rhoconnect/api/system/get_adapter.rb +4 -0
  67. data/lib/rhoconnect/api/{admin → system}/get_license_info.rb +2 -1
  68. data/lib/rhoconnect/api/system/login.rb +15 -0
  69. data/lib/rhoconnect/api/{admin → system}/reset.rb +3 -2
  70. data/lib/rhoconnect/api/system/save_adapter.rb +4 -0
  71. data/lib/rhoconnect/api/{admin → system}/stats.rb +2 -1
  72. data/lib/rhoconnect/api/user/create_user.rb +2 -2
  73. data/lib/rhoconnect/api/user/delete_client.rb +6 -0
  74. data/lib/rhoconnect/api/user/delete_user.rb +2 -1
  75. data/lib/rhoconnect/api/user/list_clients.rb +4 -0
  76. data/lib/rhoconnect/api/user/list_source_docs.rb +11 -0
  77. data/lib/rhoconnect/api/user/list_users.rb +1 -1
  78. data/lib/rhoconnect/api/user/ping.rb +7 -0
  79. data/lib/rhoconnect/api/user/show_user.rb +3 -0
  80. data/lib/rhoconnect/api/user/update_user.rb +3 -2
  81. data/lib/rhoconnect/api/user/user_get_db_doc.rb +5 -0
  82. data/lib/rhoconnect/api/user/user_set_db_doc.rb +10 -0
  83. data/lib/rhoconnect/app.rb +12 -2
  84. data/lib/rhoconnect/async.rb +6 -10
  85. data/lib/rhoconnect/bulk_data/bulk_data.rb +4 -4
  86. data/lib/rhoconnect/client.rb +10 -9
  87. data/lib/rhoconnect/client_sync.rb +24 -19
  88. data/lib/rhoconnect/document.rb +18 -4
  89. data/lib/rhoconnect/graph_helper.rb +4 -2
  90. data/lib/rhoconnect/jobs/bulk_data_job.rb +1 -1
  91. data/lib/rhoconnect/jobs/ping_job.rb +39 -29
  92. data/lib/rhoconnect/middleware/admin_user.rb +23 -0
  93. data/lib/rhoconnect/middleware/body_content_type_parser.rb +35 -0
  94. data/lib/rhoconnect/{cors.rb → middleware/cors.rb} +1 -0
  95. data/lib/rhoconnect/middleware/current_app.rb +16 -0
  96. data/lib/rhoconnect/middleware/current_request.rb +16 -0
  97. data/lib/rhoconnect/middleware/current_user.rb +17 -0
  98. data/lib/rhoconnect/middleware/helpers.rb +105 -0
  99. data/lib/rhoconnect/middleware/login_required.rb +22 -0
  100. data/lib/rhoconnect/{stats/middleware.rb → middleware/stats.rb} +5 -3
  101. data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +58 -0
  102. data/lib/rhoconnect/ping.rb +1 -0
  103. data/lib/rhoconnect/ping/apple.rb +18 -16
  104. data/lib/rhoconnect/ping/blackberry.rb +9 -9
  105. data/lib/rhoconnect/ping/rhoconnect_push.rb +45 -0
  106. data/lib/rhoconnect/server.rb +98 -91
  107. data/lib/rhoconnect/source.rb +5 -1
  108. data/lib/rhoconnect/source_sync.rb +4 -3
  109. data/lib/rhoconnect/stats/record.rb +15 -15
  110. data/lib/rhoconnect/store.rb +253 -75
  111. data/lib/rhoconnect/tasks.rb +3 -3
  112. data/lib/rhoconnect/version.rb +1 -1
  113. data/lib/rhoconnect/web-console/controllers/admins.js +1 -14
  114. data/lib/rhoconnect/web-console/models/adapter.js +18 -8
  115. data/lib/rhoconnect/web-console/models/client.js +15 -9
  116. data/lib/rhoconnect/web-console/models/doc.js +7 -11
  117. data/lib/rhoconnect/web-console/models/session.js +5 -2
  118. data/lib/rhoconnect/web-console/models/source.js +55 -36
  119. data/lib/rhoconnect/web-console/models/user.js +20 -11
  120. data/lib/rhoconnect/web-console/public/backbone.js +8 -2
  121. data/lib/rhoconnect/web-console/templates/index.erb +11 -5
  122. data/lib/rhoconnect/web-console/views/doc.js +6 -8
  123. data/lib/rhoconnect/web-console/views/edit_user.js +6 -3
  124. data/lib/rhoconnect/web-console/views/home.js +98 -25
  125. data/lib/rhoconnect/web-console/views/index.js +1 -1
  126. data/lib/rhoconnect/web-console/views/new_ping.js +6 -3
  127. data/lib/rhoconnect/web-console/views/server_doc.js +12 -4
  128. data/lib/rhoconnect/web-console/views/show_device.js +6 -3
  129. data/rhoconnect.gemspec +1 -2
  130. data/spec/api/{source → app}/fast_delete_spec.rb +4 -4
  131. data/spec/api/{source → app}/fast_insert_spec.rb +4 -4
  132. data/spec/api/{source → app}/fast_update_spec.rb +22 -6
  133. data/spec/api/{source → app}/push_deletes_spec.rb +2 -2
  134. data/spec/api/app/push_objects_spec.rb +45 -0
  135. data/spec/api/client/client_get_db_doc_spec.rb +31 -0
  136. data/spec/api/client/client_set_db_doc_spec.rb +14 -0
  137. data/spec/api/client/get_client_params_spec.rb +3 -2
  138. data/spec/api/client/list_client_docs_spec.rb +2 -2
  139. data/spec/api/{source → readstate}/set_refresh_time_spec.rb +15 -9
  140. data/spec/api/source/get_source_params_spec.rb +3 -2
  141. data/spec/api/source/list_sources_spec.rb +3 -9
  142. data/spec/api/source/update_source_params_spec.rb +4 -4
  143. data/spec/api/store/get_db_doc_spec.rb +32 -0
  144. data/spec/api/store/set_db_doc_spec.rb +43 -0
  145. data/spec/api/system/adapter_spec.rb +33 -0
  146. data/spec/api/{admin → system}/get_license_info_spec.rb +2 -5
  147. data/spec/api/{admin/get_api_token_spec.rb → system/login_spec.rb} +4 -11
  148. data/spec/api/{admin → system}/reset_spec.rb +2 -2
  149. data/spec/api/{admin → system}/stats_spec.rb +19 -13
  150. data/spec/api/user/create_user_spec.rb +15 -8
  151. data/spec/api/{client → user}/delete_client_spec.rb +3 -4
  152. data/spec/api/user/delete_user_spec.rb +33 -4
  153. data/spec/api/user/list_clients_spec.rb +30 -0
  154. data/spec/api/user/list_source_docs_spec.rb +35 -0
  155. data/spec/api/user/list_users_spec.rb +5 -6
  156. data/spec/api/{client → user}/ping_spec.rb +4 -6
  157. data/spec/api/user/show_user_spec.rb +14 -0
  158. data/spec/api/user/update_user_spec.rb +28 -10
  159. data/spec/api/user/user_get_db_doc_spec.rb +16 -0
  160. data/spec/api/user/user_set_db_doc_spec.rb +41 -0
  161. data/spec/apps/rhotestapp/application.rb +4 -0
  162. data/spec/apps/rhotestapp/settings/settings.yml +3 -1
  163. data/spec/bulk_data/bulk_data_spec.rb +13 -0
  164. data/spec/client_sync_spec.rb +41 -59
  165. data/spec/document_spec.rb +23 -0
  166. data/spec/javascripts/doc_view_spec.js +1 -1
  167. data/spec/javascripts/home_view_spec.js +10 -5
  168. data/spec/javascripts/index_view_spec.js +1 -1
  169. data/spec/jobs/ping_job_spec.rb +26 -0
  170. data/spec/perf/store_perf_spec.rb +1 -1
  171. data/spec/ping/android_spec.rb +0 -7
  172. data/spec/ping/apple_spec.rb +7 -0
  173. data/spec/ping/blackberry_spec.rb +10 -0
  174. data/spec/ping/rhoconnect_push_spec.rb +58 -0
  175. data/spec/server/cors_spec.rb +1 -1
  176. data/spec/server/server_spec.rb +152 -104
  177. data/spec/{stats/middleware_spec.rb → server/stats_spec.rb} +4 -5
  178. data/spec/server/x_domain_session_wrapper_spec.rb +3 -3
  179. data/spec/source_spec.rb +2 -2
  180. data/spec/source_sync_spec.rb +2 -0
  181. data/spec/spec_helper.rb +17 -3
  182. data/spec/stats/record_spec.rb +18 -19
  183. data/spec/store_spec.rb +51 -26
  184. data/spec/support/shared_examples.rb +4 -0
  185. data/spec/sync_states_spec.rb +2 -2
  186. metadata +104 -88
  187. data/bench/benchapp/Gemfile.lock +0 -87
  188. data/bench/blobapp/Gemfile.lock +0 -107
  189. data/bench/lib/testdata/5-data.txt +0 -8
  190. data/doc/release.txt +0 -41
  191. data/lib/rhoconnect/api/admin/get_api_token.rb +0 -14
  192. data/lib/rhoconnect/api/admin/login.rb +0 -6
  193. data/lib/rhoconnect/api/application/bulk_data.rb +0 -7
  194. data/lib/rhoconnect/api/application/clientcreate.rb +0 -8
  195. data/lib/rhoconnect/api/application/clientlogin.rb +0 -6
  196. data/lib/rhoconnect/api/application/clientregister.rb +0 -13
  197. data/lib/rhoconnect/api/application/clientreset.rb +0 -6
  198. data/lib/rhoconnect/api/application/query.rb +0 -7
  199. data/lib/rhoconnect/api/application/queue_updates.rb +0 -20
  200. data/lib/rhoconnect/api/application/search.rb +0 -6
  201. data/lib/rhoconnect/api/client/create_client.rb +0 -3
  202. data/lib/rhoconnect/api/client/delete_client.rb +0 -5
  203. data/lib/rhoconnect/api/client/list_clients.rb +0 -3
  204. data/lib/rhoconnect/api/client/ping.rb +0 -7
  205. data/lib/rhoconnect/api/source/get_adapter.rb +0 -3
  206. data/lib/rhoconnect/api/source/get_db_doc.rb +0 -7
  207. data/lib/rhoconnect/api/source/list_source_docs.rb +0 -10
  208. data/lib/rhoconnect/api/source/save_adapter.rb +0 -3
  209. data/lib/rhoconnect/api/source/set_db_doc.rb +0 -10
  210. data/lib/rhoconnect/api/source/upload_file.rb +0 -4
  211. data/lib/rhoconnect/body_content_type_parser.rb +0 -32
  212. data/lib/rhoconnect/x_domain_session_wrapper.rb +0 -53
  213. data/spec/api/admin/api_token_spec.rb +0 -13
  214. data/spec/api/client/create_client_spec.rb +0 -13
  215. data/spec/api/client/list_clients_spec.rb +0 -22
  216. data/spec/api/source/adapter_spec.rb +0 -29
  217. data/spec/api/source/get_db_doc_spec.rb +0 -21
  218. data/spec/api/source/list_source_docs_spec.rb +0 -25
  219. data/spec/api/source/push_objects_spec.rb +0 -27
  220. data/spec/api/source/set_db_doc_spec.rb +0 -32
  221. data/spec/api/source/upload_file_spec.rb +0 -26
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__),'..','api_helper')
2
+
3
+ describe "RhoconnectApiClientSetDbDoc" do
4
+ it_should_behave_like "ApiHelper" do
5
+ it "should set client's db document by doc key and data" do
6
+ data = {'1' => {'foo' => 'bar'}}
7
+ dockey = 'myclientdoc'
8
+ cdocname = @c.docname(dockey)
9
+ post "/rc/#{Rhoconnect::API_VERSION}/clients/#{@c.id}/sources/#{@c.source_name}/docs/#{dockey}", {:data => data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
10
+ last_response.should be_ok
11
+ verify_result(cdocname => data)
12
+ end
13
+ end
14
+ end
@@ -3,13 +3,14 @@ require File.join(File.dirname(__FILE__),'..','api_helper')
3
3
  describe "RhoconnectApiGetClientParams" do
4
4
  it_should_behave_like "ApiHelper" do
5
5
  it "should list client attributes" do
6
- post "/api/client/get_client_params", {:api_token => @api_token, :client_id =>@c.id}
6
+ get "/rc/#{Rhoconnect::API_VERSION}/clients/#{@c.id}", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
7
7
  res = JSON.parse(last_response.body)
8
8
  res.delete_if { |attrib| attrib['name'] == 'rho__id' || attrib['name'] == 'last_sync'}
9
9
  res.sort{|x,y| x['name']<=>y['name']}.should == [
10
10
  {"name"=>"device_type", "value"=>"Apple", "type"=>"string"},
11
11
  {"name"=>"device_pin", "value"=>"abcd", "type"=>"string"},
12
- {"name"=>"device_port", "value"=>"3333", "type"=>"string"},
12
+ {"name"=>"device_port", "value"=>"3333", "type"=>"string"},
13
+ {"name"=>"device_push_type", "type"=>"string", "value"=>nil},
13
14
  {"name"=>"user_id", "value"=>"testuser", "type"=>"string"},
14
15
  {"name"=>"phone_id", "value"=>nil, "type"=>"string"},
15
16
  {"name"=>"app_id", "value"=>"application", "type"=>"string"}].sort{|x,y| x['name']<=>y['name']}
@@ -3,8 +3,8 @@ require File.join(File.dirname(__FILE__),'..','api_helper')
3
3
  describe "RhoconnectApiListClientDocs" do
4
4
  it_should_behave_like "ApiHelper" do
5
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}
6
+ source_id = "SimpleAdapter"
7
+ get "/rc/#{Rhoconnect::API_VERSION}/clients/#{@c.id}/sources/#{source_id}/docnames", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
8
8
  JSON.parse(last_response.body).should == {
9
9
  "cd"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd",
10
10
  "cd_size"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd_size",
@@ -4,8 +4,8 @@ describe "RhoconnectApiSetRefreshTime" do
4
4
  it_should_behave_like "ApiHelper" do
5
5
  it "should set refresh time to 100s from 'now'" do
6
6
  before = Time.now.to_i
7
- post "/api/source/set_refresh_time", :api_token => @api_token,
8
- :source_name => @s_fields[:name], :user_name => @u_fields[:login], :refresh_time => 100
7
+ put "/rc/#{Rhoconnect::API_VERSION}/readstate/users/#{@u_fields[:login]}/sources/#{@s_fields[:name]}",
8
+ {:refresh_time => 100}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
9
9
  after = Time.now.to_i
10
10
  last_response.should be_ok
11
11
  @s = Source.load(@s.id,@s_params)
@@ -15,8 +15,7 @@ describe "RhoconnectApiSetRefreshTime" do
15
15
 
16
16
  it "should set refresh time to 'now' if no refresh_time provided" do
17
17
  before = Time.now.to_i
18
- post "/api/source/set_refresh_time", :api_token => @api_token,
19
- :source_name => @s_fields[:name], :user_name => @u_fields[:login]
18
+ put "/rc/#{Rhoconnect::API_VERSION}/readstate/users/#{@u_fields[:login]}/sources/#{@s_fields[:name]}", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
20
19
  after = Time.now.to_i
21
20
  last_response.should be_ok
22
21
  @s = Source.load(@s.id,@s_params)
@@ -25,17 +24,24 @@ describe "RhoconnectApiSetRefreshTime" do
25
24
  end
26
25
 
27
26
  it "should set poll interval" do
28
- post "/api/source/set_refresh_time", :api_token => @api_token,
29
- :source_name => @s_fields[:name], :user_name => @u_fields[:login], :poll_interval => 100
27
+ put "/rc/#{Rhoconnect::API_VERSION}/readstate/users/#{@u_fields[:login]}/sources/#{@s_fields[:name]}", {:poll_interval => 100}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
30
28
  last_response.should be_ok
31
29
  @s = Source.load(@s.id,@s_params)
32
30
  @s.poll_interval.should == 100
33
31
  end
34
-
35
- it "should should not set nil poll interval" do
36
- post "/api/source/set_refresh_time", :api_token => @api_token,
32
+
33
+ it "should should not set nil poll interval with old route and deprecation warning" do
34
+ post "/api/set_refresh_time", :api_token => @api_token,
37
35
  :source_name => @s_fields[:name], :user_name => @u_fields[:login], :poll_interval => nil
38
36
  last_response.should be_ok
37
+ last_response.headers["Warning"].index('deprecated').should_not == nil
38
+ @s = Source.load(@s.id,@s_params)
39
+ @s.poll_interval.should == 300
40
+ end
41
+
42
+ it "should should not set nil poll interval" do
43
+ put "/rc/#{Rhoconnect::API_VERSION}/readstate/users/#{@u_fields[:login]}/sources/#{@s_fields[:name]}", {:poll_interval => nil}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
44
+ last_response.should be_ok
39
45
  @s = Source.load(@s.id,@s_params)
40
46
  @s.poll_interval.should == 300
41
47
  end
@@ -5,7 +5,8 @@ describe "RhoconnectApiGetSourceParams" do
5
5
  it_should_behave_like "ApiHelper" do
6
6
 
7
7
  it "should list source attributes" do
8
- post "/api/source/get_source_params", {:api_token => @api_token, :source_id =>"SampleAdapter"}
8
+ source_id = "SampleAdapter"
9
+ get "/rc/#{Rhoconnect::API_VERSION}/sources/#{source_id}", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
9
10
  result = JSON.parse(last_response.body).sort {|x,y| y["name"] <=> x["name"] }
10
11
  result.should == [
11
12
  {"name"=>"rho__id", "value"=>"SampleAdapter", "type"=>"string"},
@@ -14,7 +15,7 @@ describe "RhoconnectApiGetSourceParams" do
14
15
  {"name"=>"url", "value"=>"http://example.com", "type"=>"string"},
15
16
  {"name"=>"login", "value"=>"testuser", "type"=>"string"},
16
17
  {"name"=>"password", "value"=>"testpass", "type"=>"string"},
17
- {"name"=>"priority", "value"=>3, "type"=>"integer"},
18
+ {"name"=>"priority", "value"=>1, "type"=>"integer"},
18
19
  {"name"=>"callback_url", "value"=>nil, "type"=>"string"},
19
20
  {"name"=>"poll_interval", "value"=>300, "type"=>"integer"},
20
21
  {"name"=>"retry_limit", "type"=>"integer", "value"=>0},
@@ -2,24 +2,18 @@ require File.join(File.dirname(__FILE__),'..','api_helper')
2
2
 
3
3
  describe "RhoconnectApiListSources" do
4
4
  it_should_behave_like "ApiHelper" do
5
- it "should list all application sources" do
6
- post "/api/source/list_sources", {:api_token => @api_token}
7
- JSON.parse(last_response.body).sort.should == ["SimpleAdapter", "SampleAdapter", "FixedSchemaAdapter", "OtherAdapter"].sort
8
- end
9
-
10
5
  it "should list all application sources using partition_type param" do
11
- post "/api/source/list_sources",
12
- {:api_token => @api_token, :partition_type => 'all'}
6
+ get "/rc/#{Rhoconnect::API_VERSION}/sources/type/all", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
13
7
  JSON.parse(last_response.body).sort.should == ["SimpleAdapter", "SampleAdapter", "FixedSchemaAdapter", "OtherAdapter"].sort
14
8
  end
15
9
 
16
10
  it "should list app partition sources" do
17
- post "/api/source/list_sources", {:api_token => @api_token, :partition_type => :app}
11
+ get "/rc/#{Rhoconnect::API_VERSION}/sources/type/app", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
18
12
  JSON.parse(last_response.body).sort.should == ["SimpleAdapter", "OtherAdapter"].sort
19
13
  end
20
14
 
21
15
  it "should list user partition sources" do
22
- post "/api/source/list_sources", {:api_token => @api_token, :partition_type => :user}
16
+ get "/rc/#{Rhoconnect::API_VERSION}/sources/type/user", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
23
17
  JSON.parse(last_response.body).sort.should == ["SampleAdapter", "FixedSchemaAdapter"].sort
24
18
  end
25
19
  end
@@ -5,8 +5,8 @@ describe "RhoconnectApiUpdateSourceParams" do
5
5
  it "should set poll_interval to 99 seconds" do
6
6
  @s1 = Source.load(@s.id,@s_params)
7
7
  before = @s1.poll_interval.to_i
8
- post "/api/source/update_source_params", :api_token => @api_token,
9
- :source_name => @s_fields[:name], :user_name => @u_fields[:login], :data => {:poll_interval => 99}
8
+ put "/rc/#{Rhoconnect::API_VERSION}/sources/#{@s_fields[:name]}",
9
+ {:data => {:poll_interval => 99}}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
10
10
  last_response.should be_ok
11
11
  @s2 = Source.load(@s.id,@s_params)
12
12
  after = @s2.poll_interval
@@ -15,8 +15,8 @@ describe "RhoconnectApiUpdateSourceParams" do
15
15
  end
16
16
 
17
17
  it "should fail to update the source if param is not found" do
18
- post "/api/source/update_source_params", :api_token => @api_token,
19
- :source_name => @s_fields[:name], :user_name => @u_fields[:login], :data => {:invalid_param => "invalid_data"}
18
+ put "/rc/#{Rhoconnect::API_VERSION}/sources/#{@s_fields[:name]}",
19
+ {:data => {:invalid_param => "invalid_data"}}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
20
20
  last_response.status.should == 500
21
21
  last_response.body.match('undefined method').should_not be_nil
22
22
  end
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__),'..','api_helper')
2
+
3
+ describe "RhoconnectApiGetDbDoc" do
4
+ it_should_behave_like "ApiHelper" do
5
+ it "should return db document by name" do
6
+ data = {'1' => {'foo' => 'bar'}}
7
+ set_state('abc:abc' => data)
8
+ dockey = 'abc:abc'
9
+ get "/rc/#{Rhoconnect::API_VERSION}/store/#{dockey}", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
10
+ last_response.should be_ok
11
+ JSON.parse(last_response.body).should == data
12
+ end
13
+
14
+ it "should return db document by name and print deprecation warning with old route" do
15
+ data = {'1' => {'foo' => 'bar'}}
16
+ set_state('abc:abc' => data)
17
+ post "/api/get_db_doc", {:doc => 'abc:abc'}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
18
+ last_response.should be_ok
19
+ last_response.headers["Warning"].index('deprecated').should_not == nil
20
+ JSON.parse(last_response.body).should == data
21
+ end
22
+
23
+ it "should return db document by name and data_type" do
24
+ data = 'some string'
25
+ set_state('abc:abc' => data)
26
+ dockey = 'abc:abc'
27
+ get "/rc/#{Rhoconnect::API_VERSION}/store/#{dockey}", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
28
+ last_response.should be_ok
29
+ last_response.body.should == data
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require File.join(File.dirname(__FILE__),'..','api_helper')
2
+
3
+ describe "RhoconnectApiSetDbDoc" do
4
+ it_should_behave_like "ApiHelper" do
5
+ it "should set db document by doc name and data" do
6
+ data = {'1' => {'foo' => 'bar'}}
7
+ docname = 'application:abc'
8
+ post "/rc/#{Rhoconnect::API_VERSION}/store/#{docname}", {:data => data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
9
+ last_response.should be_ok
10
+ verify_result(docname => data)
11
+ end
12
+
13
+ it "should set db document by doc name, data type, and data" do
14
+ data = 'some string'
15
+ docname = 'abc:abc:str'
16
+ post "/rc/#{Rhoconnect::API_VERSION}/store/#{docname}", {:data => data, :data_type => :string}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
17
+ last_response.should be_ok
18
+ verify_result('abc:abc:str' => data)
19
+ end
20
+
21
+ it "should set db document by doc name, data type, and data with old route and deprecation warning" do
22
+ data = 'some string'
23
+ post "/api/set_db_doc", {:doc => 'abc:abc:str', :data => data, :data_type => :string}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
24
+ last_response.headers['Warning'].index('deprecated').should_not == nil
25
+ last_response.should be_ok
26
+ verify_result('abc:abc:str' => data)
27
+ end
28
+
29
+ it "should append data in set db document by doc name and data" do
30
+ data = {'1' => {'foo' => 'bar'}}
31
+ data2 = {'2' => {'foo1' => 'bar1'}}
32
+ data3 = data.merge(data2)
33
+ docname = 'abc:abc'
34
+ post "/rc/#{Rhoconnect::API_VERSION}/store/#{docname}", {:data => data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
35
+ last_response.should be_ok
36
+ verify_result('abc:abc' => data)
37
+
38
+ post "/rc/#{Rhoconnect::API_VERSION}/store/#{docname}", {:data => data2, :append => true}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
39
+ last_response.should be_ok
40
+ verify_result('abc:abc' => data3)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__),'..','api_helper')
2
+
3
+ describe "RhoconnectApiAppServer" do
4
+ it_should_behave_like "ApiHelper" do
5
+
6
+ it "should save adapter url" do
7
+ params = {:attributes => {:adapter_url => 'http://test.com'}}
8
+ post "/rc/#{Rhoconnect::API_VERSION}/system/appserver", params, {Rhoconnect::API_TOKEN_HEADER => @api_token}
9
+ last_response.should be_ok
10
+ end
11
+
12
+ it "should get adapter url" do
13
+ params = {}
14
+ get "/rc/#{Rhoconnect::API_VERSION}/system/appserver", params, {Rhoconnect::API_TOKEN_HEADER => @api_token}
15
+ last_response.should be_ok
16
+ end
17
+
18
+ it "should get check deprecation warning in /api/get_adapter" do
19
+ params = {}
20
+ post "/api/get_adapter", params, {Rhoconnect::API_TOKEN_HEADER => @api_token}
21
+ last_response.should be_ok
22
+ last_response.headers["Warning"].index('deprecated').should_not == nil
23
+ end
24
+
25
+ it "should get check deprecation warning in /api/source/get_adapter" do
26
+ params = {}
27
+ post "/api/source/get_adapter", params, {Rhoconnect::API_TOKEN_HEADER => @api_token}
28
+ last_response.should be_ok
29
+ last_response.headers["Warning"].index('deprecated').should_not == nil
30
+ end
31
+ end
32
+
33
+ end
@@ -3,8 +3,7 @@ require File.join(File.dirname(__FILE__),'..','api_helper')
3
3
  describe "RhoconnectApiGetLicenseInfo" do
4
4
  it_should_behave_like "ApiHelper" do
5
5
  it "should get license info" do
6
- true.should == true
7
- post "/api/admin/get_license_info", {:api_token => @api_token}
6
+ get "/rc/#{Rhoconnect::API_VERSION}/system/license", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
8
7
  JSON.parse(last_response.body).should == {
9
8
  "available" => 9,
10
9
  "issued" => "Fri Apr 23 17:20:13 -0700 2010",
@@ -14,8 +13,6 @@ describe "RhoconnectApiGetLicenseInfo" do
14
13
  end
15
14
 
16
15
  it "should get custom_license info with deprecation warning" do
17
- true.should == true
18
-
19
16
  # this one for test purposes to make sure
20
17
  # that an old way custom REST API still works
21
18
  Rhoconnect::Server.api :custom_license_info do |params,user|
@@ -26,7 +23,7 @@ describe "RhoconnectApiGetLicenseInfo" do
26
23
  :available => Rhoconnect.license.available }.to_json
27
24
  end
28
25
 
29
- post "/api/custom_license_info", {:api_token => @api_token}
26
+ post "/api/custom_license_info", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
30
27
  JSON.parse(last_response.body).should == {
31
28
  "available" => 9,
32
29
  "issued" => "Fri Apr 23 17:20:13 -0700 2010",
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__),'..','api_helper')
3
3
  describe "RhoconnectApiGetApiToken" do
4
4
  it_should_behave_like "ApiHelper" do
5
5
  it "should login and receive the token string" do
6
- post "/api/admin/login", :login => 'rhoadmin',:password => ''
6
+ post "/rc/#{Rhoconnect::API_VERSION}/system/login", :login => 'rhoadmin',:password => ''
7
7
  last_response.body.should == @api_token
8
8
  end
9
9
 
@@ -13,28 +13,21 @@ describe "RhoconnectApiGetApiToken" do
13
13
  last_response.headers["Warning"].index('deprecated').should_not == nil
14
14
  end
15
15
 
16
- it "should get deprecation warning for get_api_token method" do
17
- post "/api/admin/login", :login => 'rhoadmin',:password => ''
18
- post "/api/admin/get_api_token"
19
- last_response.body.should == @api_token
20
- last_response.headers['Warning'].index('deprecated').should_not == nil
21
- end
22
-
23
16
  it "should fail to login and get token if user is not rhoadmin" do
24
17
  Rhoconnect.appserver = nil
25
- post "/api/admin/login", :login => @u_fields[:login],:password => 'testpass'
18
+ post "/rc/#{Rhoconnect::API_VERSION}/system/login", :login => @u_fields[:login],:password => 'testpass'
26
19
  last_response.status.should == 422
27
20
  last_response.body.should == 'Invalid/missing API user'
28
21
  end
29
22
 
30
23
  it "should return 422 if no token provided" do
31
24
  params = {:attributes => {:login => 'testuser1', :password => 'testpass1'}}
32
- post "/api/user/create_user", params
25
+ post "/rc/#{Rhoconnect::API_VERSION}/users", params
33
26
  last_response.status.should == 422
34
27
  end
35
28
 
36
29
  it "response should have cache-control and pragma headers set to no-cache" do
37
- post "/login", :login => 'rhoadmin',:password => ''
30
+ post "/rc/#{Rhoconnect::API_VERSION}/system/login", :login => 'rhoadmin',:password => ''
38
31
  last_response.headers['Cache-Control'].should == 'no-cache'
39
32
  last_response.headers['Pragma'].should == 'no-cache'
40
33
  end
@@ -4,7 +4,7 @@ describe "RhoconnectApiReset" do
4
4
  it_should_behave_like "ApiHelper" do
5
5
  it "should reset and re-create rhoadmin user with bootstrap" do
6
6
  Store.put_data('somedoc',{ '1' => {'foo'=>'bar'}})
7
- post "/api/admin/reset", :api_token => @api_token
7
+ post "/rc/#{Rhoconnect::API_VERSION}/system/reset", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
8
8
  App.is_exist?(test_app_name).should == true
9
9
  Store.get_data('somedoc').should == {}
10
10
  User.authenticate('rhoadmin','').should_not be_nil
@@ -12,7 +12,7 @@ describe "RhoconnectApiReset" do
12
12
 
13
13
  it "should reset and re-create rhoadmin user with initializer" do
14
14
  Store.put_data('somedoc',{ '1' => {'foo'=>'bar'}})
15
- post "/api/admin/reset", :api_token => @api_token
15
+ post "/rc/#{Rhoconnect::API_VERSION}/system/reset", {}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
16
16
  App.is_exist?(test_app_name).should == true
17
17
  Store.get_data('somedoc').should == {}
18
18
  User.authenticate('rhoadmin','').should_not be_nil
@@ -20,7 +20,7 @@ describe "RhoconnectApiStats" do
20
20
  it "should retrieve metric names" do
21
21
  Store.set_value('stat:foo', '1')
22
22
  Store.set_value('stat:bar', '2')
23
- post "/api/admin/stats", {
23
+ get "/rc/#{Rhoconnect::API_VERSION}/system/stats", {
24
24
  :api_token => @api_token,
25
25
  :names => '*'
26
26
  }
@@ -31,31 +31,38 @@ describe "RhoconnectApiStats" do
31
31
  it "should retrieve range metric" do
32
32
  Store.db.zadd('stat:foo', 2, "1:2")
33
33
  Store.db.zadd('stat:foo', 3, "1:3")
34
- post "/api/admin/stats", {
35
- :api_token => @api_token,
34
+ get "/rc/#{Rhoconnect::API_VERSION}/system/stats", {
36
35
  :metric => 'foo',
37
36
  :start => 0,
38
37
  :finish => -1
39
- }
38
+ }, {Rhoconnect::API_TOKEN_HEADER => @api_token}
40
39
  last_response.should be_ok
41
40
  JSON.parse(last_response.body).should == ["1:2", "1:3"]
42
41
  end
43
42
 
44
43
  it "should retrieve string metric" do
45
44
  Store.db.set('stat:foo', 'bar')
46
- post "/api/admin/stats", {
47
- :api_token => @api_token,
45
+ get "/rc/#{Rhoconnect::API_VERSION}/system/stats", {
48
46
  :metric => 'foo'
49
- }
47
+ }, {Rhoconnect::API_TOKEN_HEADER => @api_token}
48
+ last_response.should be_ok
49
+ last_response.body.should == 'bar'
50
+ end
51
+
52
+ it "should retrieve string metric with old route and print deprecation warning" do
53
+ Store.db.set('stat:foo', 'bar')
54
+ post "/api/stats", {
55
+ :metric => 'foo'
56
+ }, {Rhoconnect::API_TOKEN_HEADER => @api_token}
50
57
  last_response.should be_ok
58
+ last_response.headers["Warning"].index('deprecated').should_not == nil
51
59
  last_response.body.should == 'bar'
52
60
  end
53
61
 
54
62
  it "should raise error on unknown metric" do
55
- post "/api/admin/stats", {
56
- :api_token => @api_token,
63
+ get "/rc/#{Rhoconnect::API_VERSION}/system/stats", {
57
64
  :metric => 'foo'
58
- }
65
+ }, {Rhoconnect::API_TOKEN_HEADER => @api_token}
59
66
  last_response.status.should == 404
60
67
  last_response.body.should == 'Unknown metric'
61
68
  end
@@ -63,10 +70,9 @@ describe "RhoconnectApiStats" do
63
70
  it "should raise error if stats not enabled" do
64
71
  Rhoconnect::Server.set :stats, false
65
72
  Rhoconnect.stats = false
66
- post "/api/admin/stats", {
67
- :api_token => @api_token,
73
+ get "/rc/#{Rhoconnect::API_VERSION}/system/stats", {
68
74
  :metric => 'foo'
69
- }
75
+ }, {Rhoconnect::API_TOKEN_HEADER => @api_token}
70
76
  last_response.status.should == 500
71
77
  last_response.body.should == 'Stats not enabled'
72
78
  end
@@ -3,22 +3,29 @@ require File.join(File.dirname(__FILE__),'..','api_helper')
3
3
  describe "RhoconnectApiCreateUser" do
4
4
  it_should_behave_like "ApiHelper" do
5
5
  it "should create user" do
6
- params = {:api_token => @api_token,
7
- :attributes => {:login => 'testuser1', :password => 'testpass1'}}
8
- post "/api/user/create_user", params
6
+ params = {:attributes => {:login => 'testuser1', :password => 'testpass1'}}
7
+ post "/rc/#{Rhoconnect::API_VERSION}/users", params, {Rhoconnect::API_TOKEN_HEADER => @api_token}
9
8
  last_response.should be_ok
10
9
  User.load(params[:attributes][:login]).login.should == params[:attributes][:login]
11
10
  User.authenticate(params[:attributes][:login],
12
11
  params[:attributes][:password]).login.should == params[:attributes][:login]
13
12
  @a.users.members.sort.should == [@u.login, params[:attributes][:login]]
14
13
  end
15
- end
14
+
15
+ it "should create user and print a deprecation warning in the route" do
16
+ params = {:attributes => {:login => 'testuser1', :password => 'testpass1'}}
17
+ post "/api/create_user", params, {Rhoconnect::API_TOKEN_HEADER => @api_token}
18
+ last_response.should be_ok
19
+ last_response.headers['Warning'].index('deprecated').should_not == nil
20
+ User.load(params[:attributes][:login]).login.should == params[:attributes][:login]
21
+ User.authenticate(params[:attributes][:login],
22
+ params[:attributes][:password]).login.should == params[:attributes][:login]
23
+ @a.users.members.sort.should == [@u.login, params[:attributes][:login]]
24
+ end
16
25
 
17
- it_should_behave_like "ApiHelper" do
18
26
  it "should not create user with empty login" do
19
- params = {:api_token => @api_token,
20
- :attributes => {:login => '', :password => ''}}
21
- post "/api/user/create_user", params
27
+ params = {:attributes => {:login => '', :password => ''}}
28
+ post "/rc/#{Rhoconnect::API_VERSION}/users", params, {Rhoconnect::API_TOKEN_HEADER => @api_token}
22
29
  last_response.should_not be_ok
23
30
  User.is_exist?('').should == false
24
31
  end