PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/t/03_legacy.t

http://pcj.googlecode.com/
Perl | 223 lines | 214 code | 8 blank | 1 comment | 5 complexity | 173e5a485d9bed2e8a0afb0231167bf1 MD5 | raw file
Possible License(s): AGPL-1.0
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use 5.010;
  5. use Test::More tests => 16;
  6. use POE;
  7. use POE::Component::Jabber;
  8. my $config =
  9. {
  10. IP => 'jabber.org',
  11. Port => '5222',
  12. Hostname => 'jabber.org',
  13. Username => 'poecomponentjabber',
  14. Password => 'poecomponentjabber',
  15. ConnectionType => +LEGACY,
  16. debug => 0,
  17. };
  18. my $scratch_space = {};
  19. POE::Session->create
  20. (
  21. 'inline_states' =>
  22. {
  23. '_start' =>
  24. sub
  25. {
  26. $_[KERNEL]->alias_set('xmpp_testing');
  27. $config->{'Alias'} = 'pcj';
  28. $_[HEAP]->{'pcj'} = POE::Component::Jabber->new(%$config);
  29. $_[KERNEL]->yield('continue');
  30. },
  31. 'continue' =>
  32. sub
  33. {
  34. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_CONNECT, 'pcj_connect');
  35. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_CONNECTING, 'pcj_connecting');
  36. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_CONNECTED, 'pcj_connected');
  37. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_CONNECTFAIL, 'pcj_connectfail');
  38. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_STREAMSTART, 'pcj_streamstart');
  39. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_STREAMEND, 'pcj_streamend');
  40. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_AUTHNEGOTIATE, 'pcj_authnegotiate');
  41. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_AUTHSUCCESS, 'pcj_authsuccess');
  42. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_AUTHFAIL, 'pcj_authfail');
  43. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_READY, 'pcj_ready');
  44. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_SHUTDOWN_START, 'pcj_shutdown_start');
  45. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_SHUTDOWN_FINISH, 'pcj_shutdown_finish');
  46. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_SOCKETFAIL, 'pcj_socketfail');
  47. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_SOCKETDISCONNECT, 'pcj_socketdisconnect');
  48. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_NODERECEIVED, 'pcj_nodereceived');
  49. $_[KERNEL]->post('pcj', 'subscribe', +PCJ_NODESENT, 'pcj_nodesent');
  50. $_[KERNEL]->post('pcj', 'subscribe', 'pcj_xpathfilter', 'pcj_xpathfilter');
  51. $_[KERNEL]->post('pcj', 'xpath_filter', 'add', 'pcj_xpathfilter', q/self::node()[@id='FILTER_TEST']|child::*[@id='FILTER_TEST']/);
  52. if(-e 'run_network_tests')
  53. {
  54. $_[KERNEL]->post('pcj', 'connect');
  55. } else {
  56. SKIP: { skip('Network tests were declined', 16); }
  57. exit 0;
  58. }
  59. },
  60. 'pcj_nodesent' =>
  61. sub
  62. {
  63. my ($kernel, $arg) = @_[KERNEL, ARG0];
  64. if($config->{'debug'})
  65. {
  66. say $arg->toString();
  67. }
  68. },
  69. 'pcj_nodereceived' =>
  70. sub
  71. {
  72. my ($kernel, $arg) = @_[KERNEL, ARG0];
  73. if($config->{'debug'})
  74. {
  75. say $arg->toString();
  76. }
  77. },
  78. 'pcj_connect' =>
  79. sub
  80. {
  81. pass('Connect started');
  82. },
  83. 'pcj_connecting' =>
  84. sub
  85. {
  86. pass('Connecting');
  87. },
  88. 'pcj_connected' =>
  89. sub
  90. {
  91. pass('Connection sucessful');
  92. },
  93. 'pcj_connectfail' =>
  94. sub
  95. {
  96. BAIL_OUT(q|We couldn't connect to the server. Check your |.
  97. 'network connection or rerun Build.PL and say "N" to '.
  98. 'network enabled tests');
  99. },
  100. 'pcj_streamstart' =>
  101. sub
  102. {
  103. pass('Stream initated');
  104. },
  105. 'pcj_streamend' =>
  106. sub
  107. {
  108. $scratch_space->{'STEAMEND'} = 1;
  109. pass('Stream end sent');
  110. },
  111. 'pcj_authnegotiate' =>
  112. sub
  113. {
  114. pass('Negotiating authentication');
  115. },
  116. 'pcj_authsuccess' =>
  117. sub
  118. {
  119. pass('Authentication sucessfully negotiated');
  120. },
  121. 'pcj_authfail' =>
  122. sub
  123. {
  124. BAIL_OUT('Authentication failed for some reason. ' .
  125. 'Please check the username and password in this test '.
  126. 'to make sure it is correct.');
  127. },
  128. 'pcj_ready' =>
  129. sub
  130. {
  131. my $node = POE::Filter::XML::Node->new
  132. (
  133. 'iq',
  134. [
  135. 'to', sprintf('%s@%s', $config->{'Username'}, $config->{'Hostname'}),
  136. 'id', 'FILTER_TEST'
  137. ]
  138. );
  139. $_[KERNEL]->post('pcj', 'output', $node);
  140. },
  141. 'pcj_shutdown_start' =>
  142. sub
  143. {
  144. if(!defined($scratch_space->{'STEAMEND'}))
  145. {
  146. fail('A stream end was not sent to the server!');
  147. } else {
  148. $scratch_space->{'SHUTDOWNSTART'} = 1;
  149. pass('Shutdown in progress');
  150. }
  151. },
  152. 'pcj_shutdown_finish' =>
  153. sub
  154. {
  155. if(!defined($scratch_space->{'SHUTDOWNSTART'}))
  156. {
  157. fail('Shutdown start was never called');
  158. } else {
  159. pass('Shutdown complete');
  160. }
  161. },
  162. 'pcj_xpathfilter' =>
  163. sub
  164. {
  165. my ($kernel, $expr, $found_nodes, $input) =
  166. @_[KERNEL, ARG0..ARG2];
  167. ok($expr eq q/self::node()[@id='FILTER_TEST']|child::*[@id='FILTER_TEST']/, 'XPATH expression');
  168. is(scalar(@$found_nodes), 1, 'One node returned from xpath expression');
  169. isa_ok($found_nodes->[0], 'POE::Filter::XML::Node');
  170. isa_ok($input, 'POE::Filter::XML::Node');
  171. is($found_nodes->[0]->toString(), $input->toString(), 'Found node matches the input node');
  172. $kernel->post('pcj', 'shutdown');
  173. },
  174. 'pcj_socketfail' =>
  175. sub
  176. {
  177. if(!defined($scratch_space->{'STEAMEND'}))
  178. {
  179. BAIL_OUT('There was a socket failure during testing');
  180. } else {
  181. pass('Socket read error at end of stream okay');
  182. }
  183. },
  184. 'pcj_socketdisconnect' =>
  185. sub
  186. {
  187. if(!defined($scratch_space->{'SHUTDOWNSTART'}))
  188. {
  189. BAIL_OUT('We were disconnected during testing');
  190. } else {
  191. pass('Disconnected called at the right time');
  192. }
  193. },
  194. }
  195. );
  196. POE::Kernel->run();
  197. exit 0;