sevenscale-adhearsion 0.7.1003 → 0.8.0

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 (149) hide show
  1. data/CHANGELOG +8 -2
  2. data/EVENTS +11 -0
  3. data/Rakefile +92 -26
  4. data/adhearsion.gemspec +131 -23
  5. data/app_generators/ahn/ahn_generator.rb +21 -7
  6. data/app_generators/ahn/templates/.ahnrc +10 -4
  7. data/app_generators/ahn/templates/Rakefile +7 -2
  8. data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
  9. data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
  10. data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
  11. data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
  12. data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
  13. data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
  14. data/app_generators/ahn/templates/config/startup.rb +3 -6
  15. data/app_generators/ahn/templates/dialplan.rb +2 -3
  16. data/app_generators/ahn/templates/events.rb +32 -6
  17. data/bin/jahn +10 -0
  18. data/examples/asterisk_manager_interface/standalone.rb +51 -0
  19. data/lib/adhearsion/cli.rb +140 -23
  20. data/lib/adhearsion/component_manager/component_tester.rb +55 -0
  21. data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
  22. data/lib/adhearsion/component_manager.rb +169 -238
  23. data/lib/adhearsion/events_support.rb +59 -237
  24. data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
  25. data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
  26. data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
  27. data/lib/adhearsion/foundation/event_socket.rb +203 -0
  28. data/lib/adhearsion/foundation/future_resource.rb +36 -0
  29. data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
  30. data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
  31. data/lib/adhearsion/foundation/numeric.rb +13 -0
  32. data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
  33. data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
  34. data/lib/adhearsion/foundation/string.rb +26 -0
  35. data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
  36. data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
  37. data/lib/adhearsion/host_definitions.rb +5 -1
  38. data/lib/adhearsion/initializer/asterisk.rb +33 -11
  39. data/lib/adhearsion/initializer/configuration.rb +58 -6
  40. data/lib/adhearsion/initializer/database.rb +3 -46
  41. data/lib/adhearsion/initializer/drb.rb +9 -3
  42. data/lib/adhearsion/initializer/freeswitch.rb +3 -3
  43. data/lib/adhearsion/initializer/rails.rb +1 -1
  44. data/lib/adhearsion/initializer.rb +213 -87
  45. data/lib/adhearsion/tasks/deprecations.rb +59 -0
  46. data/lib/adhearsion/tasks.rb +2 -1
  47. data/lib/adhearsion/version.rb +3 -3
  48. data/lib/adhearsion/voip/asterisk/agi_server.rb +6 -6
  49. data/lib/adhearsion/voip/asterisk/commands.rb +100 -2
  50. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
  51. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
  52. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
  53. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
  54. data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
  55. data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
  56. data/lib/adhearsion/voip/asterisk.rb +1 -8
  57. data/lib/adhearsion/voip/call.rb +5 -1
  58. data/lib/adhearsion/voip/dial_plan.rb +74 -61
  59. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
  60. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
  61. data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
  62. data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
  63. data/lib/adhearsion.rb +16 -11
  64. data/lib/theatre/README.markdown +64 -0
  65. data/lib/theatre/callback_definition_loader.rb +84 -0
  66. data/lib/theatre/guid.rb +23 -0
  67. data/lib/theatre/invocation.rb +121 -0
  68. data/lib/theatre/namespace_manager.rb +153 -0
  69. data/lib/theatre/version.rb +2 -0
  70. data/lib/theatre.rb +151 -0
  71. metadata +60 -147
  72. data/Manifest.txt +0 -151
  73. data/README.txt +0 -5
  74. data/ahn_generators/component/USAGE +0 -5
  75. data/ahn_generators/component/component_generator.rb +0 -57
  76. data/ahn_generators/component/templates/configuration.rb +0 -0
  77. data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
  78. data/ahn_generators/component/templates/test/test.rb.erb +0 -12
  79. data/ahn_generators/component/templates/test/test_helper.rb +0 -14
  80. data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
  81. data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
  82. data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
  83. data/lib/adhearsion/core_extensions/array.rb +0 -0
  84. data/lib/adhearsion/core_extensions/guid.rb +0 -5
  85. data/lib/adhearsion/core_extensions/hash.rb +0 -0
  86. data/lib/adhearsion/core_extensions/numeric.rb +0 -4
  87. data/lib/adhearsion/core_extensions/proc.rb +0 -0
  88. data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
  89. data/lib/adhearsion/core_extensions/publishable.rb +0 -73
  90. data/lib/adhearsion/core_extensions/string.rb +0 -26
  91. data/lib/adhearsion/core_extensions/thread.rb +0 -13
  92. data/lib/adhearsion/core_extensions/time.rb +0 -0
  93. data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
  94. data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
  95. data/lib/adhearsion/distributed/gateways/rest_gateway.rb +0 -9
  96. data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
  97. data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
  98. data/lib/adhearsion/distributed/peer_finder.rb +0 -0
  99. data/lib/adhearsion/distributed/remote_cli.rb +0 -0
  100. data/lib/adhearsion/hooks.rb +0 -57
  101. data/lib/adhearsion/initializer/paths.rb +0 -55
  102. data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
  103. data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
  104. data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
  105. data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
  106. data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
  107. data/spec/fixtures/dialplan.rb +0 -3
  108. data/spec/initializer/test_configuration.rb +0 -267
  109. data/spec/initializer/test_loading.rb +0 -162
  110. data/spec/initializer/test_paths.rb +0 -43
  111. data/spec/sample.rb +0 -9
  112. data/spec/silence.rb +0 -10
  113. data/spec/test_ahn_command.rb +0 -149
  114. data/spec/test_code_quality.rb +0 -87
  115. data/spec/test_component_manager.rb +0 -97
  116. data/spec/test_constants.rb +0 -8
  117. data/spec/test_drb.rb +0 -104
  118. data/spec/test_events.rb +0 -136
  119. data/spec/test_helper.rb +0 -106
  120. data/spec/test_hooks.rb +0 -15
  121. data/spec/test_host_definitions.rb +0 -79
  122. data/spec/test_initialization.rb +0 -124
  123. data/spec/test_logging.rb +0 -80
  124. data/spec/test_relationship_properties.rb +0 -54
  125. data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
  126. data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
  127. data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
  128. data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
  129. data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
  130. data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
  131. data/spec/voip/asterisk/mock_ami_server.rb +0 -176
  132. data/spec/voip/asterisk/test_agi_server.rb +0 -453
  133. data/spec/voip/asterisk/test_ami.rb +0 -227
  134. data/spec/voip/asterisk/test_commands.rb +0 -2006
  135. data/spec/voip/asterisk/test_config_manager.rb +0 -129
  136. data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
  137. data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
  138. data/spec/voip/dsl/test_dispatcher.rb +0 -82
  139. data/spec/voip/dsl/test_parser.rb +0 -87
  140. data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
  141. data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
  142. data/spec/voip/freeswitch/test_oes_server.rb +0 -9
  143. data/spec/voip/test_call_routing.rb +0 -127
  144. data/spec/voip/test_dialplan_manager.rb +0 -442
  145. data/spec/voip/test_numerical_string.rb +0 -48
  146. data/spec/voip/test_phone_number.rb +0 -36
  147. data/test/test_ahn_generator.rb +0 -59
  148. data/test/test_component_generator.rb +0 -52
  149. data/test/test_generator_helper.rb +0 -20
