1Net::DBus::Test::MockCoUnsneerctCioonnt(r3i)buted Perl DNoectu:m:eDnBtuast:i:oTnest::MockConnection(3)
2
3
4

NAME

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

SYNOPSIS

10         use Net::DBus;
11
12         my $bus = Net::DBus->test
13
14         # Register a service, and the objec to be tested
15         use MyObject
16         my $service = $bus->export_service("org.example.MyService");
17         my $object = MyObject->new($service);
18
19         # Acquire the service & do tests
20         my $remote_service = $bus->get_service('org.example.MyService');
21         my $remote_object = $service->get_object("/org/example/MyObjct");
22
23         # This traverses the mock connection, eventually
24         # invoking 'testSomething' on the $object above.
25         $remote_object->testSomething()
26

DESCRIPTION

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

METHODS

36       my $con = Net::DBus::Test::MockConnection->new()
37           Create a new mock connection object instance. It is not usually
38           neccessary to create instances of this object directly, instead the
39           "test" method on the Net::DBus object can be used to get a handle
40           to a test bus.
41
42       $con->send($message)
43           Send a message over the mock connection. If the message is a method
44           call, it will be dispatched straight to any corresponding mock
45           object registered. If the mesage is an error or method return it
46           will be made available as a return value for the
47           "send_with_reply_and_block" method. If the message is a signal it
48           will be queued up for processing by the "dispatch" method.
49
50       $bus->request_name($service_name)
51           Pretend to send a request to the bus registering the well known
52           name specified in the $service_name parameter. In reality this is
53           just a no-op giving the impression that the name was successfully
54           registered.
55
56       my $reply = $con->send_with_reply_and_block($msg)
57           Send a message over the mock connection and wait for a reply. The
58           $msg should be an instance of "Net::DBus::Binding::Message::Method‐
59           Call" and the return $reply will be an instance of
60           "Net::DBus::Binding::Message::MethodReturn".  It is also possible
61           that an error will be thrown, with the thrown error being blessed
62           into the "Net::DBus::Error" class.
63
64       $con->dispatch;
65           Dispatches any pending messages in the incoming queue to their mes‐
66           sage handlers. This method should be called by test suites whenever
67           they anticipate that there are pending signals to be dealt with.
68
69       $con->add_filter($coderef);
70           Adds a filter to the connection which will be invoked whenever a
71           message is received. The $coderef should be a reference to a sub‐
72           routine, which returns a true value if the message should be fil‐
73           tered out, or a false value if the normal message dispatch should
74           be performed.
75
76       $bus->add_match($rule)
77           Register a signal match rule with the bus controller, allowing
78           matching broadcast signals to routed to this client. In reality
79           this is just a no-op giving the impression that the match was suc‐
80           cessfully registered.
81
82       $bus->remove_match($rule)
83           Unregister a signal match rule with the bus controller, preventing
84           further broadcast signals being routed to this client. In reality
85           this is just a no-op giving the impression that the match was suc‐
86           cessfully unregistered.
87
88       $con->register_object_path($path, \&handler)
89           Registers a handler for messages whose path matches that specified
90           in the $path parameter. The supplied code reference will be invoked
91           with two parameters, the connection object on which the message was
92           received, and the message to be processed (an instance of the
93           "Net::DBus::Binding::Message" class).
94
95       $con->register_fallback($path, \&handler)
96           Registers a handler for messages whose path starts with the prefix
97           specified in the $path parameter. The supplied code reference will
98           be invoked with two parameters, the connection object on which the
99           message was received, and the message to be processed (an instance
100           of the "Net::DBus::Binding::Message" class).
101
102       $con->unregister_object_path($path)
103           Unregisters the handler associated with the object path $path. The
104           handler would previously have been registered with the "regis‐
105           ter_object_path" or "register_fallback" methods.
106
107       my $msg = $con->make_error_message($replyto, $name, $description)
108           Creates a new message, representing an error which occurred during
109           the handling of the method call object passed in as the $replyto
110           parameter. The $name parameter is the formal name of the error con‐
111           dition, while the $description is a short piece of text giving more
112           specific information on the error.
113
114       my $call = $con->make_method_call_message( $service_name, $object_path,
115       $interface, $method_name);
116           Create a message representing a call on the object located at the
117           path $object_path within the client owning the well-known name
118           given by $service_name. The method to be invoked has the name
119           $method_name within the interface specified by the $interface
120           parameter.
121
122       my $msg = $con->make_method_return_message($replyto)
123           Create a message representing a reply to the method call message
124           passed in the $replyto parameter.
125
126       my $msg = $con->make_signal_message($object_path, $interface, $sig‐
127       nal_name);
128           Creates a new message, representing a signal [to be] emitted by the
129           object located under the path given by the $object_path parameter.
130           The name of the signal is given by the $signal_name parameter, and
131           is scoped to the interface given by the $interface parameter.
132

BUGS

134       It doesn't completely replicate the API of Net::DBus::Binding::Connec‐
135       tion, merely enough to make the high level bindings work in a test sce‐
136       nario.
137

SEE ALSO

139       Net::DBus, Net::DBus::Test::MockObject, Net::DBus::Binding::Connection,
140       <http://www.mockobjects.com/Faq.html>
141
143       Copyright 2005 Daniel Berrange <dan@berrange.com>
144
145
146
147perl v5.8.8                       2008-02-20Net::DBus::Test::MockConnection(3)
Impressum