troystribling-agent_xmpp 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/README.rdoc +397 -2
  2. data/Rakefile +33 -21
  3. data/VERSION +1 -1
  4. data/agent_xmpp.gemspec +78 -33
  5. data/lib/agent_xmpp.rb +11 -7
  6. data/lib/agent_xmpp/app.rb +0 -5
  7. data/lib/agent_xmpp/app/boot.rb +47 -33
  8. data/lib/agent_xmpp/app/controller.rb +135 -19
  9. data/lib/agent_xmpp/client.rb +6 -1
  10. data/lib/agent_xmpp/client/client.rb +22 -155
  11. data/lib/agent_xmpp/client/connection.rb +41 -250
  12. data/lib/agent_xmpp/client/message_delegate.rb +706 -0
  13. data/lib/agent_xmpp/client/message_pipe.rb +176 -0
  14. data/lib/agent_xmpp/client/publish_model.rb +65 -0
  15. data/lib/agent_xmpp/{app/format.rb → client/response.rb} +19 -24
  16. data/lib/agent_xmpp/client/roster_model.rb +139 -0
  17. data/lib/agent_xmpp/client/services_model.rb +97 -0
  18. data/lib/agent_xmpp/config.rb +45 -0
  19. data/lib/agent_xmpp/main.rb +126 -0
  20. data/lib/agent_xmpp/patches.rb +6 -2
  21. data/lib/agent_xmpp/patches/{standard_library_patches/array.rb → array.rb} +14 -7
  22. data/lib/agent_xmpp/patches/{standard_library_patches/float.rb → float.rb} +0 -0
  23. data/lib/agent_xmpp/patches/{standard_library_patches/hash.rb → hash.rb} +3 -3
  24. data/lib/agent_xmpp/patches/{standard_library_patches/object.rb → object.rb} +3 -3
  25. data/lib/agent_xmpp/patches/rexml.rb +69 -0
  26. data/lib/agent_xmpp/patches/{standard_library_patches/string.rb → string.rb} +5 -0
  27. data/lib/agent_xmpp/xmpp.rb +17 -0
  28. data/lib/agent_xmpp/xmpp/element.rb +159 -0
  29. data/lib/agent_xmpp/xmpp/error_response.rb +179 -0
  30. data/lib/agent_xmpp/xmpp/iq.rb +90 -0
  31. data/lib/agent_xmpp/xmpp/iq_command.rb +47 -0
  32. data/lib/agent_xmpp/xmpp/iq_disco.rb +205 -0
  33. data/lib/agent_xmpp/xmpp/iq_pubsub.rb +268 -0
  34. data/lib/agent_xmpp/xmpp/iq_roster.rb +183 -0
  35. data/lib/agent_xmpp/xmpp/iq_version.rb +89 -0
  36. data/lib/agent_xmpp/xmpp/jid.rb +150 -0
  37. data/lib/agent_xmpp/xmpp/message.rb +82 -0
  38. data/lib/agent_xmpp/xmpp/presence.rb +127 -0
  39. data/lib/agent_xmpp/xmpp/sasl.rb +241 -0
  40. data/lib/agent_xmpp/xmpp/stanza.rb +107 -0
  41. data/lib/agent_xmpp/xmpp/x_data.rb +269 -0
  42. data/test/app/app.rb +134 -0
  43. data/test/cases/test_application_message_processing.rb +65 -0
  44. data/test/cases/test_errors.rb +24 -0
  45. data/test/cases/test_presence_management.rb +139 -0
  46. data/test/cases/test_roster_management.rb +214 -0
  47. data/test/cases/test_service_discovery.rb +168 -0
  48. data/test/cases/test_session_management.rb +120 -0
  49. data/test/cases/test_version_discovery.rb +67 -0
  50. data/test/helpers/matchers.rb +23 -0
  51. data/test/helpers/mocks.rb +82 -0
  52. data/test/helpers/test_case_extensions.rb +45 -0
  53. data/test/helpers/test_client.rb +44 -0
  54. data/test/helpers/test_delegate.rb +61 -0
  55. data/test/helpers/test_helper.rb +91 -0
  56. data/test/messages/application_messages.rb +206 -0
  57. data/test/messages/error_messages.rb +35 -0
  58. data/test/messages/presence_messages.rb +66 -0
  59. data/test/messages/roster_messages.rb +126 -0
  60. data/test/messages/service_discovery_messages.rb +201 -0
  61. data/test/messages/session_messages.rb +158 -0
  62. data/test/messages/version_discovery_messages.rb +69 -0
  63. data/test/peer/peer.rb +36 -0
  64. data/test/xml_messages.txt +197 -0
  65. metadata +82 -42
  66. data/bin/agent_xmpp +0 -56
  67. data/lib/agent_xmpp/app/chat_message_body_controller.rb +0 -16
  68. data/lib/agent_xmpp/app/map.rb +0 -45
  69. data/lib/agent_xmpp/app/routes.rb +0 -77
  70. data/lib/agent_xmpp/app/view.rb +0 -49
  71. data/lib/agent_xmpp/client/parser.rb +0 -71
  72. data/lib/agent_xmpp/patches/standard_library_patches.rb +0 -5
  73. data/lib/agent_xmpp/patches/xmpp4r_patches.rb +0 -3
  74. data/lib/agent_xmpp/patches/xmpp4r_patches/command.rb +0 -26
  75. data/lib/agent_xmpp/patches/xmpp4r_patches/iq.rb +0 -26
  76. data/lib/agent_xmpp/patches/xmpp4r_patches/x_data.rb +0 -116
  77. data/lib/agent_xmpp/utils.rb +0 -2
  78. data/lib/agent_xmpp/utils/logger.rb +0 -24
  79. data/lib/agent_xmpp/utils/roster.rb +0 -23
  80. data/lib/agent_xmpp/version.rb +0 -6
  81. data/test/agent_xmpp_test.rb +0 -7
  82. data/test/test_helper.rb +0 -10
