Commit | Line | Data |
0a663589 |
1 | use Test::More tests => 14; |
2 | use Test::Fork; |
3 | |
4 | # Tests which expect a STOMP server like ActiveMQ to exist on |
5 | # localhost:61613, which is what you get if you just get the ActiveMQ |
6 | # distro and run its out-of-the-box config. |
7 | |
8 | use Net::Stomp; |
9 | use YAML::XS qw/ Dump Load /; |
10 | use Data::Dumper; |
11 | |
12 | # First fire off the server |
13 | my $child_pid = fork_ok(1, sub { |
14 | ok(system("$^X -Ilib -Itestapp/lib testapp/script/testapp_stomp.pl --oneshot")); |
15 | #sleep 3; |
16 | }); |
17 | |
18 | # Now be a client to that server |
19 | |
20 | my $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } ); |
21 | ok($stomp, 'Net::Stomp object'); |
22 | |
23 | my $frame = $stomp->connect(); |
24 | ok($frame, 'connect to MQ server ok'); |
25 | |
26 | my $reply_to = sprintf '%s:1', $frame->headers->{session}; |
27 | ok($frame->headers->{session}, 'got a session'); |
28 | ok(length $reply_to > 2, 'valid-looking reply_to queue'); |
29 | |
30 | ok($stomp->subscribe( { destination => '/temp-queue/reply' } ), 'subscribe to temp queue'); |
31 | |
32 | my $message = { |
33 | payload => { foo => 1, bar => 2 }, |
34 | reply_to => $reply_to, |
35 | type => 'testaction', |
36 | }; |
37 | my $text = Dump($message); |
38 | ok($text, 'compose message'); |
39 | |
40 | $stomp->send( { destination => '/queue/testcontroller', body => $text } ); |
41 | |
42 | my $reply_frame = $stomp->receive_frame(); |
43 | ok($reply_frame, 'got a reply'); |
44 | ok($reply_frame->headers->{destination} eq "/remote-temp-queue/$reply_to", 'came to correct temp queue'); |
45 | ok($reply_frame->body, 'has a body'); |
46 | |
47 | my $response = Load($reply_frame->body); |
48 | ok($response, 'YAML response ok'); |
49 | ok($response->{type} eq 'testaction_response', 'correct type'); |
50 | |
51 | ok($stomp->disconnect, 'disconnected'); |
52 | |