NAME
Test::Plack::Handler::Stomp - testing library for Plack::Handler::Stomp
VERSION
version 1.06_01
SYNOPSIS
my $t = Test::Plack::Handler::Stomp->new();
$t->set_arg(
subscriptions => [
{ destination => '/queue/input_queue',
path_info => '/input_queue', },
],
);
$t->clear_frames_to_receive;
$t->queue_frame_to_receive(Net::Stomp::Frame->new({
command => 'MESSAGE',
headers => {
destination => '/queue/input_queue',
subscription => 0,
type => 'my_type',
'message-id' => 356,
},
body => '{"foo":"bar"}',
}));
$t->handler->run($app);
check($t->frames_sent);
DESCRIPTION
Testing a PSGI application that expects JMS/STOMP messages can be a pain. This library helps reduce that pain.
It wraps a Plack::Handler::Stomp, connecting it to a Test::Plack::Handler::Stomp::FakeStomp instead of a real STOMP connection, and allows you to inspect everything that happens to the connection.
ATTRIBUTES
handler_args
Hashref, arguments to pass to Plack::Handler::Stomp's constructor. You can add to this via the "set_arg" method. Defaults to { one_shot => 1 }
, to avoid having Plack::Handler::Stomp loop forever.
handler
A Plack::Handler::Stomp instance. It's built on-demand via "setup_handler". You can clear it with "clear_handler" to have it rebuilt (for example, if you have changed "handler_args")
frames_sent
Arrayref of Net::Stomp::Frame objects that Plack::Handler::Stomp sent. Can be edited via "queue_sent_frame", "sent_frames_count", "clear_sent_frames". Defaults to the empty array.
frames_to_receive
Arrayref of Net::Stomp::Frame objects that Plack::Handler::Stomp will consume. Can be edited via "queue_frame_to_receive", "next_frame_to_receive", "frames_left_to_receive", "clear_frames_to_receive".
Defaults to an array with a single ERROR
frame.
constructor_calls
Arrayref of whatever was passed to the Test::Plack::Handler::Stomp::FakeStomp constructor. Can be edited via "queue_constructor_call", "constructor_calls_count", "clear_constructor_calls".
connection_calls
Arrayref of whatever was passed to the Test::Plack::Handler::Stomp::FakeStomp connect
method. Can be edited via "queue_connection_call", "connection_calls_count", "clear_connection_calls".
disconnection_calls
Arrayref of whatever was passed to the Test::Plack::Handler::Stomp::FakeStomp disconnect
method. Can be edited via "queue_disconnection_call", "disconnection_calls_count", "clear_disconnection_calls".
subscription_calls
Arrayref of whatever was passed to the Test::Plack::Handler::Stomp::FakeStomp subscribe
method. Can be edited via "queue_subscription_call", "subscription_calls_count", "clear_subscription_calls".
unsubscription_calls
Arrayref of whatever was passed to the Test::Plack::Handler::Stomp::FakeStomp unsubscribe
method. Can be edited via "queue_unsubscription_call", "unsubscription_calls_count", "clear_unsubscription_calls".
log_messages
Arrayref of whatever Plack::Handler::Stomp logs. Each element is a pair [ $level, $message ]
. Can be edited via "add_log_message", "log_messages_count", "clear_log_messages".
METHODS
set_arg
$handler->set_arg(foo=>'bar',some=>'thing');
Sets arguments for Plack::Handler::Stomp's constructor, see /handler_args
.
clear_handler
Destroys the "handler", forcing it to be rebuilt next time it's needed.
queue_sent_frame
Adds a frame to the end of "frames_sent".
sent_frames_count
Returns the number of elements in "frames_sent".
clear_sent_frames
Removes all elements from "frames_sent".
queue_frame_to_receive
Adds a frame to the end of "frames_to_receive".
next_frame_to_receive
Removes a frame from the beginning of "frames_to_receive" and returns it.
frames_left_to_receive
Returns the number of elements in "frames_to_receive".
clear_frames_to_receive
Removes all elements from "frames_to_receive".
queue_constructor_call
Adds a hashref to the end of "constructor_calls".
constructor_calls_count
Returns the number of elements in "constructor_calls".
clear_constructor_calls
Removes all elements from "constructor_calls".
queue_connection_call
Adds a hashref to the end of "connection_calls".
connection_calls_count
Returns the number of elements in "connection_calls".
clear_connection_calls
Removes all elements from "connection_calls".
queue_disconnection_call
Adds a hashref to the end of "disconnection_calls".
disconnection_calls_count
Returns the number of elements in "disconnection_calls".
clear_disconnection_calls
Removes all elements from "disconnection_calls".
queue_subscription_call
Adds a hashref to the end of "subscription_calls".
subscription_calls_count
Returns the number of elements in "subscription_calls".
clear_subscription_calls
Removes all elements from "subscription_calls".
queue_unsubscription_call
Adds a hashref to the end of "unsubscription_calls".
unsubscription_calls_count
Returns the number of elements in "unsubscription_calls".
clear_unsubscription_calls
Removes all elements from "unsubscription_calls".
add_log_message
Adds a pair to the end of "log_messages".
log_messages_count
Returns the number of elements in "log_messages".
clear_log_messages
Removes all elements from "log_messages".
setup_handler
Constructs a Plack::Handler::Stomp, setting it up to capture logging, passing "handler_args", and setting a connection_builder
that returns a Test::Plack::Handler::Stomp::FakeStomp with all the callbacks set to accumulate calls in this object.
debug
info
warn
error
Logger delegate methods, the handler returned by "setup_handler" uses these to log. These methods accumulate log messages by calling "add_log_message".
clear_calls_and_queues
Calls the clearer for all the queue / accumulator attributes ("frames_sent", "frames_to_receive", "constructor_calls", "connection_calls", "disconnection_calls", "subscription_calls", "unsubscription_calls", "log_messages")
AUTHOR
Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Net-a-porter.com.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.