OLD | NEW |
| (Empty) |
1 library googleapis.freebase.v1.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 | |
12 import 'package:googleapis/freebase/v1.dart' as api; | |
13 | |
14 class HttpServerMock extends http.BaseClient { | |
15 core.Function _callback; | |
16 core.bool _expectJson; | |
17 | |
18 void register(core.Function callback, core.bool expectJson) { | |
19 _callback = callback; | |
20 _expectJson = expectJson; | |
21 } | |
22 | |
23 async.Future<http.StreamedResponse> send(http.BaseRequest request) { | |
24 if (_expectJson) { | |
25 return request.finalize() | |
26 .transform(convert.UTF8.decoder) | |
27 .join('') | |
28 .then((core.String jsonString) { | |
29 if (jsonString.isEmpty) { | |
30 return _callback(request, null); | |
31 } else { | |
32 return _callback(request, convert.JSON.decode(jsonString)); | |
33 } | |
34 }); | |
35 } else { | |
36 var stream = request.finalize(); | |
37 if (stream == null) { | |
38 return _callback(request, []); | |
39 } else { | |
40 return stream.toBytes().then((data) { | |
41 return _callback(request, data); | |
42 }); | |
43 } | |
44 } | |
45 } | |
46 } | |
47 | |
48 http.StreamedResponse stringResponse( | |
49 core.int status, core.Map headers, core.String body) { | |
50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | |
51 return new http.StreamedResponse(stream, status, headers: headers); | |
52 } | |
53 | |
54 core.int buildCounterReconcileCandidateNotable = 0; | |
55 buildReconcileCandidateNotable() { | |
56 var o = new api.ReconcileCandidateNotable(); | |
57 buildCounterReconcileCandidateNotable++; | |
58 if (buildCounterReconcileCandidateNotable < 3) { | |
59 o.id = "foo"; | |
60 o.name = "foo"; | |
61 } | |
62 buildCounterReconcileCandidateNotable--; | |
63 return o; | |
64 } | |
65 | |
66 checkReconcileCandidateNotable(api.ReconcileCandidateNotable o) { | |
67 buildCounterReconcileCandidateNotable++; | |
68 if (buildCounterReconcileCandidateNotable < 3) { | |
69 unittest.expect(o.id, unittest.equals('foo')); | |
70 unittest.expect(o.name, unittest.equals('foo')); | |
71 } | |
72 buildCounterReconcileCandidateNotable--; | |
73 } | |
74 | |
75 core.int buildCounterReconcileCandidate = 0; | |
76 buildReconcileCandidate() { | |
77 var o = new api.ReconcileCandidate(); | |
78 buildCounterReconcileCandidate++; | |
79 if (buildCounterReconcileCandidate < 3) { | |
80 o.confidence = 42.0; | |
81 o.lang = "foo"; | |
82 o.mid = "foo"; | |
83 o.name = "foo"; | |
84 o.notable = buildReconcileCandidateNotable(); | |
85 } | |
86 buildCounterReconcileCandidate--; | |
87 return o; | |
88 } | |
89 | |
90 checkReconcileCandidate(api.ReconcileCandidate o) { | |
91 buildCounterReconcileCandidate++; | |
92 if (buildCounterReconcileCandidate < 3) { | |
93 unittest.expect(o.confidence, unittest.equals(42.0)); | |
94 unittest.expect(o.lang, unittest.equals('foo')); | |
95 unittest.expect(o.mid, unittest.equals('foo')); | |
96 unittest.expect(o.name, unittest.equals('foo')); | |
97 checkReconcileCandidateNotable(o.notable); | |
98 } | |
99 buildCounterReconcileCandidate--; | |
100 } | |
101 | |
102 buildUnnamed1389() { | |
103 var o = new core.List<api.ReconcileCandidate>(); | |
104 o.add(buildReconcileCandidate()); | |
105 o.add(buildReconcileCandidate()); | |
106 return o; | |
107 } | |
108 | |
109 checkUnnamed1389(core.List<api.ReconcileCandidate> o) { | |
110 unittest.expect(o, unittest.hasLength(2)); | |
111 checkReconcileCandidate(o[0]); | |
112 checkReconcileCandidate(o[1]); | |
113 } | |
114 | |
115 core.int buildCounterReconcileGetCosts = 0; | |
116 buildReconcileGetCosts() { | |
117 var o = new api.ReconcileGetCosts(); | |
118 buildCounterReconcileGetCosts++; | |
119 if (buildCounterReconcileGetCosts < 3) { | |
120 o.hits = 42; | |
121 o.ms = 42; | |
122 } | |
123 buildCounterReconcileGetCosts--; | |
124 return o; | |
125 } | |
126 | |
127 checkReconcileGetCosts(api.ReconcileGetCosts o) { | |
128 buildCounterReconcileGetCosts++; | |
129 if (buildCounterReconcileGetCosts < 3) { | |
130 unittest.expect(o.hits, unittest.equals(42)); | |
131 unittest.expect(o.ms, unittest.equals(42)); | |
132 } | |
133 buildCounterReconcileGetCosts--; | |
134 } | |
135 | |
136 core.int buildCounterReconcileGetWarning = 0; | |
137 buildReconcileGetWarning() { | |
138 var o = new api.ReconcileGetWarning(); | |
139 buildCounterReconcileGetWarning++; | |
140 if (buildCounterReconcileGetWarning < 3) { | |
141 o.location = "foo"; | |
142 o.message = "foo"; | |
143 o.reason = "foo"; | |
144 } | |
145 buildCounterReconcileGetWarning--; | |
146 return o; | |
147 } | |
148 | |
149 checkReconcileGetWarning(api.ReconcileGetWarning o) { | |
150 buildCounterReconcileGetWarning++; | |
151 if (buildCounterReconcileGetWarning < 3) { | |
152 unittest.expect(o.location, unittest.equals('foo')); | |
153 unittest.expect(o.message, unittest.equals('foo')); | |
154 unittest.expect(o.reason, unittest.equals('foo')); | |
155 } | |
156 buildCounterReconcileGetWarning--; | |
157 } | |
158 | |
159 buildUnnamed1390() { | |
160 var o = new core.List<api.ReconcileGetWarning>(); | |
161 o.add(buildReconcileGetWarning()); | |
162 o.add(buildReconcileGetWarning()); | |
163 return o; | |
164 } | |
165 | |
166 checkUnnamed1390(core.List<api.ReconcileGetWarning> o) { | |
167 unittest.expect(o, unittest.hasLength(2)); | |
168 checkReconcileGetWarning(o[0]); | |
169 checkReconcileGetWarning(o[1]); | |
170 } | |
171 | |
172 core.int buildCounterReconcileGet = 0; | |
173 buildReconcileGet() { | |
174 var o = new api.ReconcileGet(); | |
175 buildCounterReconcileGet++; | |
176 if (buildCounterReconcileGet < 3) { | |
177 o.candidate = buildUnnamed1389(); | |
178 o.costs = buildReconcileGetCosts(); | |
179 o.match = buildReconcileCandidate(); | |
180 o.warning = buildUnnamed1390(); | |
181 } | |
182 buildCounterReconcileGet--; | |
183 return o; | |
184 } | |
185 | |
186 checkReconcileGet(api.ReconcileGet o) { | |
187 buildCounterReconcileGet++; | |
188 if (buildCounterReconcileGet < 3) { | |
189 checkUnnamed1389(o.candidate); | |
190 checkReconcileGetCosts(o.costs); | |
191 checkReconcileCandidate(o.match); | |
192 checkUnnamed1390(o.warning); | |
193 } | |
194 buildCounterReconcileGet--; | |
195 } | |
196 | |
197 buildUnnamed1391() { | |
198 var o = new core.List<core.String>(); | |
199 o.add("foo"); | |
200 o.add("foo"); | |
201 return o; | |
202 } | |
203 | |
204 checkUnnamed1391(core.List<core.String> o) { | |
205 unittest.expect(o, unittest.hasLength(2)); | |
206 unittest.expect(o[0], unittest.equals('foo')); | |
207 unittest.expect(o[1], unittest.equals('foo')); | |
208 } | |
209 | |
210 buildUnnamed1392() { | |
211 var o = new core.List<core.String>(); | |
212 o.add("foo"); | |
213 o.add("foo"); | |
214 return o; | |
215 } | |
216 | |
217 checkUnnamed1392(core.List<core.String> o) { | |
218 unittest.expect(o, unittest.hasLength(2)); | |
219 unittest.expect(o[0], unittest.equals('foo')); | |
220 unittest.expect(o[1], unittest.equals('foo')); | |
221 } | |
222 | |
223 buildUnnamed1393() { | |
224 var o = new core.List<core.String>(); | |
225 o.add("foo"); | |
226 o.add("foo"); | |
227 return o; | |
228 } | |
229 | |
230 checkUnnamed1393(core.List<core.String> o) { | |
231 unittest.expect(o, unittest.hasLength(2)); | |
232 unittest.expect(o[0], unittest.equals('foo')); | |
233 unittest.expect(o[1], unittest.equals('foo')); | |
234 } | |
235 | |
236 buildUnnamed1394() { | |
237 var o = new core.List<core.String>(); | |
238 o.add("foo"); | |
239 o.add("foo"); | |
240 return o; | |
241 } | |
242 | |
243 checkUnnamed1394(core.List<core.String> o) { | |
244 unittest.expect(o, unittest.hasLength(2)); | |
245 unittest.expect(o[0], unittest.equals('foo')); | |
246 unittest.expect(o[1], unittest.equals('foo')); | |
247 } | |
248 | |
249 buildUnnamed1395() { | |
250 var o = new core.List<core.String>(); | |
251 o.add("foo"); | |
252 o.add("foo"); | |
253 return o; | |
254 } | |
255 | |
256 checkUnnamed1395(core.List<core.String> o) { | |
257 unittest.expect(o, unittest.hasLength(2)); | |
258 unittest.expect(o[0], unittest.equals('foo')); | |
259 unittest.expect(o[1], unittest.equals('foo')); | |
260 } | |
261 | |
262 buildUnnamed1396() { | |
263 var o = new core.List<core.String>(); | |
264 o.add("foo"); | |
265 o.add("foo"); | |
266 return o; | |
267 } | |
268 | |
269 checkUnnamed1396(core.List<core.String> o) { | |
270 unittest.expect(o, unittest.hasLength(2)); | |
271 unittest.expect(o[0], unittest.equals('foo')); | |
272 unittest.expect(o[1], unittest.equals('foo')); | |
273 } | |
274 | |
275 buildUnnamed1397() { | |
276 var o = new core.List<core.String>(); | |
277 o.add("foo"); | |
278 o.add("foo"); | |
279 return o; | |
280 } | |
281 | |
282 checkUnnamed1397(core.List<core.String> o) { | |
283 unittest.expect(o, unittest.hasLength(2)); | |
284 unittest.expect(o[0], unittest.equals('foo')); | |
285 unittest.expect(o[1], unittest.equals('foo')); | |
286 } | |
287 | |
288 buildUnnamed1398() { | |
289 var o = new core.List<core.String>(); | |
290 o.add("foo"); | |
291 o.add("foo"); | |
292 return o; | |
293 } | |
294 | |
295 checkUnnamed1398(core.List<core.String> o) { | |
296 unittest.expect(o, unittest.hasLength(2)); | |
297 unittest.expect(o[0], unittest.equals('foo')); | |
298 unittest.expect(o[1], unittest.equals('foo')); | |
299 } | |
300 | |
301 buildUnnamed1399() { | |
302 var o = new core.List<core.String>(); | |
303 o.add("foo"); | |
304 o.add("foo"); | |
305 return o; | |
306 } | |
307 | |
308 checkUnnamed1399(core.List<core.String> o) { | |
309 unittest.expect(o, unittest.hasLength(2)); | |
310 unittest.expect(o[0], unittest.equals('foo')); | |
311 unittest.expect(o[1], unittest.equals('foo')); | |
312 } | |
313 | |
314 buildUnnamed1400() { | |
315 var o = new core.List<core.String>(); | |
316 o.add("foo"); | |
317 o.add("foo"); | |
318 return o; | |
319 } | |
320 | |
321 checkUnnamed1400(core.List<core.String> o) { | |
322 unittest.expect(o, unittest.hasLength(2)); | |
323 unittest.expect(o[0], unittest.equals('foo')); | |
324 unittest.expect(o[1], unittest.equals('foo')); | |
325 } | |
326 | |
327 | |
328 main() { | |
329 unittest.group("obj-schema-ReconcileCandidateNotable", () { | |
330 unittest.test("to-json--from-json", () { | |
331 var o = buildReconcileCandidateNotable(); | |
332 var od = new api.ReconcileCandidateNotable.fromJson(o.toJson()); | |
333 checkReconcileCandidateNotable(od); | |
334 }); | |
335 }); | |
336 | |
337 | |
338 unittest.group("obj-schema-ReconcileCandidate", () { | |
339 unittest.test("to-json--from-json", () { | |
340 var o = buildReconcileCandidate(); | |
341 var od = new api.ReconcileCandidate.fromJson(o.toJson()); | |
342 checkReconcileCandidate(od); | |
343 }); | |
344 }); | |
345 | |
346 | |
347 unittest.group("obj-schema-ReconcileGetCosts", () { | |
348 unittest.test("to-json--from-json", () { | |
349 var o = buildReconcileGetCosts(); | |
350 var od = new api.ReconcileGetCosts.fromJson(o.toJson()); | |
351 checkReconcileGetCosts(od); | |
352 }); | |
353 }); | |
354 | |
355 | |
356 unittest.group("obj-schema-ReconcileGetWarning", () { | |
357 unittest.test("to-json--from-json", () { | |
358 var o = buildReconcileGetWarning(); | |
359 var od = new api.ReconcileGetWarning.fromJson(o.toJson()); | |
360 checkReconcileGetWarning(od); | |
361 }); | |
362 }); | |
363 | |
364 | |
365 unittest.group("obj-schema-ReconcileGet", () { | |
366 unittest.test("to-json--from-json", () { | |
367 var o = buildReconcileGet(); | |
368 var od = new api.ReconcileGet.fromJson(o.toJson()); | |
369 checkReconcileGet(od); | |
370 }); | |
371 }); | |
372 | |
373 | |
374 unittest.group("resource-FreebaseApi", () { | |
375 unittest.test("method--reconcile", () { | |
376 | |
377 var mock = new HttpServerMock(); | |
378 api.FreebaseApi res = new api.FreebaseApi(mock); | |
379 var arg_confidence = 42.0; | |
380 var arg_kind = buildUnnamed1391(); | |
381 var arg_lang = buildUnnamed1392(); | |
382 var arg_limit = 42; | |
383 var arg_name = "foo"; | |
384 var arg_prop = buildUnnamed1393(); | |
385 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
386 var path = (req.url).path; | |
387 var pathOffset = 0; | |
388 var index; | |
389 var subPart; | |
390 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
391 pathOffset += 1; | |
392 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("freebase/v1/")); | |
393 pathOffset += 12; | |
394 unittest.expect(path.substring(pathOffset, pathOffset + 9), unittest.equ
als("reconcile")); | |
395 pathOffset += 9; | |
396 | |
397 var query = (req.url).query; | |
398 var queryOffset = 0; | |
399 var queryMap = {}; | |
400 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
401 parseBool(n) { | |
402 if (n == "true") return true; | |
403 if (n == "false") return false; | |
404 if (n == null) return null; | |
405 throw new core.ArgumentError("Invalid boolean: $n"); | |
406 } | |
407 if (query.length > 0) { | |
408 for (var part in query.split("&")) { | |
409 var keyvalue = part.split("="); | |
410 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
411 } | |
412 } | |
413 unittest.expect(core.num.parse(queryMap["confidence"].first), unittest.e
quals(arg_confidence)); | |
414 unittest.expect(queryMap["kind"], unittest.equals(arg_kind)); | |
415 unittest.expect(queryMap["lang"], unittest.equals(arg_lang)); | |
416 unittest.expect(core.int.parse(queryMap["limit"].first), unittest.equals
(arg_limit)); | |
417 unittest.expect(queryMap["name"].first, unittest.equals(arg_name)); | |
418 unittest.expect(queryMap["prop"], unittest.equals(arg_prop)); | |
419 | |
420 | |
421 var h = { | |
422 "content-type" : "application/json; charset=utf-8", | |
423 }; | |
424 var resp = convert.JSON.encode(buildReconcileGet()); | |
425 return new async.Future.value(stringResponse(200, h, resp)); | |
426 }), true); | |
427 res.reconcile(confidence: arg_confidence, kind: arg_kind, lang: arg_lang,
limit: arg_limit, name: arg_name, prop: arg_prop).then(unittest.expectAsync(((ap
i.ReconcileGet response) { | |
428 checkReconcileGet(response); | |
429 }))); | |
430 }); | |
431 | |
432 unittest.test("method--search", () { | |
433 // TODO: Implement tests for media upload; | |
434 // TODO: Implement tests for media download; | |
435 | |
436 var mock = new HttpServerMock(); | |
437 api.FreebaseApi res = new api.FreebaseApi(mock); | |
438 var arg_asOfTime = "foo"; | |
439 var arg_callback = "foo"; | |
440 var arg_cursor = 42; | |
441 var arg_domain = buildUnnamed1394(); | |
442 var arg_encode = "foo"; | |
443 var arg_exact = true; | |
444 var arg_filter = buildUnnamed1395(); | |
445 var arg_format = "foo"; | |
446 var arg_help = "foo"; | |
447 var arg_indent = true; | |
448 var arg_lang = buildUnnamed1396(); | |
449 var arg_limit = 42; | |
450 var arg_mid = buildUnnamed1397(); | |
451 var arg_mqlOutput = "foo"; | |
452 var arg_output = "foo"; | |
453 var arg_prefixed = true; | |
454 var arg_query = "foo"; | |
455 var arg_scoring = "foo"; | |
456 var arg_spell = "foo"; | |
457 var arg_stemmed = true; | |
458 var arg_type = buildUnnamed1398(); | |
459 var arg_with_ = buildUnnamed1399(); | |
460 var arg_without = buildUnnamed1400(); | |
461 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
462 var path = (req.url).path; | |
463 var pathOffset = 0; | |
464 var index; | |
465 var subPart; | |
466 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
467 pathOffset += 1; | |
468 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("freebase/v1/")); | |
469 pathOffset += 12; | |
470 unittest.expect(path.substring(pathOffset, pathOffset + 6), unittest.equ
als("search")); | |
471 pathOffset += 6; | |
472 | |
473 var query = (req.url).query; | |
474 var queryOffset = 0; | |
475 var queryMap = {}; | |
476 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
477 parseBool(n) { | |
478 if (n == "true") return true; | |
479 if (n == "false") return false; | |
480 if (n == null) return null; | |
481 throw new core.ArgumentError("Invalid boolean: $n"); | |
482 } | |
483 if (query.length > 0) { | |
484 for (var part in query.split("&")) { | |
485 var keyvalue = part.split("="); | |
486 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
487 } | |
488 } | |
489 unittest.expect(queryMap["as_of_time"].first, unittest.equals(arg_asOfTi
me)); | |
490 unittest.expect(queryMap["callback"].first, unittest.equals(arg_callback
)); | |
491 unittest.expect(core.int.parse(queryMap["cursor"].first), unittest.equal
s(arg_cursor)); | |
492 unittest.expect(queryMap["domain"], unittest.equals(arg_domain)); | |
493 unittest.expect(queryMap["encode"].first, unittest.equals(arg_encode)); | |
494 unittest.expect(queryMap["exact"].first, unittest.equals("$arg_exact")); | |
495 unittest.expect(queryMap["filter"], unittest.equals(arg_filter)); | |
496 unittest.expect(queryMap["format"].first, unittest.equals(arg_format)); | |
497 unittest.expect(queryMap["help"].first, unittest.equals(arg_help)); | |
498 unittest.expect(queryMap["indent"].first, unittest.equals("$arg_indent")
); | |
499 unittest.expect(queryMap["lang"], unittest.equals(arg_lang)); | |
500 unittest.expect(core.int.parse(queryMap["limit"].first), unittest.equals
(arg_limit)); | |
501 unittest.expect(queryMap["mid"], unittest.equals(arg_mid)); | |
502 unittest.expect(queryMap["mql_output"].first, unittest.equals(arg_mqlOut
put)); | |
503 unittest.expect(queryMap["output"].first, unittest.equals(arg_output)); | |
504 unittest.expect(queryMap["prefixed"].first, unittest.equals("$arg_prefix
ed")); | |
505 unittest.expect(queryMap["query"].first, unittest.equals(arg_query)); | |
506 unittest.expect(queryMap["scoring"].first, unittest.equals(arg_scoring))
; | |
507 unittest.expect(queryMap["spell"].first, unittest.equals(arg_spell)); | |
508 unittest.expect(queryMap["stemmed"].first, unittest.equals("$arg_stemmed
")); | |
509 unittest.expect(queryMap["type"], unittest.equals(arg_type)); | |
510 unittest.expect(queryMap["with"], unittest.equals(arg_with_)); | |
511 unittest.expect(queryMap["without"], unittest.equals(arg_without)); | |
512 | |
513 | |
514 var h = { | |
515 "content-type" : "application/json; charset=utf-8", | |
516 }; | |
517 var resp = ""; | |
518 return new async.Future.value(stringResponse(200, h, resp)); | |
519 }), true); | |
520 res.search(asOfTime: arg_asOfTime, callback: arg_callback, cursor: arg_cur
sor, domain: arg_domain, encode: arg_encode, exact: arg_exact, filter: arg_filte
r, format: arg_format, help: arg_help, indent: arg_indent, lang: arg_lang, limit
: arg_limit, mid: arg_mid, mqlOutput: arg_mqlOutput, output: arg_output, prefixe
d: arg_prefixed, query: arg_query, scoring: arg_scoring, spell: arg_spell, stemm
ed: arg_stemmed, type: arg_type, with_: arg_with_, without: arg_without).then(un
ittest.expectAsync((_) {})); | |
521 }); | |
522 | |
523 }); | |
524 | |
525 | |
526 } | |
527 | |
OLD | NEW |