Guest User

Untitled

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