eric-adhearsion 0.7.999 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/CHANGELOG +8 -2
  2. data/EVENTS +11 -0
  3. data/Rakefile +96 -24
  4. data/adhearsion.gemspec +148 -0
  5. data/app_generators/ahn/ahn_generator.rb +24 -9
  6. data/app_generators/ahn/templates/.ahnrc +25 -3
  7. data/app_generators/ahn/templates/Rakefile +22 -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 -0
  17. data/bin/jahn +10 -0
  18. data/examples/asterisk_manager_interface/standalone.rb +51 -0
  19. data/lib/adhearsion.rb +17 -11
  20. data/lib/adhearsion/cli.rb +141 -24
  21. data/lib/adhearsion/component_manager.rb +169 -238
  22. data/lib/adhearsion/component_manager/component_tester.rb +55 -0
  23. data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
  24. data/lib/adhearsion/events_support.rb +84 -0
  25. data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
  26. data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
  27. data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
  28. data/lib/adhearsion/foundation/event_socket.rb +203 -0
  29. data/lib/adhearsion/foundation/future_resource.rb +36 -0
  30. data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
  31. data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
  32. data/lib/adhearsion/foundation/numeric.rb +13 -0
  33. data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
  34. data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
  35. data/lib/adhearsion/foundation/string.rb +26 -0
  36. data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
  37. data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
  38. data/lib/adhearsion/host_definitions.rb +5 -1
  39. data/lib/adhearsion/initializer.rb +229 -73
  40. data/lib/adhearsion/initializer/asterisk.rb +33 -11
  41. data/lib/adhearsion/initializer/configuration.rb +58 -6
  42. data/lib/adhearsion/initializer/database.rb +3 -46
  43. data/lib/adhearsion/initializer/drb.rb +9 -3
  44. data/lib/adhearsion/initializer/freeswitch.rb +3 -3
  45. data/lib/adhearsion/initializer/rails.rb +1 -1
  46. data/lib/adhearsion/tasks.rb +2 -1
  47. data/lib/adhearsion/tasks/deprecations.rb +59 -0
  48. data/lib/adhearsion/version.rb +3 -3
  49. data/lib/adhearsion/voip/asterisk.rb +2 -2
  50. data/lib/adhearsion/voip/asterisk/agi_server.rb +9 -6
  51. data/lib/adhearsion/voip/asterisk/commands.rb +106 -4
  52. data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
  53. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
  54. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
  55. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
  56. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
  57. data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
  58. data/lib/adhearsion/voip/call.rb +51 -2
  59. data/lib/adhearsion/voip/dial_plan.rb +74 -61
  60. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
  61. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
  62. data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
  63. data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
  64. data/lib/theatre.rb +151 -0
  65. data/lib/theatre/README.markdown +64 -0
  66. data/lib/theatre/callback_definition_loader.rb +84 -0
  67. data/lib/theatre/guid.rb +23 -0
  68. data/lib/theatre/invocation.rb +121 -0
  69. data/lib/theatre/namespace_manager.rb +153 -0
  70. data/lib/theatre/version.rb +2 -0
  71. metadata +63 -138
  72. data/Manifest.txt +0 -149
  73. data/README.txt +0 -6
  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/services/scheduler.rb +0 -5
  103. data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
  104. data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
  105. data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
  106. data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
  107. data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
  108. data/script/destroy +0 -14
  109. data/script/generate +0 -14
  110. data/spec/fixtures/dialplan.rb +0 -3
  111. data/spec/initializer/test_configuration.rb +0 -267
  112. data/spec/initializer/test_loading.rb +0 -162
  113. data/spec/initializer/test_paths.rb +0 -43
  114. data/spec/silence.rb +0 -10
  115. data/spec/test_ahn_command.rb +0 -149
  116. data/spec/test_code_quality.rb +0 -87
  117. data/spec/test_component_manager.rb +0 -97
  118. data/spec/test_constants.rb +0 -8
  119. data/spec/test_drb.rb +0 -104
  120. data/spec/test_helper.rb +0 -94
  121. data/spec/test_hooks.rb +0 -37
  122. data/spec/test_host_definitions.rb +0 -79
  123. data/spec/test_initialization.rb +0 -105
  124. data/spec/test_logging.rb +0 -80
  125. data/spec/test_relationship_properties.rb +0 -54
  126. data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
  127. data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
  128. data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
  129. data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
  130. data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
  131. data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
  132. data/spec/voip/asterisk/mock_ami_server.rb +0 -176
  133. data/spec/voip/asterisk/test_agi_server.rb +0 -451
  134. data/spec/voip/asterisk/test_ami.rb +0 -227
  135. data/spec/voip/asterisk/test_commands.rb +0 -2006
  136. data/spec/voip/asterisk/test_config_manager.rb +0 -129
  137. data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
  138. data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
  139. data/spec/voip/dsl/test_dispatcher.rb +0 -82
  140. data/spec/voip/dsl/test_parser.rb +0 -87
  141. data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
  142. data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
  143. data/spec/voip/freeswitch/test_oes_server.rb +0 -9
  144. data/spec/voip/test_call_routing.rb +0 -127
  145. data/spec/voip/test_dialplan_manager.rb +0 -372
  146. data/spec/voip/test_numerical_string.rb +0 -48
  147. data/spec/voip/test_phone_number.rb +0 -36
  148. data/test/test_ahn_generator.rb +0 -59
  149. data/test/test_component_generator.rb +0 -52
  150. data/test/test_generator_helper.rb +0 -20
