OLD | NEW |
| (Empty) |
1 library googleapis_beta.pubsub.v1beta1.test; | |
2 | |
3 import "dart:core" as core; | |
4 import "dart:collection" as collection; | |
5 import "dart:async" as async; | |
6 import "dart:convert" as convert; | |
7 | |
8 import 'package:http/http.dart' as http; | |
9 import 'package:http/testing.dart' as http_testing; | |
10 import 'package:unittest/unittest.dart' as unittest; | |
11 import 'package:googleapis_beta/common/common.dart' as common; | |
12 import 'package:googleapis_beta/src/common_internal.dart' as common_internal; | |
13 import '../common/common_internal_test.dart' as common_test; | |
14 | |
15 import 'package:googleapis_beta/pubsub/v1beta1.dart' as api; | |
16 | |
17 | |
18 | |
19 buildUnnamed1170() { | |
20 var o = new core.List<core.String>(); | |
21 o.add("foo"); | |
22 o.add("foo"); | |
23 return o; | |
24 } | |
25 | |
26 checkUnnamed1170(core.List<core.String> o) { | |
27 unittest.expect(o, unittest.hasLength(2)); | |
28 unittest.expect(o[0], unittest.equals('foo')); | |
29 unittest.expect(o[1], unittest.equals('foo')); | |
30 } | |
31 | |
32 core.int buildCounterAcknowledgeRequest = 0; | |
33 buildAcknowledgeRequest() { | |
34 var o = new api.AcknowledgeRequest(); | |
35 buildCounterAcknowledgeRequest++; | |
36 if (buildCounterAcknowledgeRequest < 3) { | |
37 o.ackId = buildUnnamed1170(); | |
38 o.subscription = "foo"; | |
39 } | |
40 buildCounterAcknowledgeRequest--; | |
41 return o; | |
42 } | |
43 | |
44 checkAcknowledgeRequest(api.AcknowledgeRequest o) { | |
45 buildCounterAcknowledgeRequest++; | |
46 if (buildCounterAcknowledgeRequest < 3) { | |
47 checkUnnamed1170(o.ackId); | |
48 unittest.expect(o.subscription, unittest.equals('foo')); | |
49 } | |
50 buildCounterAcknowledgeRequest--; | |
51 } | |
52 | |
53 core.int buildCounterLabel = 0; | |
54 buildLabel() { | |
55 var o = new api.Label(); | |
56 buildCounterLabel++; | |
57 if (buildCounterLabel < 3) { | |
58 o.key = "foo"; | |
59 o.numValue = "foo"; | |
60 o.strValue = "foo"; | |
61 } | |
62 buildCounterLabel--; | |
63 return o; | |
64 } | |
65 | |
66 checkLabel(api.Label o) { | |
67 buildCounterLabel++; | |
68 if (buildCounterLabel < 3) { | |
69 unittest.expect(o.key, unittest.equals('foo')); | |
70 unittest.expect(o.numValue, unittest.equals('foo')); | |
71 unittest.expect(o.strValue, unittest.equals('foo')); | |
72 } | |
73 buildCounterLabel--; | |
74 } | |
75 | |
76 buildUnnamed1171() { | |
77 var o = new core.List<api.Subscription>(); | |
78 o.add(buildSubscription()); | |
79 o.add(buildSubscription()); | |
80 return o; | |
81 } | |
82 | |
83 checkUnnamed1171(core.List<api.Subscription> o) { | |
84 unittest.expect(o, unittest.hasLength(2)); | |
85 checkSubscription(o[0]); | |
86 checkSubscription(o[1]); | |
87 } | |
88 | |
89 core.int buildCounterListSubscriptionsResponse = 0; | |
90 buildListSubscriptionsResponse() { | |
91 var o = new api.ListSubscriptionsResponse(); | |
92 buildCounterListSubscriptionsResponse++; | |
93 if (buildCounterListSubscriptionsResponse < 3) { | |
94 o.nextPageToken = "foo"; | |
95 o.subscription = buildUnnamed1171(); | |
96 } | |
97 buildCounterListSubscriptionsResponse--; | |
98 return o; | |
99 } | |
100 | |
101 checkListSubscriptionsResponse(api.ListSubscriptionsResponse o) { | |
102 buildCounterListSubscriptionsResponse++; | |
103 if (buildCounterListSubscriptionsResponse < 3) { | |
104 unittest.expect(o.nextPageToken, unittest.equals('foo')); | |
105 checkUnnamed1171(o.subscription); | |
106 } | |
107 buildCounterListSubscriptionsResponse--; | |
108 } | |
109 | |
110 buildUnnamed1172() { | |
111 var o = new core.List<api.Topic>(); | |
112 o.add(buildTopic()); | |
113 o.add(buildTopic()); | |
114 return o; | |
115 } | |
116 | |
117 checkUnnamed1172(core.List<api.Topic> o) { | |
118 unittest.expect(o, unittest.hasLength(2)); | |
119 checkTopic(o[0]); | |
120 checkTopic(o[1]); | |
121 } | |
122 | |
123 core.int buildCounterListTopicsResponse = 0; | |
124 buildListTopicsResponse() { | |
125 var o = new api.ListTopicsResponse(); | |
126 buildCounterListTopicsResponse++; | |
127 if (buildCounterListTopicsResponse < 3) { | |
128 o.nextPageToken = "foo"; | |
129 o.topic = buildUnnamed1172(); | |
130 } | |
131 buildCounterListTopicsResponse--; | |
132 return o; | |
133 } | |
134 | |
135 checkListTopicsResponse(api.ListTopicsResponse o) { | |
136 buildCounterListTopicsResponse++; | |
137 if (buildCounterListTopicsResponse < 3) { | |
138 unittest.expect(o.nextPageToken, unittest.equals('foo')); | |
139 checkUnnamed1172(o.topic); | |
140 } | |
141 buildCounterListTopicsResponse--; | |
142 } | |
143 | |
144 core.int buildCounterModifyAckDeadlineRequest = 0; | |
145 buildModifyAckDeadlineRequest() { | |
146 var o = new api.ModifyAckDeadlineRequest(); | |
147 buildCounterModifyAckDeadlineRequest++; | |
148 if (buildCounterModifyAckDeadlineRequest < 3) { | |
149 o.ackDeadlineSeconds = 42; | |
150 o.ackId = "foo"; | |
151 o.subscription = "foo"; | |
152 } | |
153 buildCounterModifyAckDeadlineRequest--; | |
154 return o; | |
155 } | |
156 | |
157 checkModifyAckDeadlineRequest(api.ModifyAckDeadlineRequest o) { | |
158 buildCounterModifyAckDeadlineRequest++; | |
159 if (buildCounterModifyAckDeadlineRequest < 3) { | |
160 unittest.expect(o.ackDeadlineSeconds, unittest.equals(42)); | |
161 unittest.expect(o.ackId, unittest.equals('foo')); | |
162 unittest.expect(o.subscription, unittest.equals('foo')); | |
163 } | |
164 buildCounterModifyAckDeadlineRequest--; | |
165 } | |
166 | |
167 core.int buildCounterModifyPushConfigRequest = 0; | |
168 buildModifyPushConfigRequest() { | |
169 var o = new api.ModifyPushConfigRequest(); | |
170 buildCounterModifyPushConfigRequest++; | |
171 if (buildCounterModifyPushConfigRequest < 3) { | |
172 o.pushConfig = buildPushConfig(); | |
173 o.subscription = "foo"; | |
174 } | |
175 buildCounterModifyPushConfigRequest--; | |
176 return o; | |
177 } | |
178 | |
179 checkModifyPushConfigRequest(api.ModifyPushConfigRequest o) { | |
180 buildCounterModifyPushConfigRequest++; | |
181 if (buildCounterModifyPushConfigRequest < 3) { | |
182 checkPushConfig(o.pushConfig); | |
183 unittest.expect(o.subscription, unittest.equals('foo')); | |
184 } | |
185 buildCounterModifyPushConfigRequest--; | |
186 } | |
187 | |
188 core.int buildCounterPublishRequest = 0; | |
189 buildPublishRequest() { | |
190 var o = new api.PublishRequest(); | |
191 buildCounterPublishRequest++; | |
192 if (buildCounterPublishRequest < 3) { | |
193 o.message = buildPubsubMessage(); | |
194 o.topic = "foo"; | |
195 } | |
196 buildCounterPublishRequest--; | |
197 return o; | |
198 } | |
199 | |
200 checkPublishRequest(api.PublishRequest o) { | |
201 buildCounterPublishRequest++; | |
202 if (buildCounterPublishRequest < 3) { | |
203 checkPubsubMessage(o.message); | |
204 unittest.expect(o.topic, unittest.equals('foo')); | |
205 } | |
206 buildCounterPublishRequest--; | |
207 } | |
208 | |
209 core.int buildCounterPubsubEvent = 0; | |
210 buildPubsubEvent() { | |
211 var o = new api.PubsubEvent(); | |
212 buildCounterPubsubEvent++; | |
213 if (buildCounterPubsubEvent < 3) { | |
214 o.deleted = true; | |
215 o.message = buildPubsubMessage(); | |
216 o.subscription = "foo"; | |
217 o.truncated = true; | |
218 } | |
219 buildCounterPubsubEvent--; | |
220 return o; | |
221 } | |
222 | |
223 checkPubsubEvent(api.PubsubEvent o) { | |
224 buildCounterPubsubEvent++; | |
225 if (buildCounterPubsubEvent < 3) { | |
226 unittest.expect(o.deleted, unittest.isTrue); | |
227 checkPubsubMessage(o.message); | |
228 unittest.expect(o.subscription, unittest.equals('foo')); | |
229 unittest.expect(o.truncated, unittest.isTrue); | |
230 } | |
231 buildCounterPubsubEvent--; | |
232 } | |
233 | |
234 buildUnnamed1173() { | |
235 var o = new core.List<api.Label>(); | |
236 o.add(buildLabel()); | |
237 o.add(buildLabel()); | |
238 return o; | |
239 } | |
240 | |
241 checkUnnamed1173(core.List<api.Label> o) { | |
242 unittest.expect(o, unittest.hasLength(2)); | |
243 checkLabel(o[0]); | |
244 checkLabel(o[1]); | |
245 } | |
246 | |
247 core.int buildCounterPubsubMessage = 0; | |
248 buildPubsubMessage() { | |
249 var o = new api.PubsubMessage(); | |
250 buildCounterPubsubMessage++; | |
251 if (buildCounterPubsubMessage < 3) { | |
252 o.data = "foo"; | |
253 o.label = buildUnnamed1173(); | |
254 } | |
255 buildCounterPubsubMessage--; | |
256 return o; | |
257 } | |
258 | |
259 checkPubsubMessage(api.PubsubMessage o) { | |
260 buildCounterPubsubMessage++; | |
261 if (buildCounterPubsubMessage < 3) { | |
262 unittest.expect(o.data, unittest.equals('foo')); | |
263 checkUnnamed1173(o.label); | |
264 } | |
265 buildCounterPubsubMessage--; | |
266 } | |
267 | |
268 core.int buildCounterPullRequest = 0; | |
269 buildPullRequest() { | |
270 var o = new api.PullRequest(); | |
271 buildCounterPullRequest++; | |
272 if (buildCounterPullRequest < 3) { | |
273 o.returnImmediately = true; | |
274 o.subscription = "foo"; | |
275 } | |
276 buildCounterPullRequest--; | |
277 return o; | |
278 } | |
279 | |
280 checkPullRequest(api.PullRequest o) { | |
281 buildCounterPullRequest++; | |
282 if (buildCounterPullRequest < 3) { | |
283 unittest.expect(o.returnImmediately, unittest.isTrue); | |
284 unittest.expect(o.subscription, unittest.equals('foo')); | |
285 } | |
286 buildCounterPullRequest--; | |
287 } | |
288 | |
289 core.int buildCounterPullResponse = 0; | |
290 buildPullResponse() { | |
291 var o = new api.PullResponse(); | |
292 buildCounterPullResponse++; | |
293 if (buildCounterPullResponse < 3) { | |
294 o.ackId = "foo"; | |
295 o.pubsubEvent = buildPubsubEvent(); | |
296 } | |
297 buildCounterPullResponse--; | |
298 return o; | |
299 } | |
300 | |
301 checkPullResponse(api.PullResponse o) { | |
302 buildCounterPullResponse++; | |
303 if (buildCounterPullResponse < 3) { | |
304 unittest.expect(o.ackId, unittest.equals('foo')); | |
305 checkPubsubEvent(o.pubsubEvent); | |
306 } | |
307 buildCounterPullResponse--; | |
308 } | |
309 | |
310 core.int buildCounterPushConfig = 0; | |
311 buildPushConfig() { | |
312 var o = new api.PushConfig(); | |
313 buildCounterPushConfig++; | |
314 if (buildCounterPushConfig < 3) { | |
315 o.pushEndpoint = "foo"; | |
316 } | |
317 buildCounterPushConfig--; | |
318 return o; | |
319 } | |
320 | |
321 checkPushConfig(api.PushConfig o) { | |
322 buildCounterPushConfig++; | |
323 if (buildCounterPushConfig < 3) { | |
324 unittest.expect(o.pushEndpoint, unittest.equals('foo')); | |
325 } | |
326 buildCounterPushConfig--; | |
327 } | |
328 | |
329 core.int buildCounterSubscription = 0; | |
330 buildSubscription() { | |
331 var o = new api.Subscription(); | |
332 buildCounterSubscription++; | |
333 if (buildCounterSubscription < 3) { | |
334 o.ackDeadlineSeconds = 42; | |
335 o.name = "foo"; | |
336 o.pushConfig = buildPushConfig(); | |
337 o.topic = "foo"; | |
338 } | |
339 buildCounterSubscription--; | |
340 return o; | |
341 } | |
342 | |
343 checkSubscription(api.Subscription o) { | |
344 buildCounterSubscription++; | |
345 if (buildCounterSubscription < 3) { | |
346 unittest.expect(o.ackDeadlineSeconds, unittest.equals(42)); | |
347 unittest.expect(o.name, unittest.equals('foo')); | |
348 checkPushConfig(o.pushConfig); | |
349 unittest.expect(o.topic, unittest.equals('foo')); | |
350 } | |
351 buildCounterSubscription--; | |
352 } | |
353 | |
354 core.int buildCounterTopic = 0; | |
355 buildTopic() { | |
356 var o = new api.Topic(); | |
357 buildCounterTopic++; | |
358 if (buildCounterTopic < 3) { | |
359 o.name = "foo"; | |
360 } | |
361 buildCounterTopic--; | |
362 return o; | |
363 } | |
364 | |
365 checkTopic(api.Topic o) { | |
366 buildCounterTopic++; | |
367 if (buildCounterTopic < 3) { | |
368 unittest.expect(o.name, unittest.equals('foo')); | |
369 } | |
370 buildCounterTopic--; | |
371 } | |
372 | |
373 | |
374 main() { | |
375 unittest.group("obj-schema-AcknowledgeRequest", () { | |
376 unittest.test("to-json--from-json", () { | |
377 var o = buildAcknowledgeRequest(); | |
378 var od = new api.AcknowledgeRequest.fromJson(o.toJson()); | |
379 checkAcknowledgeRequest(od); | |
380 }); | |
381 }); | |
382 | |
383 | |
384 unittest.group("obj-schema-Label", () { | |
385 unittest.test("to-json--from-json", () { | |
386 var o = buildLabel(); | |
387 var od = new api.Label.fromJson(o.toJson()); | |
388 checkLabel(od); | |
389 }); | |
390 }); | |
391 | |
392 | |
393 unittest.group("obj-schema-ListSubscriptionsResponse", () { | |
394 unittest.test("to-json--from-json", () { | |
395 var o = buildListSubscriptionsResponse(); | |
396 var od = new api.ListSubscriptionsResponse.fromJson(o.toJson()); | |
397 checkListSubscriptionsResponse(od); | |
398 }); | |
399 }); | |
400 | |
401 | |
402 unittest.group("obj-schema-ListTopicsResponse", () { | |
403 unittest.test("to-json--from-json", () { | |
404 var o = buildListTopicsResponse(); | |
405 var od = new api.ListTopicsResponse.fromJson(o.toJson()); | |
406 checkListTopicsResponse(od); | |
407 }); | |
408 }); | |
409 | |
410 | |
411 unittest.group("obj-schema-ModifyAckDeadlineRequest", () { | |
412 unittest.test("to-json--from-json", () { | |
413 var o = buildModifyAckDeadlineRequest(); | |
414 var od = new api.ModifyAckDeadlineRequest.fromJson(o.toJson()); | |
415 checkModifyAckDeadlineRequest(od); | |
416 }); | |
417 }); | |
418 | |
419 | |
420 unittest.group("obj-schema-ModifyPushConfigRequest", () { | |
421 unittest.test("to-json--from-json", () { | |
422 var o = buildModifyPushConfigRequest(); | |
423 var od = new api.ModifyPushConfigRequest.fromJson(o.toJson()); | |
424 checkModifyPushConfigRequest(od); | |
425 }); | |
426 }); | |
427 | |
428 | |
429 unittest.group("obj-schema-PublishRequest", () { | |
430 unittest.test("to-json--from-json", () { | |
431 var o = buildPublishRequest(); | |
432 var od = new api.PublishRequest.fromJson(o.toJson()); | |
433 checkPublishRequest(od); | |
434 }); | |
435 }); | |
436 | |
437 | |
438 unittest.group("obj-schema-PubsubEvent", () { | |
439 unittest.test("to-json--from-json", () { | |
440 var o = buildPubsubEvent(); | |
441 var od = new api.PubsubEvent.fromJson(o.toJson()); | |
442 checkPubsubEvent(od); | |
443 }); | |
444 }); | |
445 | |
446 | |
447 unittest.group("obj-schema-PubsubMessage", () { | |
448 unittest.test("to-json--from-json", () { | |
449 var o = buildPubsubMessage(); | |
450 var od = new api.PubsubMessage.fromJson(o.toJson()); | |
451 checkPubsubMessage(od); | |
452 }); | |
453 }); | |
454 | |
455 | |
456 unittest.group("obj-schema-PullRequest", () { | |
457 unittest.test("to-json--from-json", () { | |
458 var o = buildPullRequest(); | |
459 var od = new api.PullRequest.fromJson(o.toJson()); | |
460 checkPullRequest(od); | |
461 }); | |
462 }); | |
463 | |
464 | |
465 unittest.group("obj-schema-PullResponse", () { | |
466 unittest.test("to-json--from-json", () { | |
467 var o = buildPullResponse(); | |
468 var od = new api.PullResponse.fromJson(o.toJson()); | |
469 checkPullResponse(od); | |
470 }); | |
471 }); | |
472 | |
473 | |
474 unittest.group("obj-schema-PushConfig", () { | |
475 unittest.test("to-json--from-json", () { | |
476 var o = buildPushConfig(); | |
477 var od = new api.PushConfig.fromJson(o.toJson()); | |
478 checkPushConfig(od); | |
479 }); | |
480 }); | |
481 | |
482 | |
483 unittest.group("obj-schema-Subscription", () { | |
484 unittest.test("to-json--from-json", () { | |
485 var o = buildSubscription(); | |
486 var od = new api.Subscription.fromJson(o.toJson()); | |
487 checkSubscription(od); | |
488 }); | |
489 }); | |
490 | |
491 | |
492 unittest.group("obj-schema-Topic", () { | |
493 unittest.test("to-json--from-json", () { | |
494 var o = buildTopic(); | |
495 var od = new api.Topic.fromJson(o.toJson()); | |
496 checkTopic(od); | |
497 }); | |
498 }); | |
499 | |
500 | |
501 unittest.group("resource-SubscriptionsResourceApi", () { | |
502 unittest.test("method--acknowledge", () { | |
503 | |
504 var mock = new common_test.HttpServerMock(); | |
505 api.SubscriptionsResourceApi res = new api.PubsubApi(mock).subscriptions; | |
506 var arg_request = buildAcknowledgeRequest(); | |
507 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
508 var obj = new api.AcknowledgeRequest.fromJson(json); | |
509 checkAcknowledgeRequest(obj); | |
510 | |
511 var path = (req.url).path; | |
512 var pathOffset = 0; | |
513 var index; | |
514 var subPart; | |
515 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
516 pathOffset += 16; | |
517 unittest.expect(path.substring(pathOffset, pathOffset + 25), unittest.eq
uals("subscriptions/acknowledge")); | |
518 pathOffset += 25; | |
519 | |
520 var query = (req.url).query; | |
521 var queryOffset = 0; | |
522 var queryMap = {}; | |
523 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
524 parseBool(n) { | |
525 if (n == "true") return true; | |
526 if (n == "false") return false; | |
527 if (n == null) return null; | |
528 throw new core.ArgumentError("Invalid boolean: $n"); | |
529 } | |
530 if (query.length > 0) { | |
531 for (var part in query.split("&")) { | |
532 var keyvalue = part.split("="); | |
533 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
534 } | |
535 } | |
536 | |
537 | |
538 var h = { | |
539 "content-type" : "application/json; charset=utf-8", | |
540 }; | |
541 var resp = ""; | |
542 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
543 }), true); | |
544 res.acknowledge(arg_request).then(unittest.expectAsync((_) {})); | |
545 }); | |
546 | |
547 unittest.test("method--create", () { | |
548 | |
549 var mock = new common_test.HttpServerMock(); | |
550 api.SubscriptionsResourceApi res = new api.PubsubApi(mock).subscriptions; | |
551 var arg_request = buildSubscription(); | |
552 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
553 var obj = new api.Subscription.fromJson(json); | |
554 checkSubscription(obj); | |
555 | |
556 var path = (req.url).path; | |
557 var pathOffset = 0; | |
558 var index; | |
559 var subPart; | |
560 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
561 pathOffset += 16; | |
562 unittest.expect(path.substring(pathOffset, pathOffset + 13), unittest.eq
uals("subscriptions")); | |
563 pathOffset += 13; | |
564 | |
565 var query = (req.url).query; | |
566 var queryOffset = 0; | |
567 var queryMap = {}; | |
568 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
569 parseBool(n) { | |
570 if (n == "true") return true; | |
571 if (n == "false") return false; | |
572 if (n == null) return null; | |
573 throw new core.ArgumentError("Invalid boolean: $n"); | |
574 } | |
575 if (query.length > 0) { | |
576 for (var part in query.split("&")) { | |
577 var keyvalue = part.split("="); | |
578 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
579 } | |
580 } | |
581 | |
582 | |
583 var h = { | |
584 "content-type" : "application/json; charset=utf-8", | |
585 }; | |
586 var resp = convert.JSON.encode(buildSubscription()); | |
587 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
588 }), true); | |
589 res.create(arg_request).then(unittest.expectAsync(((api.Subscription respo
nse) { | |
590 checkSubscription(response); | |
591 }))); | |
592 }); | |
593 | |
594 unittest.test("method--delete", () { | |
595 | |
596 var mock = new common_test.HttpServerMock(); | |
597 api.SubscriptionsResourceApi res = new api.PubsubApi(mock).subscriptions; | |
598 var arg_subscription = "foo"; | |
599 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
600 var path = (req.url).path; | |
601 var pathOffset = 0; | |
602 var index; | |
603 var subPart; | |
604 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
605 pathOffset += 16; | |
606 unittest.expect(path.substring(pathOffset, pathOffset + 14), unittest.eq
uals("subscriptions/")); | |
607 pathOffset += 14; | |
608 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; | |
609 | |
610 var query = (req.url).query; | |
611 var queryOffset = 0; | |
612 var queryMap = {}; | |
613 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
614 parseBool(n) { | |
615 if (n == "true") return true; | |
616 if (n == "false") return false; | |
617 if (n == null) return null; | |
618 throw new core.ArgumentError("Invalid boolean: $n"); | |
619 } | |
620 if (query.length > 0) { | |
621 for (var part in query.split("&")) { | |
622 var keyvalue = part.split("="); | |
623 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
624 } | |
625 } | |
626 | |
627 | |
628 var h = { | |
629 "content-type" : "application/json; charset=utf-8", | |
630 }; | |
631 var resp = ""; | |
632 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
633 }), true); | |
634 res.delete(arg_subscription).then(unittest.expectAsync((_) {})); | |
635 }); | |
636 | |
637 unittest.test("method--get", () { | |
638 | |
639 var mock = new common_test.HttpServerMock(); | |
640 api.SubscriptionsResourceApi res = new api.PubsubApi(mock).subscriptions; | |
641 var arg_subscription = "foo"; | |
642 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
643 var path = (req.url).path; | |
644 var pathOffset = 0; | |
645 var index; | |
646 var subPart; | |
647 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
648 pathOffset += 16; | |
649 unittest.expect(path.substring(pathOffset, pathOffset + 14), unittest.eq
uals("subscriptions/")); | |
650 pathOffset += 14; | |
651 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; | |
652 | |
653 var query = (req.url).query; | |
654 var queryOffset = 0; | |
655 var queryMap = {}; | |
656 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
657 parseBool(n) { | |
658 if (n == "true") return true; | |
659 if (n == "false") return false; | |
660 if (n == null) return null; | |
661 throw new core.ArgumentError("Invalid boolean: $n"); | |
662 } | |
663 if (query.length > 0) { | |
664 for (var part in query.split("&")) { | |
665 var keyvalue = part.split("="); | |
666 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
667 } | |
668 } | |
669 | |
670 | |
671 var h = { | |
672 "content-type" : "application/json; charset=utf-8", | |
673 }; | |
674 var resp = convert.JSON.encode(buildSubscription()); | |
675 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
676 }), true); | |
677 res.get(arg_subscription).then(unittest.expectAsync(((api.Subscription res
ponse) { | |
678 checkSubscription(response); | |
679 }))); | |
680 }); | |
681 | |
682 unittest.test("method--list", () { | |
683 | |
684 var mock = new common_test.HttpServerMock(); | |
685 api.SubscriptionsResourceApi res = new api.PubsubApi(mock).subscriptions; | |
686 var arg_maxResults = 42; | |
687 var arg_pageToken = "foo"; | |
688 var arg_query = "foo"; | |
689 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
690 var path = (req.url).path; | |
691 var pathOffset = 0; | |
692 var index; | |
693 var subPart; | |
694 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
695 pathOffset += 16; | |
696 unittest.expect(path.substring(pathOffset, pathOffset + 13), unittest.eq
uals("subscriptions")); | |
697 pathOffset += 13; | |
698 | |
699 var query = (req.url).query; | |
700 var queryOffset = 0; | |
701 var queryMap = {}; | |
702 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
703 parseBool(n) { | |
704 if (n == "true") return true; | |
705 if (n == "false") return false; | |
706 if (n == null) return null; | |
707 throw new core.ArgumentError("Invalid boolean: $n"); | |
708 } | |
709 if (query.length > 0) { | |
710 for (var part in query.split("&")) { | |
711 var keyvalue = part.split("="); | |
712 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
713 } | |
714 } | |
715 unittest.expect(core.int.parse(queryMap["maxResults"].first), unittest.e
quals(arg_maxResults)); | |
716 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); | |
717 unittest.expect(queryMap["query"].first, unittest.equals(arg_query)); | |
718 | |
719 | |
720 var h = { | |
721 "content-type" : "application/json; charset=utf-8", | |
722 }; | |
723 var resp = convert.JSON.encode(buildListSubscriptionsResponse()); | |
724 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
725 }), true); | |
726 res.list(maxResults: arg_maxResults, pageToken: arg_pageToken, query: arg_
query).then(unittest.expectAsync(((api.ListSubscriptionsResponse response) { | |
727 checkListSubscriptionsResponse(response); | |
728 }))); | |
729 }); | |
730 | |
731 unittest.test("method--modifyAckDeadline", () { | |
732 | |
733 var mock = new common_test.HttpServerMock(); | |
734 api.SubscriptionsResourceApi res = new api.PubsubApi(mock).subscriptions; | |
735 var arg_request = buildModifyAckDeadlineRequest(); | |
736 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
737 var obj = new api.ModifyAckDeadlineRequest.fromJson(json); | |
738 checkModifyAckDeadlineRequest(obj); | |
739 | |
740 var path = (req.url).path; | |
741 var pathOffset = 0; | |
742 var index; | |
743 var subPart; | |
744 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
745 pathOffset += 16; | |
746 unittest.expect(path.substring(pathOffset, pathOffset + 31), unittest.eq
uals("subscriptions/modifyAckDeadline")); | |
747 pathOffset += 31; | |
748 | |
749 var query = (req.url).query; | |
750 var queryOffset = 0; | |
751 var queryMap = {}; | |
752 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
753 parseBool(n) { | |
754 if (n == "true") return true; | |
755 if (n == "false") return false; | |
756 if (n == null) return null; | |
757 throw new core.ArgumentError("Invalid boolean: $n"); | |
758 } | |
759 if (query.length > 0) { | |
760 for (var part in query.split("&")) { | |
761 var keyvalue = part.split("="); | |
762 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
763 } | |
764 } | |
765 | |
766 | |
767 var h = { | |
768 "content-type" : "application/json; charset=utf-8", | |
769 }; | |
770 var resp = ""; | |
771 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
772 }), true); | |
773 res.modifyAckDeadline(arg_request).then(unittest.expectAsync((_) {})); | |
774 }); | |
775 | |
776 unittest.test("method--modifyPushConfig", () { | |
777 | |
778 var mock = new common_test.HttpServerMock(); | |
779 api.SubscriptionsResourceApi res = new api.PubsubApi(mock).subscriptions; | |
780 var arg_request = buildModifyPushConfigRequest(); | |
781 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
782 var obj = new api.ModifyPushConfigRequest.fromJson(json); | |
783 checkModifyPushConfigRequest(obj); | |
784 | |
785 var path = (req.url).path; | |
786 var pathOffset = 0; | |
787 var index; | |
788 var subPart; | |
789 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
790 pathOffset += 16; | |
791 unittest.expect(path.substring(pathOffset, pathOffset + 30), unittest.eq
uals("subscriptions/modifyPushConfig")); | |
792 pathOffset += 30; | |
793 | |
794 var query = (req.url).query; | |
795 var queryOffset = 0; | |
796 var queryMap = {}; | |
797 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
798 parseBool(n) { | |
799 if (n == "true") return true; | |
800 if (n == "false") return false; | |
801 if (n == null) return null; | |
802 throw new core.ArgumentError("Invalid boolean: $n"); | |
803 } | |
804 if (query.length > 0) { | |
805 for (var part in query.split("&")) { | |
806 var keyvalue = part.split("="); | |
807 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
808 } | |
809 } | |
810 | |
811 | |
812 var h = { | |
813 "content-type" : "application/json; charset=utf-8", | |
814 }; | |
815 var resp = ""; | |
816 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
817 }), true); | |
818 res.modifyPushConfig(arg_request).then(unittest.expectAsync((_) {})); | |
819 }); | |
820 | |
821 unittest.test("method--pull", () { | |
822 | |
823 var mock = new common_test.HttpServerMock(); | |
824 api.SubscriptionsResourceApi res = new api.PubsubApi(mock).subscriptions; | |
825 var arg_request = buildPullRequest(); | |
826 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
827 var obj = new api.PullRequest.fromJson(json); | |
828 checkPullRequest(obj); | |
829 | |
830 var path = (req.url).path; | |
831 var pathOffset = 0; | |
832 var index; | |
833 var subPart; | |
834 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
835 pathOffset += 16; | |
836 unittest.expect(path.substring(pathOffset, pathOffset + 18), unittest.eq
uals("subscriptions/pull")); | |
837 pathOffset += 18; | |
838 | |
839 var query = (req.url).query; | |
840 var queryOffset = 0; | |
841 var queryMap = {}; | |
842 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
843 parseBool(n) { | |
844 if (n == "true") return true; | |
845 if (n == "false") return false; | |
846 if (n == null) return null; | |
847 throw new core.ArgumentError("Invalid boolean: $n"); | |
848 } | |
849 if (query.length > 0) { | |
850 for (var part in query.split("&")) { | |
851 var keyvalue = part.split("="); | |
852 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
853 } | |
854 } | |
855 | |
856 | |
857 var h = { | |
858 "content-type" : "application/json; charset=utf-8", | |
859 }; | |
860 var resp = convert.JSON.encode(buildPullResponse()); | |
861 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
862 }), true); | |
863 res.pull(arg_request).then(unittest.expectAsync(((api.PullResponse respons
e) { | |
864 checkPullResponse(response); | |
865 }))); | |
866 }); | |
867 | |
868 }); | |
869 | |
870 | |
871 unittest.group("resource-TopicsResourceApi", () { | |
872 unittest.test("method--create", () { | |
873 | |
874 var mock = new common_test.HttpServerMock(); | |
875 api.TopicsResourceApi res = new api.PubsubApi(mock).topics; | |
876 var arg_request = buildTopic(); | |
877 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
878 var obj = new api.Topic.fromJson(json); | |
879 checkTopic(obj); | |
880 | |
881 var path = (req.url).path; | |
882 var pathOffset = 0; | |
883 var index; | |
884 var subPart; | |
885 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
886 pathOffset += 16; | |
887 unittest.expect(path.substring(pathOffset, pathOffset + 6), unittest.equ
als("topics")); | |
888 pathOffset += 6; | |
889 | |
890 var query = (req.url).query; | |
891 var queryOffset = 0; | |
892 var queryMap = {}; | |
893 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
894 parseBool(n) { | |
895 if (n == "true") return true; | |
896 if (n == "false") return false; | |
897 if (n == null) return null; | |
898 throw new core.ArgumentError("Invalid boolean: $n"); | |
899 } | |
900 if (query.length > 0) { | |
901 for (var part in query.split("&")) { | |
902 var keyvalue = part.split("="); | |
903 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
904 } | |
905 } | |
906 | |
907 | |
908 var h = { | |
909 "content-type" : "application/json; charset=utf-8", | |
910 }; | |
911 var resp = convert.JSON.encode(buildTopic()); | |
912 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
913 }), true); | |
914 res.create(arg_request).then(unittest.expectAsync(((api.Topic response) { | |
915 checkTopic(response); | |
916 }))); | |
917 }); | |
918 | |
919 unittest.test("method--delete", () { | |
920 | |
921 var mock = new common_test.HttpServerMock(); | |
922 api.TopicsResourceApi res = new api.PubsubApi(mock).topics; | |
923 var arg_topic = "foo"; | |
924 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
925 var path = (req.url).path; | |
926 var pathOffset = 0; | |
927 var index; | |
928 var subPart; | |
929 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
930 pathOffset += 16; | |
931 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("topics/")); | |
932 pathOffset += 7; | |
933 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; | |
934 | |
935 var query = (req.url).query; | |
936 var queryOffset = 0; | |
937 var queryMap = {}; | |
938 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
939 parseBool(n) { | |
940 if (n == "true") return true; | |
941 if (n == "false") return false; | |
942 if (n == null) return null; | |
943 throw new core.ArgumentError("Invalid boolean: $n"); | |
944 } | |
945 if (query.length > 0) { | |
946 for (var part in query.split("&")) { | |
947 var keyvalue = part.split("="); | |
948 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
949 } | |
950 } | |
951 | |
952 | |
953 var h = { | |
954 "content-type" : "application/json; charset=utf-8", | |
955 }; | |
956 var resp = ""; | |
957 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
958 }), true); | |
959 res.delete(arg_topic).then(unittest.expectAsync((_) {})); | |
960 }); | |
961 | |
962 unittest.test("method--get", () { | |
963 | |
964 var mock = new common_test.HttpServerMock(); | |
965 api.TopicsResourceApi res = new api.PubsubApi(mock).topics; | |
966 var arg_topic = "foo"; | |
967 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
968 var path = (req.url).path; | |
969 var pathOffset = 0; | |
970 var index; | |
971 var subPart; | |
972 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
973 pathOffset += 16; | |
974 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("topics/")); | |
975 pathOffset += 7; | |
976 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; | |
977 | |
978 var query = (req.url).query; | |
979 var queryOffset = 0; | |
980 var queryMap = {}; | |
981 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
982 parseBool(n) { | |
983 if (n == "true") return true; | |
984 if (n == "false") return false; | |
985 if (n == null) return null; | |
986 throw new core.ArgumentError("Invalid boolean: $n"); | |
987 } | |
988 if (query.length > 0) { | |
989 for (var part in query.split("&")) { | |
990 var keyvalue = part.split("="); | |
991 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
992 } | |
993 } | |
994 | |
995 | |
996 var h = { | |
997 "content-type" : "application/json; charset=utf-8", | |
998 }; | |
999 var resp = convert.JSON.encode(buildTopic()); | |
1000 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
1001 }), true); | |
1002 res.get(arg_topic).then(unittest.expectAsync(((api.Topic response) { | |
1003 checkTopic(response); | |
1004 }))); | |
1005 }); | |
1006 | |
1007 unittest.test("method--list", () { | |
1008 | |
1009 var mock = new common_test.HttpServerMock(); | |
1010 api.TopicsResourceApi res = new api.PubsubApi(mock).topics; | |
1011 var arg_maxResults = 42; | |
1012 var arg_pageToken = "foo"; | |
1013 var arg_query = "foo"; | |
1014 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
1015 var path = (req.url).path; | |
1016 var pathOffset = 0; | |
1017 var index; | |
1018 var subPart; | |
1019 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
1020 pathOffset += 16; | |
1021 unittest.expect(path.substring(pathOffset, pathOffset + 6), unittest.equ
als("topics")); | |
1022 pathOffset += 6; | |
1023 | |
1024 var query = (req.url).query; | |
1025 var queryOffset = 0; | |
1026 var queryMap = {}; | |
1027 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
1028 parseBool(n) { | |
1029 if (n == "true") return true; | |
1030 if (n == "false") return false; | |
1031 if (n == null) return null; | |
1032 throw new core.ArgumentError("Invalid boolean: $n"); | |
1033 } | |
1034 if (query.length > 0) { | |
1035 for (var part in query.split("&")) { | |
1036 var keyvalue = part.split("="); | |
1037 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
1038 } | |
1039 } | |
1040 unittest.expect(core.int.parse(queryMap["maxResults"].first), unittest.e
quals(arg_maxResults)); | |
1041 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); | |
1042 unittest.expect(queryMap["query"].first, unittest.equals(arg_query)); | |
1043 | |
1044 | |
1045 var h = { | |
1046 "content-type" : "application/json; charset=utf-8", | |
1047 }; | |
1048 var resp = convert.JSON.encode(buildListTopicsResponse()); | |
1049 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
1050 }), true); | |
1051 res.list(maxResults: arg_maxResults, pageToken: arg_pageToken, query: arg_
query).then(unittest.expectAsync(((api.ListTopicsResponse response) { | |
1052 checkListTopicsResponse(response); | |
1053 }))); | |
1054 }); | |
1055 | |
1056 unittest.test("method--publish", () { | |
1057 | |
1058 var mock = new common_test.HttpServerMock(); | |
1059 api.TopicsResourceApi res = new api.PubsubApi(mock).topics; | |
1060 var arg_request = buildPublishRequest(); | |
1061 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
1062 var obj = new api.PublishRequest.fromJson(json); | |
1063 checkPublishRequest(obj); | |
1064 | |
1065 var path = (req.url).path; | |
1066 var pathOffset = 0; | |
1067 var index; | |
1068 var subPart; | |
1069 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("/pubsub/v1beta1/")); | |
1070 pathOffset += 16; | |
1071 unittest.expect(path.substring(pathOffset, pathOffset + 14), unittest.eq
uals("topics/publish")); | |
1072 pathOffset += 14; | |
1073 | |
1074 var query = (req.url).query; | |
1075 var queryOffset = 0; | |
1076 var queryMap = {}; | |
1077 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
1078 parseBool(n) { | |
1079 if (n == "true") return true; | |
1080 if (n == "false") return false; | |
1081 if (n == null) return null; | |
1082 throw new core.ArgumentError("Invalid boolean: $n"); | |
1083 } | |
1084 if (query.length > 0) { | |
1085 for (var part in query.split("&")) { | |
1086 var keyvalue = part.split("="); | |
1087 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
1088 } | |
1089 } | |
1090 | |
1091 | |
1092 var h = { | |
1093 "content-type" : "application/json; charset=utf-8", | |
1094 }; | |
1095 var resp = ""; | |
1096 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
1097 }), true); | |
1098 res.publish(arg_request).then(unittest.expectAsync((_) {})); | |
1099 }); | |
1100 | |
1101 }); | |
1102 | |
1103 | |
1104 } | |
1105 | |
OLD | NEW |