@@ -0,0 +1,168 @@
1
+ ##############################################################################################################
2
+ require 'test_helper'
3
+
4
+ ##############################################################################################################
5
+ class TestServiceDiscovery < Test::Unit::TestCase
6
+
7
+ #.........................................................................................................
8
+ def setup
9
+ @client = TestClient.new()
10
+ test_init_roster(@client)
11
+ @delegate = @client.new_delegate
12
+ @server = AgentXmpp::Xmpp::Jid.new(@client.jid.domain)
13
+ @test = AgentXmpp::Xmpp::Jid.new('test@plan-b.ath.cx/home')
14
+ @noone = AgentXmpp::Xmpp::Jid.new('noone@plan-b.ath.cx/nowhere')
15
+ end
16
+
17
+ ####------------------------------------------------------------------------------------------------------
18
+ context "after sesson start a disco#info request addressed to the server should be generated" do
19
+
20
+ #.........................................................................................................
21
+ setup do
22
+ @delegate.did_receive_discoinfo_result_method.should_not be_called
23
+ AgentXmpp.roster.has_discoinfo?(@server).should be(false)
24
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_result_query_discoinfo(@client, @server.to_s)).should \
25
+ respond_with(ServiceDiscoveryMessages.send_iq_get_query_discoitems(@client, @server.to_s))
26
+ @delegate.did_receive_discoinfo_result_method.should be_called
27
+ AgentXmpp.roster.has_discoinfo?(@server).should be(true)
28
+ end
29
+
30
+ #.........................................................................................................
31
+ should "and the result update the server roster entry and generate a disco#info request if the result is not an error" do
32
+ end
33
+
34
+ #.........................................................................................................
35
+ should "update the server roster entry with result of server disco#items request if the result is not an error" do
36
+ @delegate.did_receive_discoitems_result_method.should_not be_called
37
+ AgentXmpp.roster.has_discoitems?(@server).should be(false)
38
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_result_query_discoitems(@client, @server.to_s)).should not_respond
39
+ @delegate.did_receive_discoitems_result_method.should be_called
40
+ AgentXmpp.roster.has_discoitems?(@server).should be(true)
41
+ end
42
+
43
+ #.........................................................................................................
44
+ should "not update the server roster entry with the disco#items result if the result is an error" do
45
+ @delegate.did_receive_discoitems_result_method.should_not be_called
46
+ @delegate.did_receive_discoitems_error_method.should_not be_called
47
+ AgentXmpp.roster.has_discoitems?(@server).should be(false)
48
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_error_query_discoitems(@client, @server.to_s)).should not_respond
49
+ @delegate.did_receive_discoitems_result_method.should_not be_called
50
+ @delegate.did_receive_discoitems_error_method.should be_called
51
+ AgentXmpp.roster.has_discoitems?(@server).should be(false)
52
+ end
53
+
54
+ end
55
+
56
+ ####------------------------------------------------------------------------------------------------------
57
+ context "after transition of contact to presence with type=available a disco#info request addressed to the contact should be genearated and the result" do
58
+
59
+ #.........................................................................................................
60
+ setup do
61
+ AgentXmpp::Xmpp::IdGenerator.set_gen_id([1,2])
62
+ @client.receiving(PresenceMessages.recv_presence_available(@client, @test.to_s))
63
+ @delegate.did_receive_discoinfo_result_method.should_not be_called
64
+ AgentXmpp.roster.has_discoinfo?(@test).should be(false)
65
+ AgentXmpp::Xmpp::IdGenerator.set_gen_id
66
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_result_query_discoinfo(@client, @test.to_s)).should \
67
+ respond_with(ServiceDiscoveryMessages.send_iq_get_query_discoitems(@client, @test.to_s))
68
+ @delegate.did_receive_discoinfo_result_method.should be_called
69
+ AgentXmpp.roster.has_discoinfo?(@test).should be(true)
70
+ end
71
+
72
+ #.........................................................................................................
73
+ should "update the contact roster entry and generate a disco#items request if the result is not an error" do
74
+ end
75
+
76
+ #.........................................................................................................
77
+ should "update the contact roster entry with result of contact disco#items request if the result is not an error" do
78
+ @delegate.did_receive_discoitems_result_method.should_not be_called
79
+ AgentXmpp.roster.has_discoitems?(@test).should be(false)
80
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_result_query_discoitems(@client, @test.to_s)).should not_respond
81
+ @delegate.did_receive_discoitems_result_method.should be_called
82
+ AgentXmpp.roster.has_discoitems?(@test).should be(true)
83
+ end
84
+
85
+ #.........................................................................................................
86
+ should "not update the contact roster entry with the disco#info result or geneate a disco#items request if the result is an error" do
87
+ @delegate.did_receive_discoitems_result_method.should_not be_called
88
+ @delegate.did_receive_discoitems_error_method.should_not be_called
89
+ AgentXmpp.roster.has_discoitems?(@test).should be(false)
90
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_error_query_discoitems(@client, @test.to_s)).should not_respond
91
+ @delegate.did_receive_discoitems_result_method.should_not be_called
92
+ @delegate.did_receive_discoitems_error_method.should be_called
93
+ AgentXmpp.roster.has_discoitems?(@test).should be(false)
94
+ end
95
+
96
+ end
97
+
98
+ #.........................................................................................................
99
+ should "not update the roster entry with the disco#info result or geneate a disco#items request if an error is received as a result of a disco#info request" do
100
+ @delegate.did_receive_discoinfo_result_method.should_not be_called
101
+ @delegate.did_receive_discoinfo_error_method.should_not be_called
102
+ AgentXmpp.roster.has_discoinfo?(@server).should be(false)
103
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_error_query_discoinfo(@client, @server.to_s)).should not_respond
104
+ AgentXmpp.roster.has_discoinfo?(@server).should be(false)
105
+ @delegate.did_receive_discoinfo_result_method.should_not be_called
106
+ @delegate.did_receive_discoinfo_error_method.should be_called
107
+ end
108
+
109
+ #.........................................................................................................
110
+ should "respond with features and identity when get disco#info is received without a specified node from a jid in the configuration roster" do
111
+ @delegate.did_receive_discoinfo_get_method.should_not be_called
112
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_get_query_discoinfo(@client, @test.to_s)).should \
113
+ respond_with(ServiceDiscoveryMessages.send_iq_result_query_discoinfo(@client, @test.to_s))
114
+ @delegate.did_receive_discoinfo_get_method.should be_called
115
+ end
116
+
117
+ #.........................................................................................................
118
+ should "respond with service-unavailable error when get disco#info is received for unsupported node" do
119
+ @delegate.did_receive_discoinfo_get_method.should_not be_called
120
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_get_query_discoinfo_error(@client, @test.to_s)).should \
121
+ respond_with(ServiceDiscoveryMessages.send_iq_error_discoinfo_service_unavailable(@client, @test.to_s))
122
+ @delegate.did_receive_discoinfo_get_method.should be_called
123
+ end
124
+
125
+ #.........................................................................................................
126
+ should "not respond if get disco#info is received from a jid not in the configuration roster" do
127
+ AgentXmpp.roster.has_jid?(@noone).should be(false)
128
+ @delegate.did_receive_discoinfo_get_method.should_not be_called
129
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_get_query_discoinfo(@client, @noone.to_s)).should not_respond
130
+ AgentXmpp.roster.has_jid?(@noone).should be(false)
131
+ @delegate.did_receive_discoinfo_get_method.should be_called
132
+ end
133
+
134
+ #.........................................................................................................
135
+ should "respond with empty result when get disco#items is received with no specified node from a jid in the configuration roster" do
136
+ @delegate.did_receive_discoitems_get_method.should_not be_called
137
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_get_query_discoitems(@client, @test.to_s)).should \
138
+ respond_with(ServiceDiscoveryMessages.send_iq_result_query_discoitems(@client, @test.to_s))
139
+ @delegate.did_receive_discoitems_get_method.should be_called
140
+ end
141
+
142
+ #.........................................................................................................
143
+ should "respond with command nodes when get disco#items is received for the node 'http://jabber.org/protocol/commands'" do
144
+ @delegate.did_receive_discoitems_get_method.should_not be_called
145
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_get_query_discoitems_for_commands_node(@client, @test.to_s)).should \
146
+ respond_with(ServiceDiscoveryMessages.send_iq_result_query_discoitems_for_commands_node(@client, @test.to_s))
147
+ @delegate.did_receive_discoitems_get_method.should be_called
148
+ end
149
+
150
+ #.........................................................................................................
151
+ should "respond with item-not-found error when get disco#items is received for unsupported node" do
152
+ @delegate.did_receive_discoitems_get_method.should_not be_called
153
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_get_query_discoitems_error(@client, @test.to_s)).should \
154
+ respond_with(ServiceDiscoveryMessages.send_iq_error_discoitems_item_not_found(@client, @test.to_s))
155
+ @delegate.did_receive_discoitems_get_method.should be_called
156
+ end
157
+
158
+ #.........................................................................................................
159
+ should "not respond if get disco#items is received from a jid not in the configuration roster" do
160
+ AgentXmpp.roster.has_jid?(@noone).should be(false)
161
+ @delegate.did_receive_discoitems_get_method.should_not be_called
162
+ @client.receiving(ServiceDiscoveryMessages.recv_iq_get_query_discoitems(@client, @noone.to_s)).should not_respond
163
+ AgentXmpp.roster.has_jid?(@noone).should be(false)
164
+ @delegate.did_receive_discoitems_get_method.should be_called
165
+ end
166
+
167
+ end
168
+
@@ -0,0 +1,120 @@
1
+ ##############################################################################################################
2
+ require 'test_helper'
3
+
4
+ ##############################################################################################################
5
+ class TestSessionManagement < Test::Unit::TestCase
6
+
7
+ #.........................................................................................................
8
+ def setup
9
+ @client = TestClient.new
10
+ AgentXmpp::Xmpp::IdGenerator.set_gen_id
11
+ @delegate = @client.new_delegate
12
+ end
13
+
14
+ #.........................................................................................................
15
+ should "authenticate with PLAIN SASL authentication when stream features includes PLAIN authentication" do
16
+
17
+ #### connect to server
18
+ @client.client.pipe.connection_completed.should \
19
+ respond_with(SessionMessages.send_supported_xml_version(@client), SessionMessages.send_stream(@client))
20
+
21
+ #### receive pre authentication stream feautues and mechanisms and authenticate
22
+ @delegate.did_authenticate_method.should_not be_called
23
+ @delegate.did_receive_preauthenticate_features_method.should_not be_called
24
+ @client.receiving(SessionMessages.recv_preauthentication_stream_features_with_plain_SASL(@client)).should \
25
+ respond_with(SessionMessages.send_auth_plain(@client))
26
+ @client.receiving(SessionMessages.recv_auth_success(@client)).should respond_with(SessionMessages.send_stream(@client))
27
+ @delegate.did_receive_preauthenticate_features_method.should be_called
28
+ @delegate.did_authenticate_method.should be_called
29
+
30
+ #### bind resource
31
+ @delegate.did_bind_method.should_not be_called
32
+ @delegate.did_receive_postauthenticate_features_method.should_not be_called
33
+ @client.receiving(SessionMessages.recv_postauthentication_stream_features(@client)).should respond_with(SessionMessages.send_iq_set_bind(@client))
34
+ @client.receiving(SessionMessages.recv_iq_result_bind(@client)).should respond_with(SessionMessages.send_iq_set_session(@client))
35
+ @delegate.did_receive_postauthenticate_features_method.should be_called
36
+ @delegate.did_bind_method.should be_called
37
+
38
+ #### start session and request roster
39
+ @delegate.did_start_session_method.should_not be_called
40
+ @client.receiving(SessionMessages.recv_iq_result_session(@client)).should \
41
+ respond_with(SessionMessages.send_presence_init(@client), RosterMessages.send_iq_get_query_roster(@client),
42
+ ServiceDiscoveryMessages.send_iq_get_query_discoinfo(@client, @client.jid.domain))
43
+ @delegate.did_start_session_method.should be_called
44
+
45
+ end
46
+
47
+ #.........................................................................................................
48
+ should "raise exception when stream features do not include PLAIN authentication" do
49
+
50
+ #### connect to server
51
+ @client.client.pipe.connection_completed
52
+
53
+ #### receive pre authentication stream feautues which do not include plain authentication
54
+ lambda{@client.receiving(SessionMessages.recv_preauthentication_stream_features_without_plain_SASL(@client))}.should \
55
+ raise_error(AgentXmpp::AgentXmppError)
56
+ end
57
+
58
+ #.........................................................................................................
59
+ should "raise exception when authentication fails" do
60
+
61
+ #### connect to server
62
+ @client.client.pipe.connection_completed
63
+
64
+ #### receive pre authentication stream feautues and mechanisms and authenticate
65
+ @client.receiving(SessionMessages.recv_preauthentication_stream_features_with_plain_SASL(@client)).should \
66
+ respond_with(SessionMessages.send_auth_plain(@client))
67
+ lambda{@client.receiving(SessionMessages.recv_auth_failure(@client))}.should raise_error(AgentXmpp::AgentXmppError)
68
+
69
+ end
70
+
71
+ #.........................................................................................................
72
+ should "raise exception when bind fails" do
73
+
74
+ #### connect to server
75
+ @client.client.pipe.connection_completed
76
+
77
+ #### receive pre authentication stream feautues and mechanisms and authenticate
78
+ @delegate.did_authenticate_method.should_not be_called
79
+ @delegate.did_receive_preauthenticate_features_method.should_not be_called
80
+ @client.receiving(SessionMessages.recv_preauthentication_stream_features_with_plain_SASL(@client)).should \
81
+ respond_with(SessionMessages.send_auth_plain(@client))
82
+ @client.receiving(SessionMessages.recv_auth_success(@client)).should respond_with(SessionMessages.send_stream(@client))
83
+ @delegate.did_receive_preauthenticate_features_method.should be_called
84
+ @delegate.did_authenticate_method.should be_called
85
+
86
+ #### bind resource and receive error
87
+ @client.receiving(SessionMessages.recv_postauthentication_stream_features(@client)).should respond_with(SessionMessages.send_iq_set_bind(@client))
88
+ lambda{@client.receiving(SessionMessages.recv_error_bind(@client))}.should raise_error(AgentXmpp::AgentXmppError)
89
+
90
+ end
91
+
92
+ #.........................................................................................................
93
+ should "raise exception when session start fails" do
94
+
95
+ #### connect to server
96
+ @client.client.pipe.connection_completed
97
+
98
+ #### receive pre authentication stream feautues and mechanisms and authenticate
99
+ @delegate.did_authenticate_method.should_not be_called
100
+ @delegate.did_receive_preauthenticate_features_method.should_not be_called
101
+ @client.receiving(SessionMessages.recv_preauthentication_stream_features_with_plain_SASL(@client)).should \
102
+ respond_with(SessionMessages.send_auth_plain(@client))
103
+ @client.receiving(SessionMessages.recv_auth_success(@client)).should respond_with(SessionMessages.send_stream(@client))
104
+ @delegate.did_receive_preauthenticate_features_method.should be_called
105
+ @delegate.did_authenticate_method.should be_called
106
+
107
+ #### bind resource
108
+ @delegate.did_receive_postauthenticate_features_method.should_not be_called
109
+ @delegate.did_bind_method.should_not be_called
110
+ @client.receiving(SessionMessages.recv_postauthentication_stream_features(@client)).should respond_with(SessionMessages.send_iq_set_bind(@client))
111
+ @client.receiving(SessionMessages.recv_iq_result_bind(@client)).should respond_with(SessionMessages.send_iq_set_session(@client))
112
+ @delegate.did_receive_postauthenticate_features_method.should be_called
113
+ @delegate.did_bind_method.should be_called
114
+
115
+ #### start session and request roster
116
+ lambda{@client.receiving(SessionMessages.recv_error_session(@client))}.should raise_error(AgentXmpp::AgentXmppError)
117
+
118
+ end
119
+
120
+ end
@@ -0,0 +1,67 @@
1
+ ##############################################################################################################
2
+ require 'test_helper'
3
+
4
+ ##############################################################################################################
5
+ class TestClientVersionDiscovery < Test::Unit::TestCase
6
+
7
+ #.........................................................................................................
8
+ def setup
9
+ @troy = AgentXmpp::Xmpp::Jid.new('troy@nowhere.com/home')
10
+ @noone = AgentXmpp::Xmpp::Jid.new('noone@nowhere.com/nothing')
11
+ @config = {'jid' => 'test@nowhere.com', 'roster' =>[@troy.bare.to_s], 'password' => 'nopass'}
12
+ @client = TestClient.new(@config)
13
+ test_init_roster(@client)
14
+ @delegate = @client.new_delegate
15
+ end
16
+
17
+ ####-------------------------------------------------------------------------------------------------------
18
+ context "on receiving a presence message of type=available from a jid in configured roster" do
19
+
20
+ #.........................................................................................................
21
+ setup do
22
+ AgentXmpp::Xmpp::IdGenerator.set_gen_id([1,2])
23
+ @delegate.did_receive_version_get_method.should_not be_called
24
+ @delegate.did_receive_version_result_method.should_not be_called
25
+ AgentXmpp.roster.resource(@troy).should be_nil
26
+ @client.receiving(PresenceMessages.recv_presence_available(@client, @troy.to_s)).should \
27
+ respond_with(VersionDiscoveryMessages.send_iq_get_query_version(@client, @troy.to_s))
28
+ AgentXmpp.roster.resource(@troy).should_not be_nil
29
+ end
30
+
31
+ #.........................................................................................................
32
+ should "send a client version request to that jid and do nothing if the result is an error" do
33
+ @client.receiving(VersionDiscoveryMessages.recv_iq_result_query_version(@client, @troy.to_s)).should not_respond
34
+ AgentXmpp.roster.has_version?(@troy).should be(true)
35
+ @delegate.did_receive_version_result_method.should be_called
36
+ end
37
+
38
+ #.........................................................................................................
39
+ should "respond to client version requests from that jid" do
40
+ @client.receiving(VersionDiscoveryMessages.recv_iq_result_query_version(@client, @troy.to_s)).should not_respond
41
+ AgentXmpp.roster.has_version?(@troy).should be(true)
42
+ @delegate.did_receive_version_result_method.should be_called
43
+ @client.receiving(VersionDiscoveryMessages.recv_iq_get_query_version(@client, @troy.to_s)).should \
44
+ respond_with(VersionDiscoveryMessages.send_iq_result_query_version(@client, @troy.to_s))
45
+ @delegate.did_receive_version_get_method.should be_called
46
+ end
47
+
48
+ #.........................................................................................................
49
+ should "send a client version request to that jid and update roster with result version information" do
50
+ @delegate.did_receive_version_error_method.should_not be_called
51
+ @client.receiving(VersionDiscoveryMessages.recv_iq_error_query_version(@client, @troy.to_s)).should not_respond
52
+ AgentXmpp.roster.has_version?(@troy).should be(false)
53
+ @delegate.did_receive_version_error_method.should be_called
54
+ end
55
+
56
+ end
57
+
58
+ #.........................................................................................................
59
+ should "not respond to client version requests from jids not in configured roster" do
60
+ @delegate.did_receive_version_get_method.should_not be_called
61
+ AgentXmpp.roster.has_jid?(@noone).should be(false)
62
+ @client.receiving(VersionDiscoveryMessages.recv_iq_get_query_version(@client, @noone.to_s)).should not_respond
63
+ @delegate.did_receive_version_get_method.should be_called
64
+ end
65
+
66
+ end
67
+
@@ -0,0 +1,23 @@
1
+ ####------------------------------------------------------------------------------------------------------
2
+ def_matcher :respond_with do |receiver, matcher, args|
3
+ prepare_msg = lambda{|msg| msg.collect{|i| i.split(/\n+/).inject("") {|p, m| p + m.strip.gsub(/id='\d+'/, '').gsub(/\s+/, " ")}}}
4
+ given = prepare_msg[[receiver].flatten].join
5
+ expected = prepare_msg[args].join
6
+ matcher.positive_msg = "Expected response message of \"#{expected}\" but was given message \"#{given}\""
7
+ matcher.negative_msg = "Expected response message \"#{expected}\" to not match given message \"#{given}\""
8
+ given.include?(expected)
9
+ end
10
+
11
+ ####------------------------------------------------------------------------------------------------------
12
+ def_matcher :not_respond do |receiver, matcher, args|
13
+ matcher.positive_msg = "Expected no responce"
14
+ matcher.negative_msg = "Expected a response"
15
+ receiver.nil? || receiver.empty?
16
+ end
17
+
18
+ ####------------------------------------------------------------------------------------------------------
19
+ def_matcher :be_called do |receiver, matcher, args|
20
+ matcher.positive_msg = "Expected client delgate method '#{receiver.last}' to be called"
21
+ matcher.negative_msg = "Expected client delgate method '#{receiver.last}' to not be called"
22
+ receiver.first
23
+ end
@@ -0,0 +1,82 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+
4
+ #####-------------------------------------------------------------------------------------------------------
5
+ class Connection
6
+
7
+ #.........................................................................................................
8
+ def self.new(*args)
9
+ allocate.instance_eval do
10
+ initialize(*args)
11
+ connection_completed
12
+ self
13
+ end
14
+ end
15
+
16
+ #.........................................................................................................
17
+ def send_data(data)
18
+ data
19
+ end
20
+
21
+ def connection_completed
22
+ pipe.connection_completed
23
+ end
24
+
25
+ #.........................................................................................................
26
+ def error?
27
+ false
28
+ end
29
+
30
+ #.........................................................................................................
31
+ def reset_parser
32
+ end
33
+
34
+ #### Connection
35
+ end
36
+
37
+ #####-------------------------------------------------------------------------------------------------------
38
+ class Client
39
+
40
+ #.........................................................................................................
41
+ def connect
42
+ @connection = AgentXmpp::Connection.new(self)
43
+ end
44
+
45
+ #.........................................................................................................
46
+ def reconnect
47
+ true
48
+ end
49
+
50
+ #### Client
51
+ end
52
+
53
+ #####-------------------------------------------------------------------------------------------------------
54
+ class Controller
55
+ def handle_request
56
+ request_callback(request).collect{|m| Send(Xmpp::Stanza::import(REXML::Document.new(m).root))}
57
+ end
58
+ end
59
+
60
+ #####-------------------------------------------------------------------------------------------------------
61
+ class Boot
62
+ def self.boot
63
+ end
64
+ end
65
+
66
+ #### AgentXmpp
67
+ end
68
+
69
+
70
+ ##############################################################################################################
71
+ module AgentXmpp
72
+ module Xmpp
73
+ class IdGenerator
74
+ @gen_id;
75
+ class << self
76
+ def set_gen_id(val=1); @gen_id = val; end
77
+ def gen_id; @gen_id; end;
78
+ def generate_id; @gen_id.kind_of?(Array) ? @gen_id.shift : @gen_id; end
79
+ end
80
+ end
81
+ end
82
+ end