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.
- data/CHANGELOG +8 -2
- data/EVENTS +11 -0
- data/Rakefile +96 -24
- data/adhearsion.gemspec +148 -0
- data/app_generators/ahn/ahn_generator.rb +24 -9
- data/app_generators/ahn/templates/.ahnrc +25 -3
- data/app_generators/ahn/templates/Rakefile +22 -2
- data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
- data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
- data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
- data/app_generators/ahn/templates/config/startup.rb +3 -6
- data/app_generators/ahn/templates/dialplan.rb +2 -3
- data/app_generators/ahn/templates/events.rb +32 -0
- data/bin/jahn +10 -0
- data/examples/asterisk_manager_interface/standalone.rb +51 -0
- data/lib/adhearsion.rb +17 -11
- data/lib/adhearsion/cli.rb +141 -24
- data/lib/adhearsion/component_manager.rb +169 -238
- data/lib/adhearsion/component_manager/component_tester.rb +55 -0
- data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
- data/lib/adhearsion/events_support.rb +84 -0
- data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
- data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
- data/lib/adhearsion/foundation/event_socket.rb +203 -0
- data/lib/adhearsion/foundation/future_resource.rb +36 -0
- data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
- data/lib/adhearsion/foundation/numeric.rb +13 -0
- data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
- data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
- data/lib/adhearsion/foundation/string.rb +26 -0
- data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
- data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
- data/lib/adhearsion/host_definitions.rb +5 -1
- data/lib/adhearsion/initializer.rb +229 -73
- data/lib/adhearsion/initializer/asterisk.rb +33 -11
- data/lib/adhearsion/initializer/configuration.rb +58 -6
- data/lib/adhearsion/initializer/database.rb +3 -46
- data/lib/adhearsion/initializer/drb.rb +9 -3
- data/lib/adhearsion/initializer/freeswitch.rb +3 -3
- data/lib/adhearsion/initializer/rails.rb +1 -1
- data/lib/adhearsion/tasks.rb +2 -1
- data/lib/adhearsion/tasks/deprecations.rb +59 -0
- data/lib/adhearsion/version.rb +3 -3
- data/lib/adhearsion/voip/asterisk.rb +2 -2
- data/lib/adhearsion/voip/asterisk/agi_server.rb +9 -6
- data/lib/adhearsion/voip/asterisk/commands.rb +106 -4
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
- data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
- data/lib/adhearsion/voip/call.rb +51 -2
- data/lib/adhearsion/voip/dial_plan.rb +74 -61
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
- data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
- data/lib/theatre.rb +151 -0
- data/lib/theatre/README.markdown +64 -0
- data/lib/theatre/callback_definition_loader.rb +84 -0
- data/lib/theatre/guid.rb +23 -0
- data/lib/theatre/invocation.rb +121 -0
- data/lib/theatre/namespace_manager.rb +153 -0
- data/lib/theatre/version.rb +2 -0
- metadata +63 -138
- data/Manifest.txt +0 -149
- data/README.txt +0 -6
- data/ahn_generators/component/USAGE +0 -5
- data/ahn_generators/component/component_generator.rb +0 -57
- data/ahn_generators/component/templates/configuration.rb +0 -0
- data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
- data/ahn_generators/component/templates/test/test.rb.erb +0 -12
- data/ahn_generators/component/templates/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
- data/lib/adhearsion/core_extensions/array.rb +0 -0
- data/lib/adhearsion/core_extensions/guid.rb +0 -5
- data/lib/adhearsion/core_extensions/hash.rb +0 -0
- data/lib/adhearsion/core_extensions/numeric.rb +0 -4
- data/lib/adhearsion/core_extensions/proc.rb +0 -0
- data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
- data/lib/adhearsion/core_extensions/publishable.rb +0 -73
- data/lib/adhearsion/core_extensions/string.rb +0 -26
- data/lib/adhearsion/core_extensions/thread.rb +0 -13
- data/lib/adhearsion/core_extensions/time.rb +0 -0
- data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/rest_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
- data/lib/adhearsion/distributed/peer_finder.rb +0 -0
- data/lib/adhearsion/distributed/remote_cli.rb +0 -0
- data/lib/adhearsion/hooks.rb +0 -57
- data/lib/adhearsion/initializer/paths.rb +0 -55
- data/lib/adhearsion/services/scheduler.rb +0 -5
- data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
- data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
- data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
- data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
- data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/fixtures/dialplan.rb +0 -3
- data/spec/initializer/test_configuration.rb +0 -267
- data/spec/initializer/test_loading.rb +0 -162
- data/spec/initializer/test_paths.rb +0 -43
- data/spec/silence.rb +0 -10
- data/spec/test_ahn_command.rb +0 -149
- data/spec/test_code_quality.rb +0 -87
- data/spec/test_component_manager.rb +0 -97
- data/spec/test_constants.rb +0 -8
- data/spec/test_drb.rb +0 -104
- data/spec/test_helper.rb +0 -94
- data/spec/test_hooks.rb +0 -37
- data/spec/test_host_definitions.rb +0 -79
- data/spec/test_initialization.rb +0 -105
- data/spec/test_logging.rb +0 -80
- data/spec/test_relationship_properties.rb +0 -54
- data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
- data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
- data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
- data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
- data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
- data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
- data/spec/voip/asterisk/mock_ami_server.rb +0 -176
- data/spec/voip/asterisk/test_agi_server.rb +0 -451
- data/spec/voip/asterisk/test_ami.rb +0 -227
- data/spec/voip/asterisk/test_commands.rb +0 -2006
- data/spec/voip/asterisk/test_config_manager.rb +0 -129
- data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
- data/spec/voip/dsl/test_dispatcher.rb +0 -82
- data/spec/voip/dsl/test_parser.rb +0 -87
- data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_oes_server.rb +0 -9
- data/spec/voip/test_call_routing.rb +0 -127
- data/spec/voip/test_dialplan_manager.rb +0 -372
- data/spec/voip/test_numerical_string.rb +0 -48
- data/spec/voip/test_phone_number.rb +0 -36
- data/test/test_ahn_generator.rb +0 -59
- data/test/test_component_generator.rb +0 -52
- data/test/test_generator_helper.rb +0 -20
@@ -1,97 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/test_helper"
|
2
|
-
|
3
|
-
context "Adding call context to components" do
|
4
|
-
include CallContextComponentTestHelpers
|
5
|
-
|
6
|
-
attr_reader :sample_component
|
7
|
-
|
8
|
-
setup do
|
9
|
-
@sample_component = new_componenet_class_named(sample_component_name)
|
10
|
-
end
|
11
|
-
|
12
|
-
test "Component name is added to list of components that will have call contexts injected into them" do
|
13
|
-
components_with_call_context.should.be.empty
|
14
|
-
the_following_code {
|
15
|
-
sample_component.add_call_context
|
16
|
-
}.should.not.raise
|
17
|
-
|
18
|
-
components_with_call_context.should.not.be.empty
|
19
|
-
Adhearsion::ComponentManager.components_with_call_context[sample_component_name].component_class.should.equal sample_component
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
def components_with_call_context
|
24
|
-
Adhearsion::ComponentManager.components_with_call_context.keys
|
25
|
-
end
|
26
|
-
|
27
|
-
def sample_component_name
|
28
|
-
'SampleComponent'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "Referencing a component class in a dial plan context" do
|
33
|
-
include CallContextComponentTestHelpers
|
34
|
-
|
35
|
-
test "the class constant should be available in the scope of a call context" do
|
36
|
-
sample_component_class = new_componenet_class_named('SampleComponent2')
|
37
|
-
sample_component_class.add_call_context
|
38
|
-
|
39
|
-
loader = load_dial_plan(<<-DIAL_PLAN)
|
40
|
-
some_context {
|
41
|
-
SampleComponent2
|
42
|
-
}
|
43
|
-
DIAL_PLAN
|
44
|
-
|
45
|
-
flexmock(Adhearsion::DialPlan::Loader).should_receive(:load_dial_plan).and_return(loader)
|
46
|
-
tested_call = Adhearsion::Call.new(nil, :context => :some_context)
|
47
|
-
mock_config = flexmock 'a Configuration which communicates automatically_answer_incoming_calls properly',
|
48
|
-
:automatically_answer_incoming_calls => false
|
49
|
-
flexmock(Adhearsion::Configuration).should_receive(:new).once.and_return mock_config
|
50
|
-
Adhearsion::Configuration.configure
|
51
|
-
|
52
|
-
the_following_code {
|
53
|
-
handle(tested_call)
|
54
|
-
}.should.not.raise
|
55
|
-
end
|
56
|
-
|
57
|
-
test "the call context is injected into any instances of the component class" do
|
58
|
-
sample_component_class = new_componenet_class_named('SampleComponent3')
|
59
|
-
sample_component_class.add_call_context :as => :call_context_variable_name
|
60
|
-
|
61
|
-
loader = load_dial_plan(<<-DIAL_PLAN)
|
62
|
-
some_context {
|
63
|
-
new_sample_component3.call_context_variable_name
|
64
|
-
}
|
65
|
-
DIAL_PLAN
|
66
|
-
|
67
|
-
flexmock(Adhearsion::DialPlan::Loader).should_receive(:load_dial_plan).and_return(loader)
|
68
|
-
sample_call = Adhearsion::Call.new(nil, :context => :some_context)
|
69
|
-
mock_config = flexmock 'a Configuration which communicates automatically_answer_incoming_calls properly',
|
70
|
-
:automatically_answer_incoming_calls => false
|
71
|
-
flexmock(Adhearsion::Configuration).should_receive(:new).once.and_return mock_config
|
72
|
-
Adhearsion::Configuration.configure
|
73
|
-
|
74
|
-
the_following_code {
|
75
|
-
handle(sample_call)
|
76
|
-
}.should.not.raise
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
def load_dial_plan(dial_plan_as_string)
|
81
|
-
Adhearsion::DialPlan::Loader.load(dial_plan_as_string)
|
82
|
-
end
|
83
|
-
|
84
|
-
def handle(call)
|
85
|
-
Adhearsion::DialPlan::Manager.handle(call)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
BEGIN {
|
90
|
-
module CallContextComponentTestHelpers
|
91
|
-
def new_componenet_class_named(component_name)
|
92
|
-
component_namespace = Adhearsion::Components::ComponentModule.new('passed in component does not matter here')
|
93
|
-
Adhearsion::Components::Component.prepare_component_class(component_namespace, component_name)
|
94
|
-
component_namespace.const_get(component_name)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
}
|
data/spec/test_constants.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/test_helper"
|
2
|
-
|
3
|
-
context "The Adhearsion module" do
|
4
|
-
# This test is of questionable benefit
|
5
|
-
test "should have a VERSION constant" do
|
6
|
-
assert(Adhearsion.const_defined?(:VERSION), "VERSION constant should be defined")
|
7
|
-
end
|
8
|
-
end
|
data/spec/test_drb.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/test_helper"
|
2
|
-
|
3
|
-
# The way I envisoned publishing this DRb:
|
4
|
-
#
|
5
|
-
# publish :globally do/end
|
6
|
-
# publish :with => :drb do/end
|
7
|
-
|
8
|
-
context "Publishing an interface" do
|
9
|
-
test "should be allowed with a class method" do
|
10
|
-
Class.new.class_eval do
|
11
|
-
include Adhearsion::Publishable
|
12
|
-
publish :through => :interface do
|
13
|
-
def self.bar
|
14
|
-
[1, 2, 3]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
Adhearsion::DrbDoor.instance.interface.bar.should.equal [1, 2, 3]
|
19
|
-
end
|
20
|
-
|
21
|
-
test "should be allowed with an alternate interface" do
|
22
|
-
Class.new.class_eval do
|
23
|
-
include Adhearsion::Publishable
|
24
|
-
publish :through => :api do
|
25
|
-
def self.bar
|
26
|
-
[2, 3, 4]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
Adhearsion::DrbDoor.instance.api.bar.should.equal [2, 3, 4]
|
31
|
-
end
|
32
|
-
|
33
|
-
test "should be allowed with a metaclass block" do
|
34
|
-
Class.new.class_eval do
|
35
|
-
include Adhearsion::Publishable
|
36
|
-
publish :through => :interface do
|
37
|
-
class << self
|
38
|
-
def bar
|
39
|
-
[3, 2, 1]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
Adhearsion::DrbDoor.instance.interface.bar.should.equal [3, 2, 1]
|
45
|
-
end
|
46
|
-
|
47
|
-
test "should be allowed from within the metaclass block" do
|
48
|
-
# Class.new.class_eval do
|
49
|
-
# include Publishable
|
50
|
-
# class << self
|
51
|
-
# publish :through => :interface do
|
52
|
-
# def baz
|
53
|
-
# [4, 5, 6]
|
54
|
-
# end
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
# end
|
58
|
-
# Adhearsion::DrbDoor.instance.interface.baz.should.equal [4, 5, 6]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "Invoking an interface" do
|
63
|
-
test "should raise an exception if the method is not found" do
|
64
|
-
the_following_code do
|
65
|
-
Adhearsion::DrbDoor.instance.interface.foobar.should.equal [1, 2, 3]
|
66
|
-
end.should.raise NoMethodError
|
67
|
-
end
|
68
|
-
|
69
|
-
test "should raise an exception if the interface is not found" do
|
70
|
-
the_following_code do
|
71
|
-
Adhearsion::DrbDoor.instance.bad_interface.bar.should.equal [1, 2, 3]
|
72
|
-
end.should.raise NoMethodError
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "Invoking an interface method via DRb" do
|
77
|
-
require 'drb'
|
78
|
-
before do
|
79
|
-
@door = DRb.start_service "druby://127.0.0.1:9050", Adhearsion::DrbDoor.instance
|
80
|
-
end
|
81
|
-
|
82
|
-
test "should return the proper result" do
|
83
|
-
client = DRbObject.new nil, DRb.uri
|
84
|
-
client.interface.bar.should.equal [3, 2, 1]
|
85
|
-
end
|
86
|
-
|
87
|
-
test "should raise an exception for a non-existent interface" do
|
88
|
-
client = DRbObject.new nil, DRb.uri
|
89
|
-
the_following_code do
|
90
|
-
client.interface.bad_interface.should.equal [3, 2, 1]
|
91
|
-
end.should.raise NoMethodError
|
92
|
-
end
|
93
|
-
|
94
|
-
test "should raise an exception for a non-existent method" do
|
95
|
-
client = DRbObject.new nil, DRb.uri
|
96
|
-
the_following_code do
|
97
|
-
client.interface.interface.foobar.equal [3, 2, 1]
|
98
|
-
end.should.raise NoMethodError
|
99
|
-
end
|
100
|
-
|
101
|
-
after do
|
102
|
-
DRb.stop_service
|
103
|
-
end
|
104
|
-
end
|
data/spec/test_helper.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
Dir.chdir File.join(File.dirname(__FILE__), '..')
|
2
|
-
require 'rubygems'
|
3
|
-
def require_or_report_dependency(require_name, gem_name)
|
4
|
-
begin
|
5
|
-
require require_name
|
6
|
-
rescue LoadError
|
7
|
-
report_dependency!(gem_name)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def report_dependency!(name)
|
12
|
-
puts;puts
|
13
|
-
puts "You need #{name} to run these tests: gem install #{name}"
|
14
|
-
puts;puts
|
15
|
-
exit!
|
16
|
-
end
|
17
|
-
|
18
|
-
require_or_report_dependency('test/spec', 'test-spec')
|
19
|
-
require_or_report_dependency('flexmock/test_unit', 'flexmock')
|
20
|
-
require_or_report_dependency('active_support', 'activesupport')
|
21
|
-
# require_or_report_dependency('ruby-debug', 'ruby-debug')
|
22
|
-
require_or_report_dependency('rubigen', 'rubigen')
|
23
|
-
|
24
|
-
require 'pp'
|
25
|
-
require 'stringio'
|
26
|
-
|
27
|
-
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
28
|
-
$: << File.expand_path('lib')
|
29
|
-
$: << File.dirname(__FILE__)
|
30
|
-
|
31
|
-
require 'adhearsion'
|
32
|
-
class Adhearsion::Initializer
|
33
|
-
def asterisk_enabled?
|
34
|
-
false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
class Test::Unit::TestCase
|
42
|
-
|
43
|
-
alias_method :the_following_code, :lambda
|
44
|
-
def self.test(*args, &block)
|
45
|
-
if block_given?
|
46
|
-
specify(args, &block)
|
47
|
-
else
|
48
|
-
disabled_test(*args)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.disabled_test(*args, &block)
|
53
|
-
xspecify(*args, &block)
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
module InitializerStubs
|
59
|
-
|
60
|
-
UNWANTED_BEHAVIOR = {
|
61
|
-
Adhearsion::Initializer => [:initialize_log_file, :switch_to_root_directory, :daemonize!],
|
62
|
-
Adhearsion::Hooks::AfterInitialized.metaclass => [:create_hook, :trigger_hooks]
|
63
|
-
} unless defined? UNWANTED_BEHAVIOR
|
64
|
-
|
65
|
-
def with_new_initializer_with_no_path_changing_behavior
|
66
|
-
stub_unwanted_behavior
|
67
|
-
Adhearsion::Initializer.new('path does not matter')
|
68
|
-
yield if block_given?
|
69
|
-
unstub_directory_changing_behavior
|
70
|
-
end
|
71
|
-
|
72
|
-
def stub_unwanted_behavior
|
73
|
-
UNWANTED_BEHAVIOR.each do |stub_victim_class, undesired_methods|
|
74
|
-
undesired_methods.each do |undesired_method_name|
|
75
|
-
stub_victim_class.send(:alias_method, "pre_stubbed_#{undesired_method_name}", undesired_method_name)
|
76
|
-
stub_victim_class.send(:define_method, undesired_method_name) { |*args| }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def unstub_directory_changing_behavior
|
82
|
-
UNWANTED_BEHAVIOR.each do |stub_victim_class, undesired_methods|
|
83
|
-
undesired_methods.each do |undesired_method_name|
|
84
|
-
stub_victim_class.send(:alias_method, undesired_method_name, "pre_stubbed_#{undesired_method_name}")
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
Adhearsion::Initializer.ahn_root = File.dirname(__FILE__) + '/fixtures'
|
91
|
-
require 'spec/silence' unless ENV['SHOW_DISABLED']
|
92
|
-
|
93
|
-
require 'adhearsion/voip/asterisk'
|
94
|
-
require 'adhearsion/component_manager'
|
data/spec/test_hooks.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/test_helper.rb"
|
2
|
-
|
3
|
-
# context "Adhearsion::Hooks::TearDown when initializing a project" do
|
4
|
-
# include InitializerStubs
|
5
|
-
# test "should trap TERM and INT signals" do
|
6
|
-
# flexmock(Adhearsion::Hooks::TearDown).should_receive(:catch_termination_signals).at_least.once
|
7
|
-
# with_new_initializer_with_no_path_changing_behavior {}
|
8
|
-
# end
|
9
|
-
# end
|
10
|
-
|
11
|
-
# module StandardHookBehavior
|
12
|
-
# def test_standard_hook_behavior
|
13
|
-
# @hook.should.respond_to(:trigger_hooks)
|
14
|
-
# @hook.should.respond_to(:create_hook)
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
|
18
|
-
# for hook in Adhearsion::Hooks.constants.map { |c| (Adhearsion::Hooks.const_get c) }
|
19
|
-
# describe hook.to_s do
|
20
|
-
# include StandardHookBehavior
|
21
|
-
# before(:each) { @hook = hook }
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
|
25
|
-
context "A HookWithArguments" do
|
26
|
-
test "should pass the arguments to trigger_hooks() along to each registered block" do
|
27
|
-
hook_manager = Adhearsion::Hooks::HookWithArguments.new
|
28
|
-
hook_manager.create_hook do |foo, bar|
|
29
|
-
foo.should.equal :foo
|
30
|
-
bar.should.equal :bar
|
31
|
-
throw :inside_hook
|
32
|
-
end
|
33
|
-
the_following_code {
|
34
|
-
hook_manager.trigger_hooks(:foo, :bar)
|
35
|
-
}.should.throw :inside_hook
|
36
|
-
end
|
37
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
-
require 'adhearsion/host_definitions'
|
3
|
-
|
4
|
-
context 'HostDefinition' do
|
5
|
-
|
6
|
-
after :each do
|
7
|
-
Adhearsion::HostDefinition.clear_definitions!
|
8
|
-
end
|
9
|
-
|
10
|
-
test 'when loading from a YAML array, it should pass each nested Hash to the constructor' do
|
11
|
-
hosts = [
|
12
|
-
{:host => "hostname1", :username => "user", :password => "password"},
|
13
|
-
{:host => "hostname2", :username => "user", :password => "password"},
|
14
|
-
{:host => "hostname3", :username => "user", :password => "password"}
|
15
|
-
]
|
16
|
-
flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(hosts[0])
|
17
|
-
flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(hosts[1])
|
18
|
-
flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(hosts[2])
|
19
|
-
Adhearsion::HostDefinition.import_from_yaml hosts.to_yaml
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'should set the @name property to a new UUID when no name is given' do
|
23
|
-
definition = {:host => "hostname", :username => "user", :password => "pass"}
|
24
|
-
Adhearsion::HostDefinition.new(definition).name.should =~ /^[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}$/i
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'when loading from YAML keys, it should pass each nested Hash to the constructor with the key as :name' do
|
28
|
-
definitions = { :pbx1 => {},
|
29
|
-
:pbx2 => {},
|
30
|
-
:pbx3 => {} }
|
31
|
-
definitions.each_pair do |key,value|
|
32
|
-
flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(value.merge(:name => key))
|
33
|
-
end
|
34
|
-
Adhearsion::HostDefinition.import_from_data_structure(definitions)
|
35
|
-
end
|
36
|
-
|
37
|
-
test 'should have an Array class variable named definitions' do
|
38
|
-
Adhearsion::HostDefinition.definitions.should.be.kind_of Array
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'should add each HostDefinition to a class variable named @@definitions when instantiated' do
|
42
|
-
Adhearsion::HostDefinition.definitions.size.should.equal 0
|
43
|
-
Adhearsion::HostDefinition.new :name => "foobar", :host => "hostname", :username => "user", :password => "password"
|
44
|
-
Adhearsion::HostDefinition.definitions.size.should.equal 1
|
45
|
-
Adhearsion::HostDefinition.clear_definitions!
|
46
|
-
Adhearsion::HostDefinition.definitions.size.should.equal 0
|
47
|
-
end
|
48
|
-
|
49
|
-
test 'should raise a HostDefinitionException when a password and a key are given' do
|
50
|
-
the_following_code {
|
51
|
-
Adhearsion::HostDefinition.new(:username => "user", :host => "foobar", :key => "doesntmatter", :password => "pass")
|
52
|
-
}.should.raise Adhearsion::HostDefinition::HostDefinitionException
|
53
|
-
end
|
54
|
-
|
55
|
-
test 'should raise a HostDefinitionException when no password or key is given' do
|
56
|
-
the_following_code {
|
57
|
-
Adhearsion::HostDefinition.new(:username => "user", :host => "foobar")
|
58
|
-
}.should.raise Adhearsion::HostDefinition::HostDefinitionException
|
59
|
-
end
|
60
|
-
|
61
|
-
test 'should raise a HostDefinitionException when no username is given' do
|
62
|
-
the_following_code {
|
63
|
-
Adhearsion::HostDefinition.new(:host => "host", :password => "password")
|
64
|
-
}.should.raise Adhearsion::HostDefinition::HostDefinitionException
|
65
|
-
end
|
66
|
-
|
67
|
-
test 'should raise a HostDefinitionException when no "host" key is given' do
|
68
|
-
the_following_code {
|
69
|
-
Adhearsion::HostDefinition.new(:username => "foobar", :password => "password")
|
70
|
-
}.should.raise Adhearsion::HostDefinition::HostDefinitionException
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'should raise a HostDefinitionException when an unrecognized key is given' do
|
74
|
-
the_following_code {
|
75
|
-
Adhearsion::HostDefinition.new(:username => "foobar", :password => "password", :host => "blah", :thiskeyisnotrecognized => nil)
|
76
|
-
}.should.raise Adhearsion::HostDefinition::HostDefinitionException
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
data/spec/test_initialization.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
context "Adhearsion::Initializer" do
|
4
|
-
|
5
|
-
include InitializerStubs
|
6
|
-
# TODO: create a specification for aliases
|
7
|
-
|
8
|
-
before :each do
|
9
|
-
Adhearsion.send(:remove_const, 'AHN_CONFIG') if Adhearsion.const_defined? 'AHN_CONFIG'
|
10
|
-
Adhearsion::AHN_CONFIG = Adhearsion::Configuration.new
|
11
|
-
end
|
12
|
-
|
13
|
-
test "initialization will start with only a path given" do
|
14
|
-
with_new_initializer_with_no_path_changing_behavior do
|
15
|
-
Adhearsion::Initializer.new path
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
test "should create a pid file in the app's path when given 'true' as the pid_file hash key argument" do
|
20
|
-
with_new_initializer_with_no_path_changing_behavior do
|
21
|
-
flexmock(File).should_receive(:open).once.with(File.join(path, 'adhearsion.pid'), 'w', Proc)
|
22
|
-
ahn = Adhearsion::Initializer.new path, :pid_file => true
|
23
|
-
ahn.pid_file[0, path.length].should.equal(path)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
test "should NOT create a pid file in the app's path when given 'false' as the pid_file hash key argument" do
|
28
|
-
with_new_initializer_with_no_path_changing_behavior do
|
29
|
-
ahn = Adhearsion::Initializer.new path, :pid_file => false
|
30
|
-
assert_nil ahn.pid_file
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
test "should create a pid file in the app's path by default when daemonizing" do
|
35
|
-
with_new_initializer_with_no_path_changing_behavior do
|
36
|
-
flexmock(File).should_receive(:open).once.with(File.join(path, 'adhearsion.pid'), 'w', Proc)
|
37
|
-
ahn = Adhearsion::Initializer.new path, :daemon => true
|
38
|
-
ahn.pid_file[0, path.size].should.equal(path)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
test "should NOT create a pid file in the app's path when daemonizing and :pid_file is given as false" do
|
43
|
-
with_new_initializer_with_no_path_changing_behavior do
|
44
|
-
ahn = Adhearsion::Initializer.new path, :daemon => true, :pid_file => false
|
45
|
-
assert_nil ahn.pid_file
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
test "should create a designated pid file when supplied a String path as :pid_file" do
|
50
|
-
random_file = "/tmp/AHN_TEST_#{rand 100000}.pid"
|
51
|
-
with_new_initializer_with_no_path_changing_behavior do
|
52
|
-
ahn = Adhearsion::Initializer.new path, :pid_file => random_file
|
53
|
-
ahn.pid_file.should.equal(random_file)
|
54
|
-
assert File.exists?(random_file)
|
55
|
-
File.delete random_file
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
def path
|
61
|
-
'/any/ole/path'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "AHN_ROOT" do
|
66
|
-
include InitializerStubs
|
67
|
-
setup do
|
68
|
-
Object.send(:remove_const, :AHN_ROOT) if defined? AHN_ROOT
|
69
|
-
end
|
70
|
-
|
71
|
-
test "initializing will create the AHN_ROOT" do
|
72
|
-
with_new_initializer_with_no_path_changing_behavior do
|
73
|
-
ahn = Adhearsion::Initializer.new path
|
74
|
-
assert Object.constants.include?("AHN_ROOT")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
test "swapping out the base_path for the duration of the block" do
|
79
|
-
original_base_path = '.'
|
80
|
-
temporary_base = '/foo'
|
81
|
-
|
82
|
-
path = Adhearsion::PathString.new(original_base_path)
|
83
|
-
path.should.equal original_base_path
|
84
|
-
|
85
|
-
path.using_base_path temporary_base do
|
86
|
-
path.should.equal temporary_base
|
87
|
-
end
|
88
|
-
path.should.equal original_base_path
|
89
|
-
end
|
90
|
-
|
91
|
-
test "creating the AHN_ROOT will set defaults" do
|
92
|
-
with_new_initializer_with_no_path_changing_behavior do
|
93
|
-
ahn = Adhearsion::Initializer.new path
|
94
|
-
full_path = File.expand_path(path)
|
95
|
-
AHN_ROOT.to_s.should.equal(full_path)
|
96
|
-
AHN_ROOT.component_path.should.equal(File.join(full_path, "components"))
|
97
|
-
AHN_ROOT.log_path.should.equal(File.join(full_path, "logs"))
|
98
|
-
AHN_ROOT.dialplan_path.should.equal(full_path)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
private
|
102
|
-
def path
|
103
|
-
'/any/ole/path'
|
104
|
-
end
|
105
|
-
end
|