@@ -1,129 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../test_helper"
2
- require 'adhearsion/voip/asterisk/config_manager'
3
-
4
- context "The configuration file parser behavior" do
5
-
6
- include ConfigurationManagerTestHelper
7
-
8
- test "should expose a sections array" do
9
- manager = mock_config_manager
10
- manager.sections.map(&:first).should.equal(["jicksta", "picard"])
11
- end
12
-
13
- test "should ignore comments" do
14
- context_names = %w(monkey data)
15
- tested_key_name, tested_key_value_before_comment = "bar", "baz"
16
- manager = mock_config_manager_for <<-CONFIG
17
- [monkey]
18
- #{tested_key_name}=#{tested_key_value_before_comment};thiscommentshouldnotbehere
19
- asdf=fdsa
20
- ;[data]
21
- ;ignored=asdf
22
- CONFIG
23
- manager.sections.map(&:first).should.equal [context_names.first]
24
- manager[context_names.first].size.should.equal 2
25
- manager[context_names.first][tested_key_name].should.equal tested_key_value_before_comment
26
- end
27
-
28
- test "should match context names with dashes and underscores" do
29
- context_names = %w"foo-bar qaz_b-a-z"
30
- definition_string = <<-CONFIG
31
- [#{context_names.first}]
32
- platypus=no
33
- zebra=no
34
- crappyconfig=yes
35
-
36
- [#{context_names.last}]
37
- callerid="Jay Phillips" <133>
38
- CONFIG
39
- mock_config_manager_for(definition_string).sections.map(&:first).should.equal context_names
40
- end
41
-
42
- test "should strip whitespace around keys and values" do
43
- section_name = "hey-there-hot-momma"
44
- tested_key_name, tested_key_value_before_comment = "bar", "i heart white space. SIKE!"
45
- config_manager = mock_config_manager_for <<-CONFIG
46
- \t[#{section_name}]
47
-
48
- thereis = a lot of whitespace after these
49
-
50
- #{tested_key_name} = \t\t\t #{tested_key_value_before_comment}
51
-
52
- CONFIG
53
- config_manager[section_name][tested_key_name].should.equal tested_key_value_before_comment
54
- end
55
-
56
- test "should return a Hash of properties when searching for an existing section" do
57
- result = mock_config_manager["jicksta"]
58
- result.should.be.kind_of Hash
59
- result.size.should.equal 3
60
- end
61
-
62
- test "should return nil when searching for a non-existant section" do
63
- mock_config_manager["i-so-dont-exist-dude"].should.be.nil
64
- end
65
-
66
- end
67
-
68
- context "The configuration file writer" do
69
-
70
- include ConfigurationManagerTestHelper
71
-
72
- attr_reader :config_manager
73
-
74
- setup do
75
- @config_manager = mock_config_manager
76
- end
77
-
78
- test "should remove an old section when replacing it" do
79
- config_manager.delete_section "picard"
80
- config_manager.sections.map(&:first).should.equal ["jicksta"]
81
- end
82
-
83
- test "should add a new section to the end" do
84
- section_name = "wittynamehere"
85
- config_manager.new_section(section_name, :type => "friend",
86
- :witty => "yes",
87
- :shaken => "yes",
88
- :stirred => "no")
89
- new_section = config_manager.sections.last
90
- new_section.first.should.equal section_name
91
- new_section.last.size.should.equal 4
92
- end
93
- end
94
-
95
- context "The configuration file generator" do
96
- end
97
-
98
- BEGIN {
99
- module ConfigurationManagerTestHelper
100
-
101
- def mock_config_manager
102
- mock_config_manager_for sample_standard_config
103
- end
104
-
105
- def mock_config_manager_for(config_string)
106
- returning new_config_manager_with("bogus filename") do |manager|
107
- flexmock(manager).should_receive(:execute).and_return(config_string)
108
- end
109
- end
110
-
111
- def new_config_manager_with(filename)
112
- Adhearsion::VoIP::Asterisk::ConfigurationManager.new(filename)
113
- end
114
-
115
- def sample_standard_config
116
- <<-CONFIG
117
- [jicksta]
118
- foo=bar
119
- qaz=qwerty
120
- baz=zxcvb
121
- [picard]
122
- type=friend
123
- insecure=very
124
- host=dynamic
125
- secret=blargh
126
- CONFIG
127
- end
128
- end
129
- }
@@ -1,45 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
-
3
- require 'adhearsion/voip/dsl/dialplan/dispatcher'
4
-
5
- module StandardDispatcherBehavior
6
- def xtest_standard_dispatcher_behavior
7
- #"This test looks bogus. Not finished? Let's not check in failing specs ever if we can help it."
8
- returned_event_command = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "ilikesexypants"
9
- linking_event_command = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "ihavesexypants" do
10
- returned_event_command
11
- end
12
-
13
- dispatcher = @dispatcher_class.new MyFactory
14
- dispatcher.should_receive(:dispatch!).with(linking_event_command, returned_event_command).and_return(linking_event_command, returned_event_command)
15
- # returned_event_command.should_receive(:command_block).and_return nil
16
- dispatcher.dispatch! linking_event_command
17
- end
18
- end
19
-
20
- class NilDispatcher < Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher
21
- def dispatch!(string)
22
- # Would send it off to the PBX here (or prepend something to the String)
23
- end
24
- end
25
-
26
- class EvalDispatcher < Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher
27
- def dispatch!(event)
28
- eval event.app.to_s
29
- end
30
- end
31
-
32
- class MyFactory
33
-
34
- def initialize(context)
35
- @context = context
36
- end
37
-
38
- def sequence
39
- all = []
40
- EventCommand.new("2", :response => Numeric) do |response|
41
- all << response
42
- all.size > 3 ? all : nil
43
- end
44
- end
45
- end
@@ -1,268 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
2
- require 'adhearsion/voip/dsl/dialing_dsl'
3
-
4
- # Keep the monkey patches in a module and load that into Regexp
5
- # eigenclasses during a before(:all) block?
6
-
7
- describe "RouteRule Regexp assembling" do
8
-
9
- test "should compile two Regexps" do
10
- first, last = /jay/, /phillips/
11
- r = first | last
12
- r.patterns.should == [first, last]
13
- end
14
-
15
- test "should compile three or more Regexps" do
16
- first, second, third = /lorem/, /ipsum/, /dolar/
17
- r = first | second | third
18
- r.patterns.should == [first, second, third]
19
- end
20
-
21
- end
22
-
23
- describe "RouteRule assembling with one provider definition" do
24
-
25
- before :each do
26
- @provider = Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:icanhascheezburger?)
27
- end
28
-
29
- test "should store one pattern properly" do
30
- pattern = /lorem/
31
- route = pattern >> @provider
32
- route.patterns.should == [pattern]
33
- end
34
-
35
- test "should store three patterns properly" do
36
- first, second, third = /lorem/, /ipsum/, /dolar/
37
- route = first | second | third >> @provider
38
- route.patterns.should == [first, second, third]
39
- route.providers.should == [@provider]
40
- end
41
-
42
- end
43
-
44
- describe "RouteRule assembling with multiple patterns and multiple provider definitions" do
45
-
46
- before:each do
47
- 1.upto 3 do |i|
48
- instance_variable_set "@prov_#{i}",
49
- Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new("prov_#{i}")
50
- instance_variable_set "@pattern_#{i}", /^#{i * 100}$/
51
- end
52
- end
53
-
54
- test "should store the patterns properly" do
55
- route_1 = @pattern_1 | @pattern_2 | @pattern_3 >> @prov_1 >> @prov_2 >> @prov_3
56
- route_1.patterns.should == [@pattern_1, @pattern_2, @pattern_3]
57
-
58
- route_2 = @pattern_2 | @pattern_3 | @pattern_1 >> @prov_3 >> @prov_2 >> @prov_1
59
- route_2.patterns.should == [@pattern_2, @pattern_3, @pattern_1]
60
- end
61
-
62
- test "should store the providers properly" do
63
- route_1 = @pattern_1 | @pattern_2 | @pattern_3 >> @prov_1 >> @prov_2 >> @prov_3
64
- route_1.providers.should == [@prov_1, @prov_2, @prov_3]
65
-
66
- route_2 = @pattern_2 | @pattern_3 | @pattern_1 >> @prov_3 >> @prov_2 >> @prov_1
67
- route_2.patterns.should == [@pattern_2, @pattern_3, @pattern_1]
68
- end
69
- end
70
-
71
- describe "The DialingDSL class internals" do
72
-
73
- test "should allow Asterisk-like patterns" do
74
- Adhearsion::VoIP::DSL::DialingDSL.class_eval do
75
- _('23XX')
76
- end.should.be.instance_of Regexp
77
- end
78
-
79
- test "should define all of the VoIP constants" do
80
- lambda do
81
- Adhearsion::VoIP::Constants.constants.each do |constant|
82
- eval "Adhearsion::VoIP::DSL::DialingDSL::#{constant}"
83
- end
84
- end.should.not.raise NameError
85
- end
86
-
87
- # test "should define a DUNDI constant"
88
-
89
- test "should synchronize access to the trunking information for Thread safety"
90
-
91
- end
92
-
93
- describe "The provider DSL's 'provider' macro" do
94
-
95
- test "should make the providers available in the order they were received" do
96
- provider_holder = Class.new Adhearsion::VoIP::DSL::DialingDSL
97
- provider_holder.class_eval do
98
- provider(:tweedledee) {}
99
- provider(:tweedledum) {}
100
- end
101
- provider_holder.providers.map { |x| x.name }.should == [:tweedledee, :tweedledum]
102
- end
103
- test "should define a singleton method for the provider name given" do
104
- Class.new(Adhearsion::VoIP::DSL::DialingDSL).class_eval do
105
- class_variable_get(:@@providers).size.should == 0
106
-
107
- provider(:icanhascheezburger?) {}
108
-
109
- should.respond_to(:icanhascheezburger?)
110
- class_variable_get(:@@providers).size.should == 1
111
- end
112
- end
113
- test "should not define a class-wide method for the provider name given" do
114
- Class.new(Adhearsion::VoIP::DSL::DialingDSL).class_eval do
115
- provider(:icanhascheezburger?) {}
116
- end
117
- Adhearsion::VoIP::DSL::DialingDSL.class_eval do
118
- class_variable_defined?(:@@providers).should == false
119
- should.not.respond_to(:icanhascheezburger?)
120
- end
121
- end
122
- test "should yield a ProviderDefinition object" do
123
- possible_provider_definition = nil
124
- Class.new(Adhearsion::VoIP::DSL::DialingDSL).class_eval do
125
- provider(:blah) { |pd| possible_provider_definition = pd }
126
- end
127
- possible_provider_definition.should.be.a.kind_of(Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition)
128
- end
129
- test "should raise an error when no block is given" do
130
- the_following_code do
131
- Class.new(Adhearsion::VoIP::DSL::DialingDSL).class_eval do
132
- provider :explode
133
- end
134
- end.should.raise ArgumentError
135
- end
136
- end
137
-
138
- describe "The provider DSL's monkey patches to Regexp" do
139
- test "should return a RouteRule when using Regexp#| with another Regexp" do
140
- (// | //).should.be.a.kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
141
- end
142
- test "should return a RouteRule when chaining three Regexp's with the | operator" do
143
- (// | // | //).should.be.a.kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
144
- end
145
- test "should return a RouteRule when Regexp#| is given a RouteRule" do
146
- route_rule = Adhearsion::VoIP::DSL::DialingDSL::RouteRule.new :patterns => //
147
- (// | route_rule).should.be.a.kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
148
- end
149
- test "should return a RouteRule when Regexp#>> is given a ProviderDefinition" do
150
- (/1/ >> Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:foo)).
151
- should.be.a.kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
152
- end
153
- test "should return a RouteRule when Regexp#>>() receives a ProviderDefinition" do
154
- definition = Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:london)
155
- (/foo/ >> definition).should.be.a.kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
156
- end
157
- test "should raise an exception when Regexp#| receives something other than a RouteRule" do
158
- bad_args = [ 0..100, 20, 45.55, {}, [] ]
159
- bad_args.each do |arg|
160
- the_following_code { /foo/ | arg }.should.raise ArgumentError
161
- end
162
- end
163
- test "should raise an exception when Regexp#>>() receives anything other than a ProviderDefintion or RouteRule" do
164
- bad_args = [ 0..100, 20, 45.55, {}, [] ]
165
- bad_args.each do |arg|
166
- the_following_code { /foo/ >> arg }.should.raise ArgumentError
167
- end
168
- end
169
- end
170
-
171
- describe "A RouteRule" do
172
- test "should expose chained ProviderDefinitions properly" do
173
- one, two, three = definitions = %w"foo bar qaz".map do |name|
174
- Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new name
175
- end
176
- route = /^911$/ >> one >> two >> three
177
- route.should.be.kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
178
- route.providers.should == definitions
179
- end
180
- test "should define attr_readers for providers and patterns" do
181
- route = Adhearsion::VoIP::DSL::DialingDSL::RouteRule.new
182
- route.should.respond_to(:patterns)
183
- route.should.respond_to(:providers)
184
- end
185
- end
186
-
187
- describe "The provider order modifiers" do
188
- disabled_test "should support randomizing trunks" do
189
- dsl = Class.new Adhearsion::VoIP::DSL::DialingDSL
190
- dsl.class_eval do
191
- provider(:l33thost) {}
192
- provider(:h4xxhost) {}
193
- route /\d+\*548/ >> random(l33thost, h4xxhost)
194
- end
195
- dsl.routes.first.provider_definitions.first.should.be.a.kind_of(
196
- Adhearsion::VoIP::DSL::DialingDSL::RandomRouteRule
197
- )
198
- end
199
- end
200
-
201
- describe "The provider DSL's 'route' builder" do
202
- test "should register routes in the order received" do
203
- dsl = Class.new Adhearsion::VoIP::DSL::DialingDSL
204
- dsl.class_eval do
205
- provider(:kewlphone) {}
206
- [/1?4445556666/, /123/, /\d+\*548/].each do |r|
207
- route r >> kewlphone
208
- end
209
- end
210
- dsl.routes.map { |x| x.patterns }.flatten.should == [/1?4445556666/, /123/, /\d+\*548/]
211
- end
212
- end
213
-
214
- describe "A ProviderDefinition" do
215
- test "should store any arbitrary property" do
216
- definition = Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new :foo
217
- definition.qaz = :something
218
- definition.qaz.should == :something
219
- end
220
- test "should define a >>() method" do
221
- Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:arghh).should.respond_to(:>>)
222
- end
223
-
224
- test "should format numbers properly" do
225
- definition = Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:arghh)
226
- definition.protocol = "SIP"
227
- definition.format_number_for_platform("14445556666", :asterisk).should == "SIP/arghh/14445556666"
228
- definition.protocol = "SCCP"
229
- definition.format_number_for_platform("16663331111", :asterisk).should == "SCCP/arghh/16663331111"
230
-
231
- end
232
- end
233
-
234
- describe "Routing with the interpreted route definitions" do
235
- test "should use the first matching regular expression" do
236
- dsl = Class.new Adhearsion::VoIP::DSL::DialingDSL
237
- dsl.class_eval do
238
- provider(:bad) {}
239
- provider(:good) {}
240
- route /^111$/ | /^222$/ | /^333$/ >> good >> bad
241
- end
242
-
243
- found = dsl.calculate_routes_for(333)
244
-
245
- assert_equal 1, found.size
246
- found.first.size.should.equal 2
247
- end
248
-
249
- end
250
-
251
- # @example = Class.new Adhearsion::VoIP::DSL::DialingDSL
252
- # @example.class_eval do
253
- #
254
- # provider:kewlphone do |trunk|
255
- # trunk.protocol :sip
256
- # trunk.host "voip.nufone.com"
257
- # trunk.username "phonedude"
258
- # trunk.password "secret"
259
- # trunk.enters :internal
260
- # end
261
- #
262
- # route US_NUMBER | US_LOCAL_NUMBER >> voip_ms >> nufone
263
- #
264
- # route INTL_NUMBER >> random(voip_ms, nufone)
265
- #
266
- # # route _('NXX') >> DUNDI
267
- #
268
- # end
@@ -1,82 +0,0 @@
1
- require File.dirname(__FILE__) + '/dispatcher_spec_helper'
2
- require 'adhearsion/voip/dsl/dialplan/dispatcher'
3
-
4
-
5
- describe "A EventCommand" do
6
-
7
- test "should allow a block that's set to response_block()" do
8
- block = lambda {}
9
- cmd = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "foo", &block
10
- cmd.response_block.should.equal(block)
11
- end
12
-
13
- test "should return specified return type with returns()" do
14
- return_type = Numeric
15
- cmd = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "foo", :returns => return_type
16
- cmd.returns.should.equal(return_type)
17
- end
18
-
19
- end
20
-
21
- describe "The abstract CommandDispatcher" do
22
-
23
- test "should make an attribute reader for context()" do
24
- context = "foo"
25
- d = Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher.new String, context
26
- d.context.should.equal(context)
27
- end
28
-
29
- test "should instantiate a new instance of the specified factory" do
30
- d = Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher.new Hash
31
- d.factory.should.be.kind_of(Hash)
32
- end
33
-
34
- test "should pass the context to the factory when instantiating it" do
35
- context = "shazbot"
36
- klass = flexmock "a class that has one argument in its constructor"
37
- klass.should_receive(:new).with(context)
38
- d = Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher.new klass, context
39
- end
40
-
41
- test "should not allow calling dispatch!() directly" do
42
- dispatcher = Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher.new MyFactory
43
- lambda do
44
- dispatcher.dispatch! nil
45
- end.should.raise(NotImplementedError)
46
- end
47
-
48
- test "should pass a method and any args onto its CommandFactory" do
49
-
50
- weird_args = [1, 2, ["foo", nil], Object.new, 12.3..13.4]
51
-
52
- bogus_command = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "123"
53
-
54
- dispatcher = NilDispatcher.new MyFactory
55
- flexmock(dispatcher.factory).should_receive(:monkey).with(*weird_args).and_return bogus_command
56
- dispatcher.monkey(*weird_args)
57
-
58
- end
59
-
60
- test "should continue executing response_blocks until nil is returned" do
61
- actual_executions, target_executions = 0, 5
62
- response = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "1" do |response|
63
- if response > target_executions
64
- nil
65
- else
66
- actual_executions += 1
67
- Adhearsion::VoIP::DSL::Dialplan::EventCommand.new(response + 1)
68
- end
69
- end
70
- mock_factory_class = Class.new do
71
- def initialize(*args)
72
- end
73
- def testplz
74
- response
75
- end
76
- end
77
- dispatcher = EvalDispatcher.new(mock_factory_class)
78
- flexmock(dispatcher.factory).should_receive(:testplz).and_return(response)
79
- dispatcher.testplz
80
- actual_executions.should.equal(target_executions)
81
- end
82
- end