Remove Test::Fork, do it by hand
[catagits/Catalyst-Engine-STOMP.git] / t / Catalyst-Engine-Stomp.t
CommitLineData
ff3b0412 1use Test::More tests => 12;
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
11# First fire off the server
ff3b0412 12unless (fork()) {
13 system("$^X -Ilib -Itestapp/lib testapp/script/testapp_stomp.pl --oneshot");
14 exit 0;
15}
0a663589 16
17# Now be a client to that server
18
19my $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
20ok($stomp, 'Net::Stomp object');
21
22my $frame = $stomp->connect();
23ok($frame, 'connect to MQ server ok');
24
25my $reply_to = sprintf '%s:1', $frame->headers->{session};
26ok($frame->headers->{session}, 'got a session');
27ok(length $reply_to > 2, 'valid-looking reply_to queue');
28
29ok($stomp->subscribe( { destination => '/temp-queue/reply' } ), 'subscribe to temp queue');
30
31my $message = {
32 payload => { foo => 1, bar => 2 },
33 reply_to => $reply_to,
34 type => 'testaction',
35 };
36my $text = Dump($message);
37ok($text, 'compose message');
38
39$stomp->send( { destination => '/queue/testcontroller', body => $text } );
40
41my $reply_frame = $stomp->receive_frame();
42ok($reply_frame, 'got a reply');
43ok($reply_frame->headers->{destination} eq "/remote-temp-queue/$reply_to", 'came to correct temp queue');
44ok($reply_frame->body, 'has a body');
45
46my $response = Load($reply_frame->body);
47ok($response, 'YAML response ok');
48ok($response->{type} eq 'testaction_response', 'correct type');
49
50ok($stomp->disconnect, 'disconnected');
51