Commit | Line | Data |
bf8937b7 |
1 | use Test::More; |
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 | |
7 | use Net::Stomp; |
8 | use YAML::XS qw/ Dump Load /; |
9 | use Data::Dumper; |
10 | |
11 | use FindBin; |
12 | use lib "$FindBin::Bin"; |
13 | require 'server.pl'; |
14 | |
15 | plan tests => 11; |
16 | |
17 | my $frame = $stomp->connect(); |
18 | ok($frame, 'connect to MQ server ok'); |
19 | |
20 | my $reply_to = sprintf '%s:1', $frame->headers->{session}; |
21 | ok($frame->headers->{session}, 'got a session'); |
22 | ok(length $reply_to > 2, 'valid-looking reply_to queue'); |
23 | |
24 | ok($stomp->subscribe( { destination => '/temp-queue/reply' } ), 'subscribe to temp queue'); |
25 | |
26 | my $message = { |
27 | payload => { foo => 1, bar => 2 }, |
28 | reply_to => $reply_to, |
29 | type => 'testaction', |
30 | }; |
31 | my $text = Dump($message); |
32 | ok($text, 'compose message'); |
33 | |
34 | $stomp->send( { destination => '/queue/testcontroller', body => $text } ); |
35 | |
36 | my $reply_frame = $stomp->receive_frame(); |
37 | ok($reply_frame, 'got a reply'); |
38 | ok($reply_frame->headers->{destination} eq "/remote-temp-queue/$reply_to", 'came to correct temp queue'); |
39 | ok($reply_frame->body, 'has a body'); |
40 | |
41 | my $response = Load($reply_frame->body); |
42 | ok($response, 'YAML response ok'); |
43 | ok($response->{type} eq 'testaction_response', 'correct type'); |
44 | |
45 | ok($stomp->disconnect, 'disconnected'); |
46 | |