Guest User

Untitled

a guest
Mar 11th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1.  
  2. #
  3. # Testing ruote-dm
  4. #
  5. # Sun Aug 9 19:39:16 JST 2009
  6. #
  7.  
  8. require File.join(File.dirname(__FILE__), 'path_helper')
  9.  
  10. require 'test/unit'
  11. require 'rubygems'
  12. require 'ruby-debug'
  13. Debugger.start
  14. require 'dm-core'
  15.  
  16.  
  17. DataMapper.setup(:default, {
  18. :adapter => 'postgres',
  19. :database => "alumni_development",
  20. :username => 'denis',
  21. :password => '',
  22. :host => 'localhost',
  23. :encoding => 'unicode',
  24. :pool => 1
  25. })
  26. DataMapper::Logger.new(STDOUT, 0)
  27.  
  28.  
  29. require 'ruote/dm/storage/dm_storage.rb'
  30. require 'ruote/dm/part/dm_participant.rb'
  31.  
  32. DataMapper.repository(:default) do
  33. Ruote::Dm::DmExpression.auto_upgrade!
  34. Ruote::Dm::DmWorkitem.auto_upgrade!
  35. end
  36.  
  37. require 'ruote/engine'
  38. require 'ruote/part/fs_participant'
  39. require 'ruote/dm/engine'
  40.  
  41. require 'ruote/fei'
  42. require 'ruote/workitem'
  43. require 'ruote/dm/part/dm_participant'
  44.  
  45.  
  46. class ParticipantTest < Test::Unit::TestCase
  47.  
  48. def setup
  49. setup_engine
  50.  
  51. @launchitem = Ruote::Launchitem.new(define_webflow_processus,:association_id => 1,:registrar_id => 125,:locale => 'fr_BE')
  52. end
  53.  
  54. def teardown
  55. DataMapper.repository(:default) do
  56. Ruote::Dm::DmWorkitem.all.destroy!
  57. end
  58. end
  59.  
  60. def test_stop_at_first_user_as_dmparticipant
  61. register_user_as_dmparticipant_with_bloc
  62. @engine.launch(@launchitem)
  63. sleep 5
  64.  
  65. #must stop at the first DMWorker the user one
  66. assert_equal 1, Ruote::Dm::DmWorkitem.all.size
  67. assert_not_nil Ruote::Dm::DmWorkitem.first.last_modified
  68. end
  69.  
  70. def test_stop_at_first_user_as_dmparticipant
  71. register_user_as_dmparticipant_without_bloc
  72. @engine.launch(@launchitem)
  73. sleep 5
  74.  
  75. #must stop at the first DMWorker the user one
  76. assert_equal 1, Ruote::Dm::DmWorkitem.all.size
  77. assert_not_nil Ruote::Dm::DmWorkitem.first.last_modified
  78. end
  79.  
  80. protected
  81.  
  82. def define_webflow_processus
  83. Ruote.process_definition :name => 'Registration process' do
  84. sequence do
  85. setup
  86. look_for_matching_profile
  87. _if :test => "${f:match_profile_status} == no" do
  88. sequence do
  89. # Two things, alert the admins and give them work
  90. alert :role => "superuser or admin_of_group :association", :message => "Could not match ${f:registrar_id} in association ${f:association_id}"
  91. guest_email :type => "profile_does_not_match"
  92. #need user interaction process must stop here
  93. user :role => "superuser or admin_of_group :association", :activity => "Registration matching failed"
  94. end
  95. end
  96.  
  97. _if :test => "${f:match_profile_status} == active" do
  98. sequence do
  99. # Two things, alert the admins and give them work
  100. guest_email :type => "profile_already_activated" ,:redirect_url => 'lost_password'
  101. alert :role => "superuser or admin_of_group :association", :message => "Registrar ${f:registrar_id} in association ${f:association_id} try to register an active account ${f:match_profile_errors.join(', ')}"
  102. end
  103. end
  104. _if :test => "${f:match_profile_status} == yes" do
  105. sequence do
  106. # Two things, alert the admins and give them work
  107. #send an email for confirming the email et finish the comletion of the profile
  108. guest_email :type => "profile_already_activated",:redirect_url => 'double_optin'
  109.  
  110. associate_registrar_with_his_matched_profile
  111. #wait for the registrar to complete his profile
  112. #need user interaction process must stop here
  113. user :user_id => "${f:user_id}", :activity => "double optin registration"
  114. #need user interaction process must stop here
  115. user :role => "superuser or admin_of_group :association", :activity => "validate matched profile"
  116. _if :test => "${f:matched_profile_activated} == true " do
  117. sequence do
  118. activated_matched_profile
  119. user_email :user_id => "${f:user_id}", :type => "account activated"
  120. end
  121. #_else
  122. sequence do
  123. #workitem contains subject and
  124. user_email :user_id => "${f:user_id}", :type => "account refused"
  125. end
  126. end
  127. end
  128. alert :message => "something wrong with match_profile_status :${f:match_profile_status}\n"
  129. end
  130.  
  131. end
  132.  
  133. process_definition "setup" do
  134. set :f => "match_profile_status", :val => "tobematched"
  135. set :f => "match_profile_errors", :val => []
  136. set :f => "matched_user_id", :val => ''
  137. set :f => "matched_profile_validated", :val => false
  138. end
  139. end
  140. end
  141.  
  142. def setup_engine
  143.  
  144. application_context = {}
  145.  
  146. application_context[:engine_class] ||= Ruote::Dm::DmPersistedEngine #Ruote::Extras::ArPersistedEngine
  147.  
  148. application_context[:work_directory] ||= "#{File.dirname(__FILE__)}/work"
  149.  
  150. application_context[:ruby_eval_allowed] ||= true
  151. # the 'reval' expression and the ${r:some_ruby_code} notation are allowed
  152.  
  153. application_context[:dynamic_eval_allowed] ||= true
  154. # the 'eval' expression is allowed
  155.  
  156. application_context[:definition_in_launchitem_allowed] ||= true
  157. # launchitems (process_items) may contain process definitions
  158.  
  159.  
  160. engine_class = application_context.delete(:engine_class)
  161.  
  162. @engine = engine_class.new(application_context)
  163. @engine.register_participant :alert do |workitem|
  164. puts "Alert : #{}"
  165. end
  166.  
  167. @engine.register_participant :guest_email do |workitem|
  168. puts "guest_email : #{inspect_params(workitem)}\n"
  169. end
  170.  
  171. @engine.register_participant :user_email do |workitem|
  172. puts "user_email : #{inspect_params(workitem)}\n"
  173. end
  174.  
  175. @engine.register_participant :look_for_matching_profile do |workitem|
  176. puts "look_for_matching_profile : #{inspect_params(workitem)}\n"
  177. workitem.fields["match_profile_status"]= 'no' #'yes'
  178. workitem.fields["matched_user_id"] = nil # 123
  179. end
  180.  
  181. @engine.register_participant :activated_matched_profile do |workitem|
  182. puts "activated_matched_profile : #{inspect_params(workitem)}\n"
  183. workitem.fields["matched_profile_validated"]= true
  184. end
  185.  
  186. @engine.register_participant :associate_registrar_with_his_matched_profile do |workitem|
  187. #flag registrar
  188. puts "activated_matched_profile : #{inspect_params(workitem)}\n"
  189. workitem.fields["matched_profile_activated"]= true
  190. end
  191.  
  192.  
  193. end
  194.  
  195. def register_user_as_dmparticipant_with_bloc
  196. #::Ruote::Dm::DmParticipant
  197. @engine.register_participant :user, ::Ruote::Dm::DmParticipant do |workitem|
  198. puts "user : #{inspect_params(workitem)}\n"
  199. end
  200. end
  201.  
  202. def register_user_as_dmparticipant_without_bloc
  203. #::Ruote::Dm::DmParticipant
  204. @engine.register_participant :user, ::Ruote::Dm::DmParticipant
  205. end
  206.  
  207. def register_user_as_fsparticipant
  208. #::Ruote::Dm::DmParticipant
  209. @engine.register_participant :user, ::Ruote::FsParticipant
  210. end
  211.  
  212. end
Add Comment
Please, Sign In to add comment