Codex

Net::DBus::Test::MockConnection

Section: User Contributed Perl Documentation (3pm)

Updated: 2014-08-15

Index?action=index Return to Main Contents


NAME

Net::DBus::Test::MockConnection - Fake a connection to the bus unit testing

SYNOPSIS

DESCRIPTION

This object provides a fake implementation of the Net::DBus::Binding::Connection enabling a pure 'in-memory' message bus to be mocked up. This is intended to facilitate creation of unit tests for services which would otherwise need to call out to other object on a live message bus. It is used as a companion to the Net::DBus::Test::MockObject module which is how fake objects are to be provided on the fake bus.

METHODS

my $con = Net
:DBus::Test::MockConnection->new():Create a new mock connection object instance. It is not usually necessary to create instances of this object directly, instead the method on the Net::DBus object can be used to get a handle to a test bus.:
$con->send($message)
Send a message over the mock connection. If the message is a method call, it will be dispatched straight to any corresponding mock object registered. If the mesage is an error or method return it will be made available as a return value for the method. If the message is a signal it will be queued up for processing by the method.:
$bus->request_name($service_name)
Pretend to send a request to the bus registering the well known name specified in the parameter. In reality this is just a no-op giving the impression that the name was successfully registered.:
my $reply = $con->send_with_reply_and_block($msg)
Send a message over the mock connection and wait for a reply. The should be an instance of and the return will be an instance of . It is also possible that an error will be thrown, with the thrown error being blessed into the class.:
$con->dispatch;
Dispatches any pending messages in the incoming queue to their message handlers. This method should be called by test suites whenever they anticipate that there are pending signals to be dealt with.:
$con->add_filter($coderef);
Adds a filter to the connection which will be invoked whenever a message is received. The should be a reference to a subroutine, which returns a true value if the message should be filtered out, or a false value if the normal message dispatch should be performed.:
$bus->add_match($rule)
Register a signal match rule with the bus controller, allowing matching broadcast signals to routed to this client. In reality this is just a no-op giving the impression that the match was successfully registered.:
$bus->remove_match($rule)
Unregister a signal match rule with the bus controller, preventing further broadcast signals being routed to this client. In reality this is just a no-op giving the impression that the match was successfully unregistered.:
$con->register_object_path($path, \&handler)
Registers a handler for messages whose path matches that specified in the parameter. The supplied code reference will be invoked with two parameters, the connection object on which the message was received, and the message to be processed (an instance of the class).:
$con->register_fallback($path, \&handler)
Registers a handler for messages whose path starts with the prefix specified in the parameter. The supplied code reference will be invoked with two parameters, the connection object on which the message was received, and the message to be processed (an instance of the class).:
$con->unregister_object_path($path)
Unregisters the handler associated with the object path . The handler would previously have been registered with the or methods.:
my $msg = $con->make_error_message($replyto, $name, $description)
Creates a new message, representing an error which occurred during the handling of the method call object passed in as the parameter. The parameter is the formal name of the error condition, while the is a short piece of text giving more specific information on the error.:
my $call = $con->make_method_call_message( $service_name, $object_path, $interface, $method_name);
Create a message representing a call on the object located at the path within the client owning the well-known name given by . The method to be invoked has the name within the interface specified by the parameter.:
my $msg = $con->make_method_return_message($replyto)
Create a message representing a reply to the method call message passed in the parameter.:
my $msg = $con->make_signal_message($object_path, $interface, $signal_name);
Creates a new message, representing a signal [to be] emitted by the object located under the path given by the parameter. The name of the signal is given by the parameter, and is scoped to the interface given by the parameter.:

BUGS

It doesn't completely replicate the API of Net::DBus::Binding::Connection, merely enough to make the high level bindings work in a test scenario.

AUTHOR

Daniel P. Berrange

COPYRIGHT

Copyright (C) 2005-2009 Daniel P. Berrange

SEE ALSO

Net::DBus, Net::DBus::Test::MockObject, Net::DBus::Binding::Connection, <http://www.mockobjects.com/Faq.html>


Index

NAME

SYNOPSIS

DESCRIPTION

METHODS

BUGS

AUTHOR

COPYRIGHT

SEE ALSO