/[notice-sender]/trunk/t/2_soap.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/t/2_soap.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93 - (show annotations)
Tue Dec 19 15:04:05 2006 UTC (13 years, 9 months ago) by dpavlin
File MIME type: application/x-troff
File size: 4792 byte(s)
added verbose to send_queued_messages so that SOAP call (SendTest, used for tests) doesn't
produce any output (and thus confuse SOAP CGI server)
1 #!/usr/bin/perl -w
2
3 use strict;
4 use blib;
5
6 use Test::More tests => 44;
7
8 BEGIN {
9 use_ok('Nos');
10 use_ok('SOAP::Transport::HTTP');
11 use_ok('SOAP::Lite');
12 use_ok('Cwd');
13 };
14
15 use Data::Dump qw/dump/;
16
17 my $debug = 0;
18 my $list_name = 'SOAP test';
19
20 $debug = 1 if (@ARGV);
21
22 my $aliases = Cwd::abs_path($0);
23 $aliases =~ s#/[^/]*$#/#;
24 $aliases .= 'aliases';
25
26 ok($aliases, "using aliases file $aliases");
27
28 ok(my $nos = new Nos::SOAP(
29 'dsn' => 'dbi:Pg:dbname=notices',
30 'aliases' => $aliases,
31 ), "new Nos::SOAP");
32
33 ok(my $daemon = new SOAP::Transport::HTTP::Daemon(LocalAddr => 'localhost')->dispatch_to('Nos::SOAP'), "SOAP daemon");
34
35 # start server
36
37 my $pid;
38 unless ($pid = fork) {
39
40 local $SIG{HUP} = sub {
41 diag "exiting SOAP server";
42 exit 0;
43 };
44
45 diag "SOAP server at ", $daemon->url;
46 $daemon->handle;
47
48 }
49
50 diag "child pid: $pid";
51
52 my $soap = SOAP::Lite
53 ->readable(1)
54 ->uri('http://localhost/Nos/SOAP/')
55 ->proxy($daemon->url);
56
57 $soap->on_debug(sub{print "## ", join("\n## ",@_), "\n";}) if ($debug);
58
59 # CreateList
60
61 ok(my $list_id = $soap->CreateList({
62 list => $list_name,
63 from => 'SOAP list',
64 email => 'soap-test@example.com',
65 })->result, "CreateList named");
66
67 ok(my $list_id2 = $soap->CreateList(
68 $list_name,
69 'SOAP test list',
70 'soap-test@example.com',
71 )->result, "CreateList positional");
72
73 cmp_ok($list_id, '==', $list_id2, "list_id $list_id");
74
75
76 # AddMemberToList
77
78 ok(my $member_id = $soap->AddMemberToList({
79 list => $list_name,
80 email => 'dpavlin@rot13.org',
81 name => 'Dobrica Pavlinusic',
82 ext_id => 42,
83 })->result, "AddMemberToList named");
84
85 ok(my $member_id2 = $soap->AddMemberToList(
86 $list_name,
87 'dpavlin@rot13.org',
88 'Dobrica Pavlinusic',
89 42,
90 )->result, "AddMemberToList positional");
91
92 cmp_ok($member_id, '==', $member_id2, "member_id: $member_id");
93
94
95 ok($member_id = $soap->AddMemberToList({
96 list => $list_name,
97 email => 'nobody@example.com',
98 })->result, "AddMemberToList named");
99
100 ok($member_id2 = $soap->AddMemberToList(
101 $list_name,
102 'nobody@example.com',
103 )->result, "AddMemberToList positional");
104
105 cmp_ok($member_id, '==', $member_id2, "member_id: $member_id");
106
107 # AddMessageToList
108
109 my $msg = 'To: member@example.com
110 From: mylist@example.com
111 Subject: text
112
113 This is a dummy test
114 ';
115
116 ok(my $message_id = $soap->AddMessageToList({
117 list => $list_name,
118 message => $msg,
119 })->result, "AddMessageToList named");
120
121 ok(my $message_id2 = $soap->AddMessageToList(
122 $list_name,
123 $msg,
124 )->result, "AddMessageToList positional");
125
126 cmp_ok($message_id, '==', $message_id2, "message_id: $message_id");
127
128 ok(my $message_id3 = $soap->AddMessageToList({
129 list => $list_name,
130 message => "$msg\n and another one",
131 })->result, "AddMessageToList named");
132
133 cmp_ok($message_id, '!=', $message_id3, "new message_id: $message_id3");
134
135 # ListMembers
136
137 ok(my $arr = $soap->ListMembers({
138 list => $list_name,
139 })->result, "ListMembers named");
140
141 ok(my $arr2 = $soap->ListMembers(
142 $list_name,
143 )->result, "ListMembers positional");
144
145 eq_array($arr, $arr2, "members lists same");
146
147 cmp_ok($#{$arr}, '==', 1, "member count ok");
148
149 diag "arr = ", dump($arr) if ($debug);
150 cmp_ok($arr->[0]->{'name'}, 'eq', 'Dobrica Pavlinusic', "name");
151 cmp_ok($arr->[0]->{'email'}, 'eq', 'dpavlin@rot13.org', "email");
152
153 cmp_ok($arr->[1]->{'email'}, 'eq', 'nobody@example.com', "email");
154
155 # test sending
156
157 ok(my $sent = $soap->SendTest({
158 list => $list_name,
159 driver => 'Test',
160 sleep => 0,
161 })->result, "send_queued_messages for $list_name");
162
163 cmp_ok($sent, '==', 4, 'messages sent');
164
165 # replay to messages
166
167 ok(my $received = $soap->MessagesReceived(
168 list => $list_name
169 )->result, "MessagesReceived for $list_name");
170
171 diag "received = ", dump($received) if ($debug);
172 cmp_ok( $received, '==', 0, 'no messages' );
173
174 # DeleteMember
175
176 ok($soap->DeleteMemberFromList({
177 list => $list_name,
178 email => $arr->[0]->{'email'},
179 })->result, "DeleteMemberFromList ".$arr->[0]->{'email'});
180
181
182 ok($arr = $soap->ListMembers({
183 list => $list_name,
184 })->result, "ListMembers named");
185
186 cmp_ok($#{$arr}, '==', 0, "member deleted");
187
188 # DropList
189
190 ok($soap->DropList({
191 list => $list_name,
192 })->result, "DropList named");
193
194 ok(my $has_members = $soap->ListMembers({
195 list => $list_name,
196 })->result, "ListMembers for $list_name");
197
198 cmp_ok($#{$has_members}, '==', -1, "ok, no members");
199
200 ok($list_id = $soap->CreateList({
201 list => $list_name,
202 from => 'SOAP list',
203 email => 'soap-test@example.com',
204 })->result, "CreateList $list_name (recreated)");
205
206 ok($soap->DropList(
207 $list_name,
208 )->result, "DropList positional");
209
210 ok($has_members = $soap->ListMembers({
211 list => $list_name,
212 })->result, "ListMembers for $list_name");
213
214 cmp_ok($#{$has_members}, '==', -1, "ok, no members");
215
216 diag "I should add e-mail send test!";
217
218 # kill server
219
220 ok(kill('HUP' => $pid), "kill $pid");
221
222 ok(waitpid($pid,0), "waitpid");
223
224 ok(! kill(0, $pid), "child dead");
225
226 exit 1;
227

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26