Derived from Catalyst::Test, this module provides a way to run tests
against message-driven Catalyst applications - those with
Catalyst::Controller::MessageDriven-based controllers, and expect to
-run with Catalyst::Engine::Stomp.
+run with Catalyst::Engine::Stomp.
=head1 SYNOPSIS
=head2 request(queue, message)
This function accepts a queue and a message, and runs the request in
-that context. Returns a response object.
+that context. Returns a response object.
=head1 TODO
my $app = $class->run();
$request = sub { message_driven_request( $app, @_ ) };
}
-
+
return {
request => $request,
};
$request->content($req_message);
$request->content_length(length $req_message);
$request->content_type('application/octet-stream');
-
+
my $response;
$app->handle_request($request, \$response);
}
1;
+
+use strict;
+use warnings;
use Test::More;
# Tests which expect a STOMP server like ActiveMQ to exist on
use Data::Dumper;
use FindBin;
-use lib "$FindBin::Bin";
-require 'server.pl';
+use lib "$FindBin::Bin/lib";
+use TestServer;
+
+my $stomp = start_server();
plan tests => 11;
+use strict;
+use warnings;
use Test::More;
# Tests which expect a STOMP server like ActiveMQ to exist on
# localhost:61613, which is what you get if you just get the ActiveMQ
# distro and run its out-of-the-box config.
-use Net::Stomp;
use YAML::XS qw/ Dump Load /;
use Data::Dumper;
use FindBin;
-use lib "$FindBin::Bin";
-require 'server.pl';
+use lib "$FindBin::Bin/lib";
+use TestServer;
+
+my $stomp = start_server();
plan tests => 12;
+use strict;
+use warnings;
use Test::More;
# Tests which expect a STOMP server like ActiveMQ to exist on
# localhost:61613, which is what you get if you just get the ActiveMQ
# distro and run its out-of-the-box config.
-use Net::Stomp;
-
eval {
use JSON;
};
if ($@) {
plan 'skip_all' => 'JSON not installed, skipping JSON-format test';
+ exit;
}
use FindBin;
-use lib "$FindBin::Bin";
-require 'server.pl';
+use lib "$FindBin::Bin/lib";
+use TestServer;
+
+my $stomp = start_server();
plan tests => 11;
use strict;
use warnings;
-use Test::More tests => 6;
+use Test::More tests => 5;
use FindBin;
use lib "$FindBin::Bin/../testapp/lib";
-BEGIN { use_ok 'Catalyst::Test::MessageDriven' or die;
- use_ok 'StompTestApp' or die; };
+BEGIN {
+ use_ok 'Catalyst::Test::MessageDriven', 'StompTestApp' or die;
+};
# successful request - type is minimum attributes
my $req = "---\ntype: ping\n";
--- /dev/null
+package StompRole;
+use Moose::Role;
+use namespace::autoclean;
+
+after 'disconnect' => sub {
+ delete shift->{___activemq};
+};
+
+package TestServer;
+use strict;
+use warnings;
+use Alien::ActiveMQ;
+use Test::More;
+use Exporter qw/import/;
+
+our $ACTIVEMQ_VERSION = '5.2.0';
+
+our @EXPORT = qw/ start_server /;
+
+sub start_server {
+ my ($mq, $stomp);
+ eval {
+ $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
+ };
+ if ($@) {
+
+ unless (Alien::ActiveMQ->is_version_installed($ACTIVEMQ_VERSION)) {
+ plan 'skip_all' => 'No ActiveMQ server installed by Alien::ActiveMQ, try running the "install-activemq" command';
+ exit;
+ }
+
+ $mq = Alien::ActiveMQ->run_server($ACTIVEMQ_VERSION);
+
+ eval {
+ $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
+ };
+ if ($@) {
+ plan 'skip_all' => 'No ActiveMQ server listening on 61613: ' . $@;
+ exit;
+ }
+ }
+
+ $SIG{CHLD} = 'IGNORE';
+ unless (fork()) {
+ system("$^X -Ilib -Itestapp/lib testapp/script/stomptestapp_stomp.pl --oneshot");
+ exit 0;
+ }
+ print STDERR "server started, waiting for spinup...";
+ sleep 20;
+
+ $stomp->{___activemq} = $mq if $mq;
+ StompRole->meta->apply($stomp);
+ return $stomp;
+}
+
+++ /dev/null
-use Alien::ActiveMQ;
-my $ACTIVEMQ_VERSION = '5.2.0';
-
-eval {
- $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
-};
-if ($@) {
-
- unless (Alien::ActiveMQ->is_version_installed($ACTIVEMQ_VERSION)) {
- plan 'skip_all' => 'No ActiveMQ server installed by Alien::ActiveMQ, try running the "install-activemq" command';
- exit;
- }
-
- $mq = Alien::ActiveMQ->run_server($ACTIVEMQ_VERSION);
-
- eval {
- $stomp = Net::Stomp->new( { hostname => 'localhost', port => 61613 } );
- };
- if ($@) {
- plan 'skip_all' => 'No ActiveMQ server listening on 61613: ' . $@;
- exit;
- }
-}
-
-$SIG{CHLD} = 'IGNORE';
-unless (fork()) {
- system("$^X -Ilib -Itestapp/lib testapp/script/stomptestapp_stomp.pl --oneshot");
- exit 0;
-}
-print STDERR "server started, waiting for spinup...";
-sleep 20;
-