1Net::DBus::Test::MockObUjseecrt(C3o)ntributed Perl DocumNeentt:a:tDiBouns::Test::MockObject(3)
2
3
4

NAME

6       Net::DBus::Test::MockObject - Fake an object from the bus for unit
7       testing
8

SYNOPSIS

10         use Net::DBus;
11         use Net::DBus::Test::MockObject;
12
13         my $bus = Net::DBus->test
14
15         # Lets fake presence of HAL...
16
17         # First we need to define the service
18         my $service = $bus->export_service("org.freedesktop.Hal");
19
20         # Then create a mock object
21         my $object = Net::DBus::Test::MockObject->new($service,
22                                                       "/org/freedesktop/Hal/Manager");
23
24         # Fake the 'GetAllDevices' method
25         $object->seed_action("org.freedesktop.Hal.Manager",
26                              "GetAllDevices",
27                              reply => {
28                                return => [ "/org/freedesktop/Hal/devices/computer_i8042_Aux_Port",
29                                            "/org/freedesktop/Hal/devices/computer_i8042_Aux_Port_logicaldev_input",
30                                            "/org/freedesktop/Hal/devices/computer_i8042_Kbd_Port",
31                                            "/org/freedesktop/Hal/devices/computer_i8042_Kbd_Port_logicaldev_input"
32                                ],
33                              });
34
35         # Now can test any class which calls out to 'GetAllDevices' in HAL
36         ....test stuff....
37

DESCRIPTION

39       This provides an alternate for Net::DBus::Object to enable bus objects
40       to be quickly mocked up, thus facilitating creation of unit tests for
41       services which may need to call out to objects provided by 3rd party
42       services on the bus. It is typically used as a companion to the
43       Net::DBus::MockBus object, to enable complex services to be tested
44       without actually starting a real bus.
45
46       !!!!! WARNING !!!
47
48       This object & its APIs should be considered very experimental at this
49       point in time, and no guarentees about future API compatability are
50       provided what-so-ever. Comments & suggestions on how to evolve this
51       framework are, however, welcome & encouraged.
52

METHODS

54       my $object = Net::DBus::Test::MockObject->new($service, $path, $inter‐
55       face);
56           Create a new mock object, attaching to the service defined by the
57           $service parameter. This would be an instance of the
58           Net::DBus::Service object. The $path parameter defines the object
59           path at which to attach this mock object, and $interface defines
60           the interface it will support.
61
62       my $service = $object->get_service
63           Retrieves the Net::DBus::Service object within which this object is
64           exported.
65
66       my $path = $object->get_object_path
67           Retrieves the path under which this object is exported
68
69       my $msg = $object->get_last_message
70           Retrieves the last message processed by this object. The returned
71           object is an instance of Net::DBus::Binding::Message
72
73       my $sig = $object->get_last_message_signature
74           Retrieves the type signature of the last processed message.
75
76       my $value = $object->get_last_message_param
77           Returns the first value supplied as an argument to the last pro‐
78           cessed message.
79
80       my @values = $object->get_last_message_param_list
81           Returns a list of all the values supplied as arguments to the last
82           processed message.
83
84       $object->seed_action($interface, $method, %action);
85           Registers an action to be performed when a message corresponding to
86           the method $method within the interface $interface is received. The
87           %action parameter can have a number of possible keys set:
88
89           signals
90               Causes a signal to be emitted when the method is invoked. The
91               value associated with this key should be an instance of the
92               Net::DBus::Binding::Message::Signal class.
93
94           error
95               Causes an error to be generated when the method is invoked. The
96               value associated with this key should be a hash reference, with
97               two elements. The first, "name", giving the error name, and the
98               second, "description", providing the descriptive text.
99
100           reply
101               Causes a normal method return to be generated. The value asso‐
102               ciated with this key should be an array reference, whose ele‐
103               ments are the values to be returned by the method.
104

BUGS

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

SEE ALSO

110       Net::DBus, Net::DBus::Object, Net::DBus::Test::MockConnection,
111       <http://www.mockobjects.com/Faq.html>
112
114       Copyright 2005 Daniel Berrange <dan@berrange.com>
115
116
117
118perl v5.8.8                       2008-02-20    Net::DBus::Test::MockObject(3)
Impressum