adhearsion 1.2.6 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/.gitignore +17 -10
  2. data/CHANGELOG.md +273 -0
  3. data/Gemfile +1 -1
  4. data/Guardfile +17 -0
  5. data/README.markdown +61 -9
  6. data/Rakefile +16 -48
  7. data/adhearsion.gemspec +21 -7
  8. data/bin/ahn +3 -1
  9. data/cucumber.yml +4 -0
  10. data/features/app_generator.feature +42 -0
  11. data/features/cli.feature +108 -0
  12. data/features/step_definitions/app_generator_steps.rb +6 -0
  13. data/features/step_definitions/cli_steps.rb +74 -0
  14. data/features/support/aruba_helper.rb +22 -0
  15. data/features/support/env.rb +37 -0
  16. data/features/support/utils.rb +8 -0
  17. data/lib/adhearsion.rb +85 -41
  18. data/lib/adhearsion/call.rb +176 -0
  19. data/lib/adhearsion/call_controller.rb +134 -0
  20. data/lib/adhearsion/call_controller/dial.rb +70 -0
  21. data/lib/adhearsion/call_controller/input.rb +173 -0
  22. data/lib/adhearsion/call_controller/menu.rb +124 -0
  23. data/lib/adhearsion/call_controller/output.rb +267 -0
  24. data/lib/adhearsion/call_controller/record.rb +42 -0
  25. data/lib/adhearsion/call_controller/utility.rb +60 -0
  26. data/lib/adhearsion/calls.rb +81 -0
  27. data/lib/adhearsion/cli.rb +1 -3
  28. data/lib/adhearsion/cli_commands.rb +142 -0
  29. data/lib/adhearsion/configuration.rb +149 -0
  30. data/lib/adhearsion/console.rb +19 -8
  31. data/lib/adhearsion/dialplan_controller.rb +9 -0
  32. data/lib/adhearsion/events.rb +84 -0
  33. data/lib/adhearsion/foundation/all.rb +0 -7
  34. data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
  35. data/lib/adhearsion/foundation/exception_handler.rb +9 -0
  36. data/lib/adhearsion/foundation/object.rb +26 -8
  37. data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
  38. data/lib/adhearsion/foundation/thread_safety.rb +17 -1
  39. data/lib/adhearsion/generators/app/app_generator.rb +4 -13
  40. data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
  41. data/lib/adhearsion/generators/app/templates/Procfile +1 -0
  42. data/lib/adhearsion/generators/app/templates/README.md +28 -0
  43. data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
  44. data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
  45. data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
  46. data/lib/adhearsion/initializer.rb +151 -293
  47. data/lib/adhearsion/initializer/logging.rb +33 -0
  48. data/lib/adhearsion/logging.rb +65 -69
  49. data/lib/adhearsion/menu_dsl.rb +15 -0
  50. data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
  51. data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
  52. data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
  53. data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
  54. data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
  55. data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
  56. data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
  57. data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
  58. data/lib/adhearsion/outbound_call.rb +64 -0
  59. data/lib/adhearsion/plugin.rb +319 -0
  60. data/lib/adhearsion/plugin/collection.rb +19 -0
  61. data/lib/adhearsion/plugin/initializer.rb +37 -0
  62. data/lib/adhearsion/plugin/methods_container.rb +6 -0
  63. data/lib/adhearsion/process.rb +94 -0
  64. data/lib/adhearsion/punchblock_plugin.rb +29 -0
  65. data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
  66. data/lib/adhearsion/router.rb +30 -0
  67. data/lib/adhearsion/router/route.rb +42 -0
  68. data/lib/adhearsion/script_ahn_loader.rb +2 -2
  69. data/lib/adhearsion/tasks.rb +14 -9
  70. data/lib/adhearsion/tasks/configuration.rb +26 -0
  71. data/lib/adhearsion/tasks/plugins.rb +17 -0
  72. data/lib/adhearsion/version.rb +8 -14
  73. data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
  74. data/spec/adhearsion/call_controller/input_spec.rb +278 -0
  75. data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
  76. data/spec/adhearsion/call_controller/output_spec.rb +466 -0
  77. data/spec/adhearsion/call_controller/record_spec.rb +125 -0
  78. data/spec/adhearsion/call_controller_spec.rb +395 -0
  79. data/spec/adhearsion/call_spec.rb +438 -0
  80. data/spec/adhearsion/calls_spec.rb +47 -0
  81. data/spec/adhearsion/configuration_spec.rb +308 -0
  82. data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
  83. data/spec/adhearsion/events_spec.rb +112 -0
  84. data/spec/adhearsion/initializer/logging_spec.rb +58 -0
  85. data/spec/adhearsion/initializer_spec.rb +209 -122
  86. data/spec/adhearsion/logging_spec.rb +58 -47
  87. data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
  88. data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
  89. data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
  90. data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
  91. data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
  92. data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
  93. data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
  94. data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
  95. data/spec/adhearsion/menu_dsl_spec.rb +12 -0
  96. data/spec/adhearsion/outbound_call_spec.rb +174 -0
  97. data/spec/adhearsion/plugin_spec.rb +489 -0
  98. data/spec/adhearsion/process_spec.rb +34 -0
  99. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
  100. data/spec/adhearsion/router/route_spec.rb +99 -0
  101. data/spec/adhearsion/router_spec.rb +106 -0
  102. data/spec/adhearsion_spec.rb +46 -0
  103. data/spec/spec_helper.rb +14 -14
  104. data/spec/support/call_controller_test_helpers.rb +48 -0
  105. data/spec/support/initializer_stubs.rb +8 -13
  106. data/spec/support/punchblock_mocks.rb +6 -0
  107. metadata +255 -253
  108. data/CHANGELOG +0 -174
  109. data/bin/ahnctl +0 -68
  110. data/bin/jahn +0 -43
  111. data/examples/asterisk_manager_interface/standalone.rb +0 -51
  112. data/lib/adhearsion/commands.rb +0 -302
  113. data/lib/adhearsion/component_manager.rb +0 -278
  114. data/lib/adhearsion/component_manager/component_tester.rb +0 -54
  115. data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
  116. data/lib/adhearsion/events_support.rb +0 -65
  117. data/lib/adhearsion/foundation/blank_slate.rb +0 -3
  118. data/lib/adhearsion/foundation/event_socket.rb +0 -205
  119. data/lib/adhearsion/foundation/future_resource.rb +0 -36
  120. data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
  121. data/lib/adhearsion/foundation/numeric.rb +0 -13
  122. data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
  123. data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
  124. data/lib/adhearsion/foundation/string.rb +0 -26
  125. data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
  126. data/lib/adhearsion/generators/app/templates/README +0 -8
  127. data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
  128. data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
  129. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
  130. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
  131. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
  132. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
  133. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
  134. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
  135. data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
  136. data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
  137. data/lib/adhearsion/generators/app/templates/events.rb +0 -33
  138. data/lib/adhearsion/host_definitions.rb +0 -67
  139. data/lib/adhearsion/initializer/asterisk.rb +0 -86
  140. data/lib/adhearsion/initializer/configuration.rb +0 -324
  141. data/lib/adhearsion/initializer/database.rb +0 -60
  142. data/lib/adhearsion/initializer/drb.rb +0 -31
  143. data/lib/adhearsion/initializer/freeswitch.rb +0 -22
  144. data/lib/adhearsion/initializer/ldap.rb +0 -57
  145. data/lib/adhearsion/initializer/rails.rb +0 -41
  146. data/lib/adhearsion/initializer/xmpp.rb +0 -42
  147. data/lib/adhearsion/tasks/components.rb +0 -32
  148. data/lib/adhearsion/tasks/database.rb +0 -5
  149. data/lib/adhearsion/tasks/deprecations.rb +0 -59
  150. data/lib/adhearsion/tasks/generating.rb +0 -20
  151. data/lib/adhearsion/tasks/lint.rb +0 -4
  152. data/lib/adhearsion/voip/asterisk.rb +0 -4
  153. data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
  154. data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
  155. data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
  156. data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
  157. data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
  158. data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
  159. data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
  160. data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
  161. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
  162. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
  163. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
  164. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
  165. data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
  166. data/lib/adhearsion/voip/call.rb +0 -521
  167. data/lib/adhearsion/voip/call_routing.rb +0 -64
  168. data/lib/adhearsion/voip/commands.rb +0 -17
  169. data/lib/adhearsion/voip/constants.rb +0 -39
  170. data/lib/adhearsion/voip/conveniences.rb +0 -18
  171. data/lib/adhearsion/voip/dial_plan.rb +0 -252
  172. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
  173. data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
  174. data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
  175. data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
  176. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
  177. data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
  178. data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
  179. data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
  180. data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
  181. data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
  182. data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
  183. data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
  184. data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
  185. data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
  186. data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
  187. data/lib/adhearsion/xmpp/connection.rb +0 -61
  188. data/lib/theatre.rb +0 -147
  189. data/lib/theatre/README.markdown +0 -64
  190. data/lib/theatre/callback_definition_loader.rb +0 -86
  191. data/lib/theatre/guid.rb +0 -23
  192. data/lib/theatre/invocation.rb +0 -131
  193. data/lib/theatre/namespace_manager.rb +0 -153
  194. data/lib/theatre/version.rb +0 -2
  195. data/spec/adhearsion/cli_spec.rb +0 -306
  196. data/spec/adhearsion/component_manager_spec.rb +0 -292
  197. data/spec/adhearsion/constants_spec.rb +0 -8
  198. data/spec/adhearsion/drb_spec.rb +0 -65
  199. data/spec/adhearsion/fixtures/dialplan.rb +0 -3
  200. data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
  201. data/spec/adhearsion/host_definitions_spec.rb +0 -79
  202. data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
  203. data/spec/adhearsion/initializer/loading_spec.rb +0 -154
  204. data/spec/adhearsion/initializer/paths_spec.rb +0 -74
  205. data/spec/adhearsion/relationship_properties_spec.rb +0 -54
  206. data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
  207. data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
  208. data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
  209. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
  210. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
  211. data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
  212. data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
  213. data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
  214. data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
  215. data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
  216. data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
  217. data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
  218. data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
  219. data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
  220. data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
  221. data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
  222. data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
  223. data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
  224. data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
  225. data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
  226. data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
  227. data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
  228. data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
  229. data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
  230. data/spec/support/the_following_code.rb +0 -3
  231. data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
  232. data/spec/theatre/dsl_spec.rb +0 -69
  233. data/spec/theatre/invocation_spec.rb +0 -182
  234. data/spec/theatre/namespace_spec.rb +0 -125
  235. data/spec/theatre/spec_helper_spec.rb +0 -28
  236. data/spec/theatre/theatre_class_spec.rb +0 -148
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module PathsTestHelper
4
- def mock_ahnrc_with(raw_yaml)
5
- Adhearsion::AHN_CONFIG.ahnrc = raw_yaml
6
- end
7
- end
8
-
9
- describe "Files from config" do
10
-
11
- include PathsTestHelper
12
-
13
- it "the old way of doing paths should not still be around" do
14
- should_not respond_to(:all_helpers)
15
- should_not respond_to(:helper_path)
16
- end
17
-
18
- it "should work when only one filename is present" do
19
- mock_ahnrc_with "paths:\n init: foobar.rb"
20
- flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with("foobar.rb").and_return "foobar.rb"
21
- Adhearsion::AHN_CONFIG.files_from_setting("paths", "init").should ==["foobar.rb"]
22
- end
23
-
24
- it "should only expand a glob if the filename contains *"
25
-
26
- it "should work when an Array of filenames is present" do
27
- files = %w[jay.rb thomas.rb phillips.rb]
28
- flexstub(Dir).should_receive(:glob).with(*files).and_return(*files)
29
- yaml = <<-YML
30
- paths:
31
- init:
32
- #{
33
- files.map { |f| " - #{f}" }.join("\n")
34
- }
35
- YML
36
- Adhearsion::AHN_CONFIG.ahnrc = yaml
37
-
38
- flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with("jay.rb").and_return "jay.rb"
39
- flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with("thomas.rb").and_return "thomas.rb"
40
- flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with("phillips.rb").and_return "phillips.rb"
41
-
42
- Adhearsion::AHN_CONFIG.files_from_setting("paths", "init").should == files
43
- end
44
-
45
- it "should work when one glob filename is present" do
46
- files = %w[foo.rb bar.rb qaz.rb]
47
- flexmock(Dir).should_receive(:glob).once.with(/\*.rb$/).and_return files
48
- yaml = <<-YML
49
- paths:
50
- init:
51
- -*.rb
52
- YML
53
- Adhearsion::AHN_CONFIG.ahnrc = yaml
54
- Adhearsion::AHN_CONFIG.files_from_setting("paths", "init").should == %w[foo.rb bar.rb qaz.rb]
55
- end
56
-
57
- it "should work when an Array of globs are present" do
58
- files = %w[aaa.rb aba.rb aca.rb]
59
- flexstub(Dir).should_receive(:glob).with(*files).and_return(*files)
60
- yaml = <<-YML
61
- paths:
62
- init:
63
- #{
64
- files.map { |filename| " - #{filename}" }.join("\n") + "\n"
65
- }
66
- YML
67
- Adhearsion::AHN_CONFIG.ahnrc = yaml
68
- files.each do |file|
69
- flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with(file).and_return file
70
- end
71
- Adhearsion::AHN_CONFIG.files_from_setting("paths", "init").should == files
72
- end
73
-
74
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
- require 'adhearsion/foundation/relationship_properties'
3
-
4
- describe "Module#relationships" do
5
-
6
- describe "Overriding relationships in subclasses" do
7
-
8
- it "should be overridable in subclasses" do
9
- super_class = Class.new do
10
- relationships :storage_medium => Array
11
- end
12
- sub_class = Class.new(super_class) do
13
- relationships :storage_medium => Hash
14
- end
15
- super_class.new.send(:storage_medium).should be Array
16
- sub_class.new.send(:storage_medium).should be Hash
17
- end
18
-
19
- it "should not affect other defined relationships" do
20
- super_class = Class.new do
21
- relationships :io_class => TCPSocket, :error_class => StandardError
22
- end
23
- sub_class = Class.new(super_class) do
24
- relationships :error_class => RuntimeError
25
- end
26
- super_class.new.send(:io_class).should be TCPSocket
27
- sub_class.new.send(:io_class).should be TCPSocket
28
- end
29
-
30
- end
31
-
32
- it "should be accessible within instance methods of that Class as another instance method" do
33
- klass = Class.new do
34
- relationships :struct => Struct
35
- def new_struct
36
- struct.new
37
- end
38
- end
39
- end
40
-
41
- it "should be accessible in subclasses" do
42
- super_class = Class.new do
43
- relationships :number_class => Bignum
44
- end
45
-
46
- Class.new(super_class) do
47
- def number_class_name
48
- number_class.name
49
- end
50
- end.new.number_class_name.should == "Bignum"
51
-
52
- end
53
-
54
- end
@@ -1,473 +0,0 @@
1
- require 'spec_helper'
2
- require 'adhearsion/voip/asterisk'
3
-
4
- module CallVariableTestHelper
5
- def parsed_call_variables_from(io)
6
- Adhearsion::Call::Variables::Parser.parse(io).variables
7
- end
8
-
9
- def coerce_call_variables(variables)
10
- Adhearsion::Call::Variables::Parser.coerce_variables(variables)
11
- end
12
-
13
- def merged_hash_with_call_variables(new_hash)
14
- call_variables_with_new_query = typical_call_variables_hash.merge new_hash
15
- coerce_call_variables call_variables_with_new_query
16
- end
17
-
18
- def parsed_call_variables_with_query(query_string)
19
- request_string = "agi://10.0.0.0/#{query_string}"
20
- merged_hash_with_call_variables({:request => request_string})[:query]
21
- end
22
-
23
- def typical_call_variable_io
24
- StringIO.new(typical_call_variable_section)
25
- end
26
-
27
- def typical_call_variable_section
28
- <<-VARIABLES
29
- agi_network: yes
30
- agi_request: agi://10.0.0.152/monkey?foo=bar&qaz=qwerty
31
- agi_channel: SIP/marcel-b58046e0
32
- agi_language: en
33
- agi_type: SIP
34
- agi_uniqueid: 1191245124.16
35
- agi_callerid: 011441234567899
36
- agi_calleridname: unknown
37
- agi_callingpres: 0
38
- agi_callingani2: 0
39
- agi_callington: 0
40
- agi_callingtns: 0
41
- agi_dnid: 911
42
- agi_rdnis: unknown
43
- agi_context: adhearsion
44
- agi_extension: 911
45
- agi_priority: 1
46
- agi_enhanced: 0.0
47
- agi_accountcode:
48
-
49
- VARIABLES
50
- end
51
-
52
- # TODO:
53
- # - "unknown" should be converted to nil
54
- # - "yes" or "no" should be converted to true or false
55
- # - numbers beginning with a 0 MUST be converted to a NumericalString
56
- # - Look up why there are so many zeroes. They're likely reprentative of some PRI definition.
57
-
58
- def typical_call_variables_hash
59
- uncoerced_variable_map = expected_uncoerced_variable_map
60
-
61
- uncoerced_variable_map[:request] = URI.parse(uncoerced_variable_map[:request])
62
- uncoerced_variable_map[:extension] = 911 # Adhearsion::VoIP::DSL::PhoneNumber.new(uncoerced_variable_map[:extension]) #
63
- uncoerced_variable_map[:callerid] = Adhearsion::VoIP::DSL::NumericalString.new(uncoerced_variable_map[:callerid])
64
-
65
- uncoerced_variable_map[:network] = true
66
- uncoerced_variable_map[:calleridname] = nil
67
- uncoerced_variable_map[:callingpres] = 0
68
- uncoerced_variable_map[:callingani2] = 0
69
- uncoerced_variable_map[:callingtns] = 0
70
- uncoerced_variable_map[:dnid] = 911
71
- uncoerced_variable_map[:rdnis] = nil
72
- uncoerced_variable_map[:priority] = 1
73
- uncoerced_variable_map[:enhanced] = 0.0
74
- uncoerced_variable_map[:uniqueid] = "1191245124.16"
75
-
76
- uncoerced_variable_map[:type_of_calling_number] = Adhearsion::VoIP::Constants::Q931_TYPE_OF_NUMBER[uncoerced_variable_map.delete(:callington).to_i]
77
-
78
- coerced_variable_map = uncoerced_variable_map
79
- coerced_variable_map[:query] = {"foo" => "bar", "qaz" => "qwerty"}
80
- coerced_variable_map[:foo] = 'bar'
81
- coerced_variable_map[:qaz] = 'qwerty'
82
- coerced_variable_map
83
- end
84
-
85
- def expected_uncoerced_variable_map
86
- {:network => 'yes',
87
- :request => 'agi://10.0.0.152/monkey?foo=bar&qaz=qwerty',
88
- :channel => 'SIP/marcel-b58046e0',
89
- :language => 'en',
90
- :type => 'SIP',
91
- :uniqueid => '1191245124.16',
92
- :callerid => '011441234567899',
93
- :calleridname => 'unknown',
94
- :callingpres => '0',
95
- :callingani2 => '0',
96
- :callington => '0',
97
- :callingtns => '0',
98
- :dnid => '911',
99
- :rdnis => 'unknown',
100
- :context => 'adhearsion',
101
- :extension => '911',
102
- :priority => '1',
103
- :enhanced => '0.0',
104
- :accountcode => ''}
105
- end
106
- end
107
-
108
- module AgiServerTestHelper
109
- def stub_before_call_hooks!
110
- flexstub(Adhearsion::Events).should_receive(:trigger).with([:asterisk, :before_call], Proc).and_return
111
- end
112
-
113
- def stub_confirmation_manager!
114
- flexstub(Adhearsion::DialPlan::ConfirmationManager).should_receive(:confirmation_call?).and_return false
115
- end
116
- end
117
-
118
- describe "The AGI server's serve() method" do
119
-
120
- include AgiServerTestHelper
121
-
122
- attr_reader :server_class, :server
123
- before :each do
124
- @server_class = Adhearsion::VoIP::Asterisk::AGI::Server::RubyServer
125
- @server = @server_class.new(:port,:host)
126
- end
127
-
128
- before :each do
129
- Adhearsion::Events.reinitialize_theatre!
130
- end
131
-
132
- it 'should instantiate a new Call with the IO object it receives' do
133
- stub_before_call_hooks!
134
- io_mock = flexmock "Mock IO object that's passed to the serve() method"
135
- call_mock = flexmock "A Call mock that's returned by Adhearsion#receive_call_from", :variable => {}
136
- flexstub(server_class).should_receive(:ahn_log)
137
- the_following_code {
138
- flexmock(Adhearsion).should_receive(:receive_call_from).once.with(io_mock).and_throw :created_call!
139
- server.serve(io_mock)
140
- }.should throw_symbol :created_call!
141
- end
142
-
143
- it 'should hand the call off to a new Manager if the request is agi://IP_ADDRESS_HERE' do
144
- stub_before_call_hooks!
145
- call_mock = flexmock 'A new mock call that will be passed to the manager', :variables => {}, :unique_identifier => "X"
146
-
147
- flexmock(Adhearsion).should_receive(:receive_call_from).once.and_return call_mock
148
- manager_mock = flexmock 'a mock dialplan manager'
149
- manager_mock.should_receive(:handle).once.with(call_mock)
150
- flexmock(Adhearsion::DialPlan::Manager).should_receive(:new).once.and_return manager_mock
151
- server.serve(nil)
152
- end
153
-
154
- it 'should hand off a call to a ConfirmationManager if the request begins with confirm!' do
155
- confirm_options = Adhearsion::DialPlan::ConfirmationManager.encode_hash_for_dial_macro_argument :timeout => 20, :key => "#"
156
- call_mock = flexmock "a call that has network_script as a variable", :variables => {:network_script => "confirm!#{confirm_options[/^M\(\^?(.+)\)$/,1]}"}, :unique_identifier => "X"
157
- manager_mock = flexmock 'a mock ConfirmationManager'
158
-
159
- the_following_code {
160
- flexstub(Adhearsion).should_receive(:receive_call_from).once.and_return(call_mock)
161
- flexmock(Adhearsion::DialPlan::ConfirmationManager).should_receive(:confirmation_call?).once.with(call_mock).and_return true
162
- flexmock(Adhearsion::DialPlan::ConfirmationManager).should_receive(:handle).once.with(call_mock).and_throw :handled_call!
163
- server.serve(nil)
164
- }.should throw_symbol :handled_call!
165
- end
166
-
167
- it 'calling the serve() method invokes the before_call event' do
168
- mock_io = flexmock "mock IO object given to AGIServer#serve"
169
- mock_call = flexmock "mock Call"
170
- flexmock(Adhearsion).should_receive(:receive_call_from).once.with(mock_io).and_return mock_call
171
-
172
- flexmock(Adhearsion::Events).should_receive(:trigger_immediately).once.with([:asterisk, :before_call], mock_call).
173
- and_throw :triggered
174
-
175
- the_following_code {
176
- server.serve mock_io
177
- }.should throw_symbol :triggered
178
- end
179
-
180
- it 'should execute the hungup_call event when a HungupExtensionCallException is raised' do
181
- call_mock = flexmock 'a bogus call', :hungup_call? => true, :variables => {:extension => "h"}, :unique_identifier => "X"
182
- mock_env = flexmock "A mock execution environment which gets passed along in the HungupExtensionCallException"
183
-
184
- stub_confirmation_manager!
185
- flexstub(Adhearsion).should_receive(:receive_call_from).once.and_return(call_mock)
186
- flexmock(Adhearsion::DialPlan::Manager).should_receive(:handle).once.and_raise Adhearsion::HungupExtensionCallException.new(mock_env)
187
- flexmock(Adhearsion::Events).should_receive(:trigger).once.with([:asterisk, :hungup_call], mock_env).and_throw :hungup_call
188
-
189
- the_following_code { server.serve nil }.should throw_symbol :hungup_call
190
- end
191
-
192
- it 'should execute the OnFailedCall hooks when a FailedExtensionCallException is raised' do
193
- call_mock = flexmock 'a bogus call', :failed_call? => true, :variables => {:extension => "failed"}, :unique_identifier => "X"
194
- mock_env = flexmock "A mock execution environment which gets passed along in the HungupExtensionCallException", :failed_reason => "does not matter"
195
-
196
- server = Adhearsion::VoIP::Asterisk::AGI::Server::RubyServer.new :port, :host
197
-
198
- flexmock(Adhearsion).should_receive(:receive_call_from).once.and_return(call_mock)
199
- flexmock(Adhearsion::DialPlan::Manager).should_receive(:handle).once.and_raise Adhearsion::FailedExtensionCallException.new(mock_env)
200
- flexmock(Adhearsion::Events).should_receive(:trigger).once.with([:asterisk, :failed_call], mock_env).and_throw :failed_call
201
- the_following_code { server.serve nil }.should throw_symbol :failed_call
202
- end
203
-
204
- end
205
-
206
- describe "Active Calls" do
207
- include CallVariableTestHelper
208
- attr_accessor :typical_call
209
-
210
- before do
211
- @mock_io = StringIO.new
212
- @typical_call = Adhearsion::Call.new(@mock_io, typical_call_variables_hash)
213
- end
214
-
215
- after do
216
- Adhearsion::active_calls.clear!
217
- end
218
-
219
- it 'A Call object can be instantiated with a hash of attributes' do
220
- the_following_code {
221
- Adhearsion::Call.new(@mock_io, {})
222
- }.should_not raise_error
223
- end
224
-
225
- it 'Attributes passed into initialization of call object are accessible as attributes on the object' do
226
- Adhearsion::Call.new(@mock_io, {:channel => typical_call_variables_hash[:channel]}).channel.should == typical_call_variables_hash[:channel]
227
- end
228
-
229
- it 'Attributes passed into initialization of call object are accessible in the variables() Hash' do
230
- variables = Adhearsion::Call.new(@mock_io, typical_call_variables_hash).variables
231
- typical_call_variables_hash.each{|key, value|
232
- value.should == variables[key]
233
- }
234
- end
235
-
236
- it 'Can add a call to the active calls list' do
237
- Adhearsion.active_calls.any?.should be false
238
- Adhearsion.active_calls << typical_call
239
- Adhearsion.active_calls.size.should == 1
240
- end
241
-
242
- it 'A hungup call removes itself from the active calls' do
243
- mock_io = flexmock typical_call_variable_io
244
- mock_io.should_receive(:close).once
245
-
246
- size_before = Adhearsion.active_calls.size
247
-
248
- call = Adhearsion.receive_call_from mock_io
249
- Adhearsion.active_calls.size.should > size_before
250
- call.hangup!
251
- Adhearsion.active_calls.size.should == size_before
252
- end
253
-
254
- it 'Can find active call by unique ID' do
255
- Adhearsion.active_calls << typical_call
256
- Adhearsion.active_calls.find(typical_call_variables_hash[:channel]).should_not be nil
257
- end
258
-
259
- it 'A call can store the IO associated with the PBX/switch connection' do
260
- Adhearsion::Call.new(@mock_io, {}).should respond_to(:io)
261
- end
262
-
263
- it 'A call can be instantiated given a PBX/switch IO' do
264
- call = Adhearsion::Call.receive_from(typical_call_variable_io)
265
- call.should be_a_kind_of(Adhearsion::Call)
266
- call.channel.should == typical_call_variables_hash[:channel]
267
- end
268
-
269
- it 'A call with an extension of "t" raises a UselessCallException' do
270
- the_following_code {
271
- Adhearsion::Call.new(@mock_io, typical_call_variables_hash.merge(:extension => 't'))
272
- }.should raise_error(Adhearsion::UselessCallException)
273
- end
274
-
275
- it 'Can create a call and add it via a top-level method on the Adhearsion module' do
276
- Adhearsion.active_calls.any?.should be false
277
- call = Adhearsion.receive_call_from(typical_call_variable_io)
278
- call.should be_a_kind_of(Adhearsion::Call)
279
- Adhearsion.active_calls.size.should == 1
280
- end
281
-
282
- it 'A call can identify its originating voip platform' do
283
- call = Adhearsion::receive_call_from(typical_call_variable_io)
284
- call.originating_voip_platform.should be(:asterisk)
285
- end
286
-
287
- end
288
-
289
- describe 'A new Call object' do
290
-
291
- include CallVariableTestHelper
292
-
293
- it "it should have an @inbox object that's a synchronized Queue" do
294
- new_call = Adhearsion::Call.new(nil, {})
295
- new_call.inbox.should be_a_kind_of Queue
296
- new_call.should respond_to :<<
297
- end
298
-
299
- it 'the unique_identifier() method should return the :channel variable for :asterisk calls' do
300
- variables = typical_call_variables_hash
301
- new_call = Adhearsion::Call.new(nil, typical_call_variables_hash)
302
- flexmock(new_call).should_receive(:originating_voip_platform).and_return :asterisk
303
- new_call.unique_identifier.should == variables[:channel]
304
- end
305
-
306
- it "Call#define_singleton_accessor_with_pair should define a singleton method, not a class method" do
307
- control = Adhearsion::Call.new(nil, {})
308
- experiment = Adhearsion::Call.new(nil, {})
309
-
310
- experiment.send(:define_singleton_accessor_with_pair, "ohai", 123)
311
- experiment.should respond_to "ohai"
312
- control.should_not respond_to "ohai"
313
- end
314
-
315
- end
316
-
317
- describe 'the Calls collection' do
318
-
319
- include CallVariableTestHelper
320
-
321
- it 'the #<< method should add a Call to the Hash with its unique_id' do
322
- id = rand
323
- collection = Adhearsion::Calls.new
324
- call = Adhearsion::Call.new(nil, {})
325
- flexmock(call).should_receive(:unique_identifier).and_return id
326
- collection << call
327
- hash = collection.instance_variable_get("@calls")
328
- hash.empty?.should_not be true
329
- hash[id].should be call
330
- end
331
-
332
- it '#size should return the size of the Hash' do
333
- collection = Adhearsion::Calls.new
334
- collection.size.should be 0
335
- collection << Adhearsion::Call.new(nil, {})
336
- collection.size.should be 1
337
- end
338
-
339
- it '#remove_inactive_call should delete the call in the Hash' do
340
- collection = Adhearsion::Calls.new
341
-
342
- number_of_calls = 10
343
- unique_ids = Array.new(number_of_calls) { rand }
344
- calls = unique_ids.map { |id| Adhearsion::Call.new(nil, {:uniqueid => id}) }
345
- calls.each { |call| collection << call }
346
-
347
- deleted_call = calls[number_of_calls / 2]
348
- collection.remove_inactive_call deleted_call
349
- collection.size.should be number_of_calls - 1
350
- end
351
-
352
- it '#find_by_unique_id should pull the Call from the Hash using the unique_id' do
353
- id = rand
354
- call_database = flexmock "a mock Hash in which calls are stored"
355
- call_database.should_receive(:[]).once.with(id)
356
- collection = Adhearsion::Calls.new
357
- flexmock(collection).should_receive(:calls).once.and_return(call_database)
358
- collection.find(id)
359
- end
360
-
361
- end
362
-
363
- describe 'Typical call variable parsing with typical data that has no special treatment' do
364
- include CallVariableTestHelper
365
- attr_reader :variables, :io
366
-
367
- before(:each) do
368
- @io = typical_call_variable_io
369
- @variables = parsed_call_variables_from(io)
370
- end
371
-
372
- # it "listing all variable names" do
373
- # parser.variable_names.map(&:to_s).sort.should == typical_call_variables_hash.keys.map(&:to_s).sort
374
- # end
375
-
376
- it "extracts call variables into a Hash" do
377
- variables.kind_of?(Hash).should be true
378
- end
379
-
380
- it "extracting and converting variables and their values to a hash" do
381
- typical_call_variables_hash.each{|key, value|
382
- value.should == variables[key]
383
- }
384
- end
385
- end
386
-
387
- describe 'Call variable parsing with data that is treated specially' do
388
- include CallVariableTestHelper
389
- it "callington is renamed to type_of_calling_number" do
390
- variables = parsed_call_variables_from typical_call_variable_io
391
- variables[:type_of_calling_number].should == :unknown
392
- variables.has_key?(:callington).should == false
393
- end
394
- it "normalizes the context to be a valid Ruby method name"
395
- it "value of 'no' converts to false" do
396
- merged_hash_with_call_variables(:no_var => "no")[:no_var].should be(false)
397
- end
398
- it "value of 'yes' converts to true"
399
- it "value of 'unknown' converts to nil"
400
- it 'separate_line_into_key_value_pair parses values with spaces in them' do
401
- key, value = Adhearsion::Call::Variables::Parser.separate_line_into_key_value_pair("foo: My Name")
402
- value.should == 'My Name'
403
- end
404
-
405
- it "Uniqueid remains a String, not a Float" do
406
- uniqueid = "123456.12831"
407
- variables = merged_hash_with_call_variables :uniqueid => uniqueid
408
- variables[:uniqueid].should ==uniqueid
409
- end
410
-
411
- end
412
-
413
- describe 'Typical call variable line parsing with a typical line that is not treated specially' do
414
- include CallVariableTestHelper
415
- attr_reader :parser, :line
416
-
417
- before(:each) do
418
- @line = 'agi_channel: SIP/marcel-b58046e0'
419
- @key, @value = Adhearsion::Call::Variables::Parser.separate_line_into_key_value_pair line
420
- end
421
-
422
- it "raw name is extracted correctly" do
423
- @key.should == 'agi_channel'
424
- end
425
-
426
- it "raw value is extracted correctly" do
427
- @value.should == 'SIP/marcel-b58046e0'
428
- end
429
- end
430
-
431
- describe 'Call variable line parsing with a line that is treated specially' do
432
- include CallVariableTestHelper
433
- attr_reader :key, :value, :line
434
-
435
- before(:each) do
436
- @line = 'agi_request: agi://10.0.0.152'
437
- @key, @value = Adhearsion::Call::Variables::Parser.separate_line_into_key_value_pair line
438
- end
439
-
440
- it "splits out name and value correctly even if the value contains a semicolon (i.e. the same character that is used as the name/value separators)" do
441
- @key.should == 'agi_request'
442
- @value.should == 'agi://10.0.0.152'
443
- end
444
-
445
- end
446
-
447
- describe "Extracting the query from the request URI" do
448
- include CallVariableTestHelper
449
- attr_reader :parser
450
-
451
- before(:each) do
452
- # We don't want this Call::Variables::Parser to call parse because we only care about handling the request
453
- # variable which we mock here.
454
- @parser = Adhearsion::Call::Variables::Parser.new(StringIO.new('This argument does not matter'))
455
- end
456
-
457
- it "an empty hash is returned if there is no query string" do
458
- parsed_call_variables_with_query('').should == {}
459
- end
460
-
461
- it "a key and value for parameter is returned when there is one query string parameter" do
462
- parsed_call_variables_with_query('?foo=bar').should == {'foo' => 'bar'}
463
- end
464
-
465
- it "both key/value pairs are returned when there are a pair of query string parameters" do
466
- parsed_call_variables_with_query('?foo=bar&baz=quux').should == {'foo' => 'bar', 'baz' => 'quux'}
467
- end
468
-
469
- it "all key/value pairs are returned when there are more than a pair of query string parameters" do
470
- parsed_call_variables_with_query('?foo=bar&baz=quux&name=marcel').should == {'foo' => 'bar', 'baz' => 'quux', 'name' => 'marcel'}
471
- end
472
-
473
- end