Commit | Line | Data |
5c4a7793 |
1 | use 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 | |
7 | use Net::Stomp; |
8 | use YAML::XS qw/ Dump Load /; |
9 | use Data::Dumper; |
10 | |
5c4a7793 |
11 | my $stomp; |
12 | eval { |
13 | $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } ); |
14 | }; |
15 | if ($@) { |
16 | plan 'skip_all' => 'No ActiveMQ server listening on 61613: ' . $@; |
17 | exit; |
18 | } |
19 | else { |
20 | plan tests => 12; |
21 | } |
22 | |
0a663589 |
23 | # First fire off the server |
5c4a7793 |
24 | $SIG{CHLD} = 'IGNORE'; |
ff3b0412 |
25 | unless (fork()) { |
26 | system("$^X -Ilib -Itestapp/lib testapp/script/testapp_stomp.pl --oneshot"); |
27 | exit 0; |
28 | } |
5c4a7793 |
29 | sleep 30; |
0a663589 |
30 | |
31 | # Now be a client to that server |
32 | |
0a663589 |
33 | ok($stomp, 'Net::Stomp object'); |
34 | |
35 | my $frame = $stomp->connect(); |
36 | ok($frame, 'connect to MQ server ok'); |
37 | |
38 | my $reply_to = sprintf '%s:1', $frame->headers->{session}; |
39 | ok($frame->headers->{session}, 'got a session'); |
40 | ok(length $reply_to > 2, 'valid-looking reply_to queue'); |
41 | |
42 | ok($stomp->subscribe( { destination => '/temp-queue/reply' } ), 'subscribe to temp queue'); |
43 | |
44 | my $message = { |
45 | payload => { foo => 1, bar => 2 }, |
46 | reply_to => $reply_to, |
47 | type => 'testaction', |
48 | }; |
49 | my $text = Dump($message); |
50 | ok($text, 'compose message'); |
51 | |
52 | $stomp->send( { destination => '/queue/testcontroller', body => $text } ); |
53 | |
54 | my $reply_frame = $stomp->receive_frame(); |
55 | ok($reply_frame, 'got a reply'); |
56 | ok($reply_frame->headers->{destination} eq "/remote-temp-queue/$reply_to", 'came to correct temp queue'); |
57 | ok($reply_frame->body, 'has a body'); |
58 | |
59 | my $response = Load($reply_frame->body); |
60 | ok($response, 'YAML response ok'); |
61 | ok($response->{type} eq 'testaction_response', 'correct type'); |
62 | |
63 | ok($stomp->disconnect, 'disconnected'); |
64 | |