NAME
Net::DBus::Test::MockConnection - Fake a connection to the bus unit testing
SYNOPSIS
use Net::DBus;
my $bus = Net::DBus->test
# Register a service, and the objec to be tested
use MyObject
my $service = $bus->export_service("org.example.MyService");
my $object = MyObject->new($service);
# Acquire the service & do tests
my $remote_service = $bus->get_service('org.example.MyService');
my $remote_object = $service->get_object("/org/example/MyObjct");
# This traverses the mock connection, eventually
# invoking 'testSomething' on the $object above.
$remote_object->testSomething()
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 neccessary to create instances of this object directly, instead the
testmethod 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
send_with_reply_and_blockmethod. If the message is a signal it will be queued up for processing by thedispatchmethod. - $bus->request_name($service_name)
-
Pretend to send a request to the bus registering the well known name specified in the
$service_nameparameter. 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
$msgshould be an instance ofNet::DBus::Binding::Message::MethodCalland the return$replywill be an instance ofNet::DBus::Binding::Message::MethodReturn. It is also possible that an error will be thrown, with the thrown error being blessed into theNet::DBus::Errorclass. - $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
$coderefshould 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
$pathparameter. 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 theNet::DBus::Binding::Messageclass). - $con->register_fallback($path, \&handler)
-
Registers a handler for messages whose path starts with the prefix specified in the
$pathparameter. 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 theNet::DBus::Binding::Messageclass). - $con->unregister_object_path($path)
-
Unregisters the handler associated with the object path
$path. The handler would previously have been registered with theregister_object_pathorregister_fallbackmethods.
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.
SEE ALSO
Net::DBus, Net::DBus::Test::MockObject, Net::DBus::Binding::Connection, http://www.mockobjects.com/Faq.html
COPYRIGHT
Copyright 2005 Daniel Berrange <dan@berrange.com>