Turn off debug by default, you can say -d for the testapp script anyway and like...
[catagits/Catalyst-Engine-STOMP.git] / t / Catalyst-Engine-Stomp.t
CommitLineData
5c4a7793 1use Test::More;
0a663589 2
3# Tests which expect a STOMP server like ActiveMQ to exist on
4# localhost:61613, which is what you get if you just get the ActiveMQ
5# distro and run its out-of-the-box config.
6
7use Net::Stomp;
8use YAML::XS qw/ Dump Load /;
9use Data::Dumper;
10
6ac87378 11use Alien::ActiveMQ;
12my $ACTIVEMQ_VERSION = '5.2.0';
13
14unless (Alien::ActiveMQ->is_version_installed($ACTIVEMQ_VERSION)) {
15 plan 'skip_all' => 'No ActiveMQ server installed by Alien::ActiveMQ, try running the "install-activemq" command';
16 exit;
17}
18my $mq = Alien::ActiveMQ->run_server($ACTIVEMQ_VERSION);
19
5c4a7793 20my $stomp;
21eval {
22 $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
23};
24if ($@) {
25 plan 'skip_all' => 'No ActiveMQ server listening on 61613: ' . $@;
26 exit;
27}
28else {
29 plan tests => 12;
30}
31
0a663589 32# First fire off the server
5c4a7793 33$SIG{CHLD} = 'IGNORE';
ff3b0412 34unless (fork()) {
6ac87378 35 system("$^X -Ilib -Itestapp/lib testapp/script/stomptestapp_stomp.pl --oneshot");
ff3b0412 36 exit 0;
37}
a6b86b35 38print STDERR "server started, waiting for spinup...";
6ac87378 39sleep 20;
0a663589 40
41# Now be a client to that server
a6b86b35 42print STDERR "testing\n";
0a663589 43ok($stomp, 'Net::Stomp object');
44
45my $frame = $stomp->connect();
46ok($frame, 'connect to MQ server ok');
47
48my $reply_to = sprintf '%s:1', $frame->headers->{session};
49ok($frame->headers->{session}, 'got a session');
50ok(length $reply_to > 2, 'valid-looking reply_to queue');
51
52ok($stomp->subscribe( { destination => '/temp-queue/reply' } ), 'subscribe to temp queue');
53
54my $message = {
55 payload => { foo => 1, bar => 2 },
56 reply_to => $reply_to,
57 type => 'testaction',
58 };
59my $text = Dump($message);
60ok($text, 'compose message');
61
62$stomp->send( { destination => '/queue/testcontroller', body => $text } );
63
64my $reply_frame = $stomp->receive_frame();
65ok($reply_frame, 'got a reply');
66ok($reply_frame->headers->{destination} eq "/remote-temp-queue/$reply_to", 'came to correct temp queue');
67ok($reply_frame->body, 'has a body');
68
69my $response = Load($reply_frame->body);
70ok($response, 'YAML response ok');
71ok($response->{type} eq 'testaction_response', 'correct type');
72
73ok($stomp->disconnect, 'disconnected');
74