@@ -1,9 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../test_helper"
2
- require File.dirname(__FILE__) + "/../dsl/dispatcher_spec_helper"
3
- require 'adhearsion/voip/freeswitch/oes_server'
4
-
5
-
6
- describe "Adhearsion::VoIP::FreeSwitch::OesServer::OesDispatcher" do
7
- include StandardDispatcherBehavior
8
- setup { @dispatcher_class = Adhearsion::VoIP::FreeSwitch::OesServer::OesDispatcher }
9
- end
@@ -1,127 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
-
3
- context "Call routing rule generation" do
4
- include CallRoutingTestHelper
5
-
6
- attr_reader :provider_one, :provider_two, :patterns
7
-
8
- setup do
9
- @provider_one = provider_named(:one)
10
- @provider_two = provider_named(:two)
11
- @patterns = [/pattern/, /does not/, /matter/]
12
- end
13
-
14
- test "specifying a single pattern routed to a single provider properly stores that pattern and its provider in the generated route rule" do
15
- pattern = %r(does not matter)
16
- rule = route(pattern, :to => provider_one)
17
- rule.patterns.should.equal [pattern]
18
- rule.providers.should.equal [provider_one]
19
- end
20
-
21
- test "specifying multiple patterns routed to a single provider stores all of them in the generated route rule" do
22
- first, second, third = patterns
23
- rule = route(first, second, third, :to => provider_one)
24
- rule.patterns.should.equal [*patterns]
25
- rule.providers.should.equal [provider_one]
26
- end
27
-
28
- test "specifying multiple patterns routed to multiple providers stores all of them in the generated route rule, listing providers in the ordered specified" do
29
- first, second, third = patterns
30
- rule = route(first, second, third, :to => [provider_one, provider_two])
31
- rule.patterns.should.equal [*patterns]
32
- rule.providers.should.equal [provider_one, provider_two]
33
- end
34
- end
35
-
36
- context "Route calculation" do
37
- include CallRoutingTestHelper
38
- attr_reader :provider_one, :provider_two
39
-
40
- setup do
41
- rules.clear
42
- @provider_one = provider_named(:one)
43
- @provider_two = provider_named(:two)
44
- end
45
-
46
- test "Defining a rule adds it to the router rules" do
47
- provider = provider_one
48
- pattern = /123/
49
- define_rules do
50
- route pattern, :to => provider
51
- end
52
- rules.size.should.equal 1
53
- rule = rules.first
54
- rule.providers.should.equal [provider]
55
- rule.patterns.should.equal [pattern]
56
- end
57
-
58
- test "Definiting multiple rules adds them to the router rules" do
59
- provider_for_rule_1 = provider_one
60
- provider_for_rule_2 = provider_two
61
- pattern_for_rule_1 = /123/
62
- pattern_for_rule_2 = /987/
63
-
64
- define_rules do
65
- route pattern_for_rule_1, :to => provider_for_rule_1
66
- route pattern_for_rule_2, :to => provider_for_rule_2
67
- end
68
-
69
- rules.size.should.equal 2
70
-
71
- rule_1 = rules.first
72
- rule_1.providers.should.equal [provider_for_rule_1]
73
- rule_1.patterns.should.equal [pattern_for_rule_1]
74
-
75
- rule_2 = rules.last
76
- rule_2.providers.should.equal [provider_for_rule_2]
77
- rule_2.patterns.should.equal [pattern_for_rule_2]
78
- end
79
-
80
- test "Provider is found in the simplest case of having only one pattern and one provider" do
81
- target_provider = provider_one
82
- define_rules do
83
- route /123/, :to => target_provider
84
- end
85
- calculate_route_for(1234).should.equal [target_provider]
86
- end
87
-
88
- test "Provider is found when the specified pattern matches a rule that is not the first rule" do
89
- provider_for_rule_1 = provider_one
90
- provider_for_rule_2 = provider_two
91
- pattern_for_rule_1 = /123/
92
- pattern_for_rule_2 = /987/
93
-
94
- define_rules do
95
- route pattern_for_rule_1, :to => provider_for_rule_1
96
- route pattern_for_rule_2, :to => provider_for_rule_2
97
- end
98
-
99
- target_provider = provider_for_rule_2
100
- calculate_route_for(9876).should.equal [target_provider]
101
- end
102
- end
103
-
104
- BEGIN {
105
- module CallRoutingTestHelper
106
- private
107
- def route(*args, &block)
108
- Adhearsion::VoIP::CallRouting::Rule.new(*args, &block)
109
- end
110
-
111
- def provider_named(name)
112
- Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(name)
113
- end
114
-
115
- def define_rules(&block)
116
- Adhearsion::VoIP::CallRouting::Router.define(&block)
117
- end
118
-
119
- def calculate_route_for(end_point)
120
- Adhearsion::VoIP::CallRouting::Router.calculate_route_for(end_point)
121
- end
122
-
123
- def rules
124
- Adhearsion::VoIP::CallRouting::Router.rules
125
- end
126
- end
127
- }
@@ -1,442 +0,0 @@
1
- require File.dirname(__FILE__) + "/../test_helper"
2
- require 'adhearsion/voip/dsl/dialplan/parser'
3
-
4
- context "Dialplan::Manager handling" do
5
-
6
- include DialplanTestingHelper
7
-
8
- attr_accessor :manager, :call, :context_name, :mock_context
9
-
10
- before do
11
- @context_name = :some_context_name
12
- @mock_context = flexmock('a context')
13
-
14
- hack_to_work_around_parser_coupling
15
- mock_dial_plan_lookup_for_context_name
16
- flexmock(Adhearsion::DialPlan::Loader).should_receive(:load_dial_plan).and_return{flexmock("loaded contexts", :contexts => nil)}
17
- @manager = Adhearsion::DialPlan::Manager.new
18
- @call = new_call_for_context context_name
19
-
20
- # Sanity check context name being set
21
- call.context.should.equal context_name
22
- end
23
-
24
- test "Given a Call, the manager finds the call's desired entry point/context" do
25
- manager.entry_point_for(call).should.equal mock_context
26
- end
27
-
28
- test "The manager handles a call by executing the proper context" do
29
- flexmock(Adhearsion::DialPlan::ExecutionEnvironment).new_instances.should_receive(:run).once
30
- manager.handle(call)
31
- end
32
-
33
- test "should raise a NoContextError exception if the targeted context is not found" do
34
- the_following_code {
35
- flexmock(manager).should_receive(:entry_point_for).and_return nil
36
- manager.handle call
37
- }.should.raise(Adhearsion::DialPlan::Manager::NoContextError)
38
- end
39
-
40
- test 'should send :answer to the execution environment if Adhearsion::AHN_CONFIG.automatically_answer_incoming_calls is set' do
41
- mock_ahn_config = flexmock 'a mock of the Adhearsion::Configuration object that is normally set when an app is initialized'
42
- mock_ahn_config.should_receive(:automatically_answer_incoming_calls).once.and_return true
43
- flexmock(Adhearsion::Configuration).should_receive(:new).once.and_return(mock_ahn_config)
44
- flexmock(Adhearsion::DialPlan::ExecutionEnvironment).new_instances.should_receive(:answer).once.and_throw :answered_call!
45
- Adhearsion::Configuration.configure
46
- the_following_code {
47
- manager.handle(call)
48
- }.should.throw :answered_call!
49
- end
50
-
51
- test 'should not send :answer to the executuon environment if Adhearsion::AHN_CONFIG.automatically_answer_incoming_calls is NOT set' do
52
-
53
- mock_ahn_config = flexmock 'a mock of the Adhearsion::Configuration object that is normally set when an app is initialized'
54
- mock_ahn_config.should_receive(:automatically_answer_incoming_calls).once.and_return false
55
-
56
- entry_point = Adhearsion::DialPlan::DialplanContextProc.new(:does_not_matter) {}
57
- flexmock(manager).should_receive(:entry_point_for).once.with(call).and_return(entry_point)
58
-
59
- flexmock(Adhearsion::Configuration).should_receive(:new).once.and_return(mock_ahn_config)
60
- flexmock(Adhearsion::DialPlan::ExecutionEnvironment).new_instances.should_receive(:entry_point).and_return entry_point
61
- flexmock(Adhearsion::DialPlan::ExecutionEnvironment).new_instances.should_receive(:answer).never
62
- flexmock(Adhearsion::DialPlan::ExecutionEnvironment).new_instances.should_receive(:instance_eval).and_throw :doing_dialplan
63
-
64
- Adhearsion::Configuration.configure
65
- manager.handle(call)
66
- end
67
-
68
- private
69
- def hack_to_work_around_parser_coupling
70
- flexmock(Adhearsion::Paths).should_receive(:manager_for?).and_return(true)
71
- flexmock(Adhearsion::VoIP::DSL::Dialplan::DialplanParser).should_receive(:all_dialplans).and_return([])
72
- end
73
-
74
- def mock_dial_plan_lookup_for_context_name
75
- flexmock(Adhearsion::DialPlan).new_instances.should_receive(:lookup).with(context_name).and_return(mock_context)
76
- end
77
- end
78
-
79
- context "DialPlan::Manager's handling a failed call" do
80
-
81
- include DialplanTestingHelper
82
-
83
- test 'should check if the call has failed and then instruct it to extract the reason from the environment' do
84
- flexmock(Adhearsion::DialPlan::ExecutionEnvironment).new_instances.should_receive(:variable).with("REASON").once.and_return '3'
85
- call = Adhearsion::Call.new(nil, {'extension' => "failed"})
86
- call.should.be.failed_call
87
- flexmock(Adhearsion::DialPlan).should_receive(:new).once.and_return flexmock("bogus DialPlan which should never be used")
88
- begin
89
- Adhearsion::DialPlan::Manager.handle(call)
90
- rescue Adhearsion::FailedExtensionCallException => error
91
- error.call.failed_reason.should == Adhearsion::Call::ASTERISK_FRAME_STATES[3]
92
- end
93
- end
94
- end
95
-
96
- context "Call tagging" do
97
-
98
- include DialplanTestingHelper
99
-
100
- after :all do
101
- Adhearsion.active_calls.clear!
102
- end
103
-
104
- test 'tagging a call with a single Symbol' do
105
- the_following_code {
106
- call = new_call_for_context "roflcopter"
107
- call.tag :moderator
108
- }.should.not.raise
109
- end
110
-
111
- test 'tagging a call with multiple Symbols' do
112
- the_following_code {
113
- call = new_call_for_context "roflcopter"
114
- call.tag :moderator
115
- call.tag :female
116
- }.should.not.raise
117
- end
118
-
119
- test 'Call#tagged_with? with one tag' do
120
- call = new_call_for_context "roflcopter"
121
- call.tag :guest
122
- call.tagged_with?(:guest).should.equal true
123
- call.tagged_with?(:authorized).should.equal false
124
- end
125
-
126
- test "Call#remove_tag" do
127
- call = new_call_for_context "roflcopter"
128
- call.tag :moderator
129
- call.tag :female
130
- call.remove_tag :female
131
- call.tag :male
132
- call.tags.should == [:moderator, :male]
133
- end
134
-
135
- test 'Call#tagged_with? with many tags' do
136
- call = new_call_for_context "roflcopter"
137
- call.tag :customer
138
- call.tag :authorized
139
- call.tagged_with?(:customer).should.equal true
140
- call.tagged_with?(:authorized).should.equal true
141
- end
142
-
143
- test 'tagging a call with a non-Symbol object' do
144
- bad_objects = ["moderator", 123, Object.new, 888.88, nil, true, false, StringIO.new]
145
- bad_objects.each do |bad_object|
146
- the_following_code {
147
- new_call_for_context("roflcopter").tag bad_object
148
- }.should.raise ArgumentError
149
- end
150
- end
151
-
152
- test "finding calls by a tag" do
153
- Adhearsion.active_calls.clear!
154
-
155
- calls = Array.new(5) { new_call_for_context "roflcopter" }
156
- calls.each { |call| Adhearsion.active_calls << call }
157
-
158
- tagged_call = calls.last
159
- tagged_call.tag :moderator
160
-
161
- Adhearsion.active_calls.with_tag(:moderator).should == [tagged_call]
162
- end
163
-
164
- end
165
-
166
- context "DialPlan::Manager's handling a hungup call" do
167
-
168
- include DialplanTestingHelper
169
-
170
- test 'should check if the call was a hangup meta-AGI call and then raise a HangupExtensionCallException' do
171
- call = Adhearsion::Call.new(nil, {'extension' => "h"})
172
- call.should.be.hungup_call
173
- flexmock(Adhearsion::DialPlan).should_receive(:new).once.and_return flexmock("bogus DialPlan which should never be used")
174
- the_following_code {
175
- Adhearsion::DialPlan::Manager.handle(call)
176
- }.should.raise Adhearsion::HungupExtensionCallException
177
- end
178
-
179
- end
180
-
181
- context "DialPlan" do
182
-
183
- attr_accessor :loader, :loader_instance, :dial_plan
184
-
185
- before do
186
- @loader = Adhearsion::DialPlan::Loader
187
- @loader_instance = @loader.new
188
- flexmock(Adhearsion::DialPlan::Loader).should_receive(:load_dial_plan).once.and_return(@loader_instance)
189
- @dial_plan = Adhearsion::DialPlan.new(Adhearsion::DialPlan::Loader)
190
- end
191
-
192
- test "When a dial plan is instantiated, the dialplans are loaded and stored for lookup" do
193
- dial_plan.instance_variable_get("@entry_points").should.not.be.nil
194
- end
195
-
196
- test "Can look up an entry point from a dial plan" do
197
- context_name = 'this_context_is_better_than_your_context'
198
- loader_instance.contexts[context_name] = lambda { puts "o hai" }
199
- dial_plan.lookup(context_name).should.not.be.nil
200
- end
201
- end
202
-
203
- context "DialPlan loader" do
204
-
205
- include DialplanTestingHelper
206
-
207
- test "loading a single context" do
208
- loader = load(<<-DIAL_PLAN)
209
- one {
210
- raise 'this block should not be evaluated'
211
- }
212
- DIAL_PLAN
213
-
214
- loader.contexts.keys.size.should.equal 1
215
- loader.contexts.keys.first.should.equal :one
216
- end
217
-
218
- test "loading multiple contexts loads all contexts" do
219
- loader = load(<<-DIAL_PLAN)
220
- one {
221
- raise 'this block should not be evaluated'
222
- }
223
-
224
- two {
225
- raise 'this other block should not be evaluated either'
226
- }
227
- DIAL_PLAN
228
-
229
- loader.contexts.keys.size.should.equal 2
230
- loader.contexts.keys.map(&:to_s).sort.should.equal %w(one two)
231
- end
232
-
233
- test 'loading a dialplan with a syntax error' do
234
- the_following_code {
235
- load "foo { &@(*!&(*@*!@^!^%@%^! }"
236
- }.should.raise SyntaxError
237
- end
238
-
239
- test "loading a dial plan from a file" do
240
- loader = nil
241
- the_following_code {
242
- AHN_ROOT.using_base_path(File.expand_path(File.dirname(__FILE__) + '/../fixtures')) do
243
- loader = Adhearsion::DialPlan::Loader.load_dial_plan
244
- end
245
- }.should.not.raise
246
-
247
- loader.contexts.keys.size.should.equal 1
248
- loader.contexts.keys.first.should.equal :sample_context
249
- end
250
-
251
- end
252
-
253
- context "The inbox-related dialplan methods" do
254
-
255
- include DialplanTestingHelper
256
-
257
- test "with_next_message should execute its block with the message from the inbox" do
258
- mock_call = new_call_for_context :entrance
259
- [:one, :two, :three].each { |message| mock_call.inbox << message }
260
-
261
- dialplan = %{ entrance { with_next_message { |message| throw message } } }
262
- executing_dialplan(:entrance => dialplan, :call => mock_call).should.throw :one
263
- end
264
-
265
-
266
- test "messages_waiting? should return false if the inbox is empty" do
267
- mock_call = new_call_for_context :entrance
268
- dialplan = %{ entrance { throw messages_waiting? ? :yes : :no } }
269
- executing_dialplan(:entrance => dialplan, :call => mock_call).should.throw :no
270
- end
271
-
272
- test "messages_waiting? should return false if the inbox is not empty" do
273
- mock_call = new_call_for_context :entrance
274
- mock_call.inbox << Object.new
275
- dialplan = %{ entrance { throw messages_waiting? ? :yes : :no } }
276
- executing_dialplan(:entrance => dialplan, :call => mock_call).should.throw :yes
277
- end
278
-
279
- end
280
-
281
-
282
- context "ExecutionEnvironemnt" do
283
- attr_accessor :call, :entry_point
284
-
285
- include DialplanTestingHelper
286
-
287
- before do
288
- variables = { :context => "zomgzlols", :caller_id => "Ponce de Leon" }
289
- @call = Adhearsion::Call.new(nil, variables)
290
- @entry_point = lambda {}
291
- end
292
-
293
- test "On initialization, ExecutionEnvironments extend themselves with behavior specific to the voip platform which originated the call" do
294
- Adhearsion::DialPlan::ExecutionEnvironment.included_modules.should.not.include(Adhearsion::VoIP::Asterisk::Commands)
295
- execution_environent = Adhearsion::DialPlan::ExecutionEnvironment.new(call, entry_point)
296
- execution_environent.metaclass.included_modules.should.include(Adhearsion::VoIP::Asterisk::Commands)
297
- end
298
-
299
- test "An executed context should raise a NameError error when a missing constant is referenced" do
300
- the_following_code do
301
- call = new_call_for_context :context_with_missing_constant
302
- mock_dialplan_with "context_with_missing_constant { ThisConstantDoesntExist }"
303
- manager = new_manager_with_entry_points_loaded_from_dialplan_contexts
304
- manager.handle call
305
- end.should.raise NameError
306
-
307
- end
308
-
309
- test "should define variables accessors within itself" do
310
- environment = Adhearsion::DialPlan::ExecutionEnvironment.new(@call, entry_point)
311
- call.variables.should.not.be.empty
312
- call.variables.each do |key, value|
313
- environment.send(key).should.equal value
314
- end
315
- end
316
-
317
- test "should define accessors for other contexts in the dialplan" do
318
- call = new_call_for_context :am_not_for_kokoa!
319
- bogus_dialplan = <<-DIALPLAN
320
- am_not_for_kokoa! {}
321
- icanhascheezburger? {}
322
- these_context_names_do_not_really_matter {}
323
- DIALPLAN
324
-
325
- mock_dialplan_with bogus_dialplan
326
- manager = Adhearsion::DialPlan::Manager.new
327
- manager.dial_plan.entry_points = manager.dial_plan.loader.load_dial_plan.contexts
328
- manager.dial_plan.entry_points.should.not.be.empty
329
-
330
- manager.handle call
331
-
332
- %w(these_context_names_do_not_really_matter icanhascheezburger? am_not_for_kokoa!).each do |context_name|
333
- manager.context.respond_to?(context_name).should.equal true
334
- end
335
- end
336
-
337
- end
338
-
339
- context "Dialplan control statements" do
340
-
341
- include DialplanTestingHelper
342
-
343
- test "Manager should catch ControlPassingExceptions" do
344
- dialplan = %{
345
- foo { raise Adhearsion::VoIP::DSL::Dialplan::ControlPassingException.new(bar) }
346
- bar {}
347
- }
348
- executing_dialplan(:foo => dialplan).should.not.raise
349
- end
350
-
351
- test "Proc#+@ should not return to its originating context" do
352
- dialplan = %{
353
- andere {}
354
- zuerst {
355
- +andere
356
- throw :after_control_statement
357
- }
358
- }
359
- executing_dialplan(:zuerst => dialplan).should.not.throw
360
- end
361
- test "All dialplan contexts should be available at context execution time" do
362
- dialplan = %{
363
- context_defined_first {
364
- throw :i_see_it if context_defined_second
365
- }
366
- context_defined_second {}
367
- }
368
- executing_dialplan(:context_defined_first => dialplan).should.throw :i_see_it
369
- end
370
- test "Proc#+@ should execute the other context" do
371
- dialplan = %{
372
- eins {
373
- +zwei
374
- throw :eins
375
- }
376
- zwei {
377
- throw :zwei
378
- }
379
- }
380
- executing_dialplan(:eins => dialplan).should.throw :zwei
381
- end
382
-
383
- test "new constants should still be accessible within the dialplan" do
384
- ::Jicksta = :Jicksta
385
- dialplan = %{
386
- constant_test {
387
- Jicksta.should.equal:Jicksta
388
- }
389
- }
390
- executing_dialplan(:constant_test => dialplan).should.not.raise
391
- end
392
-
393
- end
394
-
395
- context "VoIP platform operations" do
396
- test "can map a platform name to a module which holds its platform-specific operations" do
397
- Adhearsion::VoIP::Commands.for(:asterisk).should == Adhearsion::VoIP::Asterisk::Commands
398
- end
399
- end
400
-
401
- context 'ContextNameCollector' do
402
- test '::build should raise a SyntaxError when the dialplan String contains one' do
403
- the_following_code {
404
- Adhearsion::DialPlan::Loader::ContextNameCollector.build "foo { ((((( *@!^*@&*^!^@ }"
405
- }.should.raise SyntaxError
406
- end
407
- end
408
-
409
- BEGIN {
410
- module DialplanTestingHelper
411
- def load(dial_plan_as_string)
412
- Adhearsion::DialPlan::Loader.load(dial_plan_as_string)
413
- end
414
-
415
- def mock_dialplan_with(string)
416
- flexstub(Adhearsion::DialPlan::Loader).should_receive(:read_dialplan_file).and_return(string)
417
- end
418
-
419
- def new_manager_with_entry_points_loaded_from_dialplan_contexts
420
- returning Adhearsion::DialPlan::Manager.new do |manager|
421
- manager.dial_plan.entry_points = manager.dial_plan.loader.load_dial_plan.contexts
422
- end
423
- end
424
-
425
- def executing_dialplan(options)
426
- call = options.delete(:call)
427
- context_name = options.keys.first
428
- dialplan = options[context_name]
429
- call ||= new_call_for_context context_name
430
-
431
- mock_dialplan_with dialplan
432
- lambda do
433
- Adhearsion::DialPlan::Manager.new.handle call
434
- end
435
- end
436
-
437
- def new_call_for_context(context)
438
- Adhearsion::Call.new(StringIO.new, :context => context)
439
- end
440
- end
441
-
442
- }
@@ -1,48 +0,0 @@
1
- require File.dirname(__FILE__) + "/../test_helper"
2
-
3
- require 'adhearsion/voip/dsl/numerical_string'
4
- require 'adhearsion/voip/constants'
5
-
6
- context "A NumericalString" do
7
- test "NumericalString should appear to be behave like a Fixnum in a case statement" do
8
- assert 123 === numerical_string_for("123")
9
- assert 987 === numerical_string_for("0987")
10
- end
11
-
12
- test "NumericalString should appear to behave like a String in a case statement" do
13
- assert "123" === numerical_string_for("123")
14
- assert "0987" === numerical_string_for("0987")
15
- end
16
-
17
- test "when compared against a Range that contains the numeric equivalent, the NumericalString is seen as a member" do
18
- assert((100..200) === numerical_string_for("150"))
19
- assert((100..200) === numerical_string_for("0150"))
20
- assert !((100..200) === numerical_string_for("1000000"))
21
- end
22
-
23
- test "comparing against a regular expression works" do
24
- assert %r|^\d+$| === numerical_string_for("027316287")
25
- end
26
-
27
- test "checking if a string representation of a number starts with a leading zero" do
28
- with_leading_zeros = %w(01 01234 01.23 01.2)
29
- without_leading_zeros = %w(1 1.2 0 0.0)
30
-
31
- with_leading_zeros.each do |number|
32
- assert numerical_string.starts_with_leading_zero?(number), number
33
- end
34
-
35
- without_leading_zeros.each do |number|
36
- assert !numerical_string.starts_with_leading_zero?(number), number
37
- end
38
- end
39
-
40
- private
41
- def numerical_string
42
- Adhearsion::VoIP::DSL::NumericalString
43
- end
44
-
45
- def numerical_string_for(string)
46
- numerical_string.new(string)
47
- end
48
- end
@@ -1,36 +0,0 @@
1
- require File.dirname(__FILE__) + "/../test_helper"
2
- require 'adhearsion/voip/constants'
3
- require 'adhearsion/voip/dsl/numerical_string'
4
-
5
-
6
- # Use cases...
7
- # case extension
8
- # when US_NUMBER
9
- # when (100..200)
10
- # when _('12Z')
11
- # when 123
12
- # when "123"
13
- # end
14
-
15
- describe "A PhoneNumber" do
16
-
17
- it "should have an ISN pattern-matching method" do
18
- !! Adhearsion::VoIP::DSL::PhoneNumber.new("0115544332211").isn?.should == false
19
- !! Adhearsion::VoIP::DSL::PhoneNumber.new("1*548").isn?.should == false
20
- end
21
-
22
- it "should have a US local number pattern-matching method" do
23
- !! Adhearsion::VoIP::DSL::PhoneNumber.new("18887776665555").local_number?.should == false
24
- !! Adhearsion::VoIP::DSL::PhoneNumber.new("18887776665555").national_number?.should == false
25
-
26
- !! Adhearsion::VoIP::DSL::PhoneNumber.new("8887776665555").local_number?.should == false
27
- !! Adhearsion::VoIP::DSL::PhoneNumber.new("8887776665555").national_number?.should == true
28
-
29
- !! Adhearsion::VoIP::DSL::PhoneNumber.new("4445555").local_number?.should == true
30
- !! Adhearsion::VoIP::DSL::PhoneNumber.new("4445555").national_number?.should == false
31
- end
32
-
33
- it "should convert from vanity numbers properly" do
34
- Adhearsion::VoIP::DSL::PhoneNumber.from_vanity("1-800-FUDGEME").should == "18003834363"
35
- end
36
- end