OLD | NEW |
1 library googleapis.appstate.v1.test; | 1 library googleapis.appstate.v1.test; |
2 | 2 |
3 import "dart:core" as core; | 3 import "dart:core" as core; |
4 import "dart:collection" as collection; | 4 import "dart:collection" as collection; |
5 import "dart:async" as async; | 5 import "dart:async" as async; |
6 import "dart:convert" as convert; | 6 import "dart:convert" as convert; |
7 | 7 |
8 import 'package:http/http.dart' as http; | 8 import 'package:http/http.dart' as http; |
9 import 'package:http/testing.dart' as http_testing; | 9 import 'package:http/testing.dart' as http_testing; |
10 import 'package:unittest/unittest.dart' as unittest; | 10 import 'package:test/test.dart' as unittest; |
11 | 11 |
12 import 'package:googleapis/appstate/v1.dart' as api; | 12 import 'package:googleapis/appstate/v1.dart' as api; |
13 | 13 |
14 class HttpServerMock extends http.BaseClient { | 14 class HttpServerMock extends http.BaseClient { |
15 core.Function _callback; | 15 core.Function _callback; |
16 core.bool _expectJson; | 16 core.bool _expectJson; |
17 | 17 |
18 void register(core.Function callback, core.bool expectJson) { | 18 void register(core.Function callback, core.bool expectJson) { |
19 _callback = callback; | 19 _callback = callback; |
20 _expectJson = expectJson; | 20 _expectJson = expectJson; |
(...skipping 18 matching lines...) Expand all Loading... |
39 } else { | 39 } else { |
40 return stream.toBytes().then((data) { | 40 return stream.toBytes().then((data) { |
41 return _callback(request, data); | 41 return _callback(request, data); |
42 }); | 42 }); |
43 } | 43 } |
44 } | 44 } |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 http.StreamedResponse stringResponse( | 48 http.StreamedResponse stringResponse( |
49 core.int status, core.Map headers, core.String body) { | 49 core.int status, core.Map<core.String, core.String> headers, core.String bod
y) { |
50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
51 return new http.StreamedResponse(stream, status, headers: headers); | 51 return new http.StreamedResponse(stream, status, headers: headers); |
52 } | 52 } |
53 | 53 |
54 core.int buildCounterGetResponse = 0; | 54 core.int buildCounterGetResponse = 0; |
55 buildGetResponse() { | 55 buildGetResponse() { |
56 var o = new api.GetResponse(); | 56 var o = new api.GetResponse(); |
57 buildCounterGetResponse++; | 57 buildCounterGetResponse++; |
58 if (buildCounterGetResponse < 3) { | 58 if (buildCounterGetResponse < 3) { |
59 o.currentStateVersion = "foo"; | 59 o.currentStateVersion = "foo"; |
60 o.data = "foo"; | 60 o.data = "foo"; |
61 o.kind = "foo"; | 61 o.kind = "foo"; |
62 o.stateKey = 42; | 62 o.stateKey = 42; |
63 } | 63 } |
64 buildCounterGetResponse--; | 64 buildCounterGetResponse--; |
65 return o; | 65 return o; |
66 } | 66 } |
67 | 67 |
68 checkGetResponse(api.GetResponse o) { | 68 checkGetResponse(api.GetResponse o) { |
69 buildCounterGetResponse++; | 69 buildCounterGetResponse++; |
70 if (buildCounterGetResponse < 3) { | 70 if (buildCounterGetResponse < 3) { |
71 unittest.expect(o.currentStateVersion, unittest.equals('foo')); | 71 unittest.expect(o.currentStateVersion, unittest.equals('foo')); |
72 unittest.expect(o.data, unittest.equals('foo')); | 72 unittest.expect(o.data, unittest.equals('foo')); |
73 unittest.expect(o.kind, unittest.equals('foo')); | 73 unittest.expect(o.kind, unittest.equals('foo')); |
74 unittest.expect(o.stateKey, unittest.equals(42)); | 74 unittest.expect(o.stateKey, unittest.equals(42)); |
75 } | 75 } |
76 buildCounterGetResponse--; | 76 buildCounterGetResponse--; |
77 } | 77 } |
78 | 78 |
79 buildUnnamed2888() { | 79 buildUnnamed2358() { |
80 var o = new core.List<api.GetResponse>(); | 80 var o = new core.List<api.GetResponse>(); |
81 o.add(buildGetResponse()); | 81 o.add(buildGetResponse()); |
82 o.add(buildGetResponse()); | 82 o.add(buildGetResponse()); |
83 return o; | 83 return o; |
84 } | 84 } |
85 | 85 |
86 checkUnnamed2888(core.List<api.GetResponse> o) { | 86 checkUnnamed2358(core.List<api.GetResponse> o) { |
87 unittest.expect(o, unittest.hasLength(2)); | 87 unittest.expect(o, unittest.hasLength(2)); |
88 checkGetResponse(o[0]); | 88 checkGetResponse(o[0]); |
89 checkGetResponse(o[1]); | 89 checkGetResponse(o[1]); |
90 } | 90 } |
91 | 91 |
92 core.int buildCounterListResponse = 0; | 92 core.int buildCounterListResponse = 0; |
93 buildListResponse() { | 93 buildListResponse() { |
94 var o = new api.ListResponse(); | 94 var o = new api.ListResponse(); |
95 buildCounterListResponse++; | 95 buildCounterListResponse++; |
96 if (buildCounterListResponse < 3) { | 96 if (buildCounterListResponse < 3) { |
97 o.items = buildUnnamed2888(); | 97 o.items = buildUnnamed2358(); |
98 o.kind = "foo"; | 98 o.kind = "foo"; |
99 o.maximumKeyCount = 42; | 99 o.maximumKeyCount = 42; |
100 } | 100 } |
101 buildCounterListResponse--; | 101 buildCounterListResponse--; |
102 return o; | 102 return o; |
103 } | 103 } |
104 | 104 |
105 checkListResponse(api.ListResponse o) { | 105 checkListResponse(api.ListResponse o) { |
106 buildCounterListResponse++; | 106 buildCounterListResponse++; |
107 if (buildCounterListResponse < 3) { | 107 if (buildCounterListResponse < 3) { |
108 checkUnnamed2888(o.items); | 108 checkUnnamed2358(o.items); |
109 unittest.expect(o.kind, unittest.equals('foo')); | 109 unittest.expect(o.kind, unittest.equals('foo')); |
110 unittest.expect(o.maximumKeyCount, unittest.equals(42)); | 110 unittest.expect(o.maximumKeyCount, unittest.equals(42)); |
111 } | 111 } |
112 buildCounterListResponse--; | 112 buildCounterListResponse--; |
113 } | 113 } |
114 | 114 |
115 core.int buildCounterUpdateRequest = 0; | 115 core.int buildCounterUpdateRequest = 0; |
116 buildUpdateRequest() { | 116 buildUpdateRequest() { |
117 var o = new api.UpdateRequest(); | 117 var o = new api.UpdateRequest(); |
118 buildCounterUpdateRequest++; | 118 buildCounterUpdateRequest++; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 }); | 194 }); |
195 | 195 |
196 | 196 |
197 unittest.group("resource-StatesResourceApi", () { | 197 unittest.group("resource-StatesResourceApi", () { |
198 unittest.test("method--clear", () { | 198 unittest.test("method--clear", () { |
199 | 199 |
200 var mock = new HttpServerMock(); | 200 var mock = new HttpServerMock(); |
201 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 201 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
202 var arg_stateKey = 42; | 202 var arg_stateKey = 42; |
203 var arg_currentDataVersion = "foo"; | 203 var arg_currentDataVersion = "foo"; |
204 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 204 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
205 var path = (req.url).path; | 205 var path = (req.url).path; |
206 var pathOffset = 0; | 206 var pathOffset = 0; |
207 var index; | 207 var index; |
208 var subPart; | 208 var subPart; |
209 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 209 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
210 pathOffset += 1; | 210 pathOffset += 1; |
211 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); | 211 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); |
212 pathOffset += 12; | 212 pathOffset += 12; |
213 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("states/")); | 213 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("states/")); |
214 pathOffset += 7; | 214 pathOffset += 7; |
(...skipping 23 matching lines...) Expand all Loading... |
238 } | 238 } |
239 unittest.expect(queryMap["currentDataVersion"].first, unittest.equals(ar
g_currentDataVersion)); | 239 unittest.expect(queryMap["currentDataVersion"].first, unittest.equals(ar
g_currentDataVersion)); |
240 | 240 |
241 | 241 |
242 var h = { | 242 var h = { |
243 "content-type" : "application/json; charset=utf-8", | 243 "content-type" : "application/json; charset=utf-8", |
244 }; | 244 }; |
245 var resp = convert.JSON.encode(buildWriteResult()); | 245 var resp = convert.JSON.encode(buildWriteResult()); |
246 return new async.Future.value(stringResponse(200, h, resp)); | 246 return new async.Future.value(stringResponse(200, h, resp)); |
247 }), true); | 247 }), true); |
248 res.clear(arg_stateKey, currentDataVersion: arg_currentDataVersion).then(u
nittest.expectAsync(((api.WriteResult response) { | 248 res.clear(arg_stateKey, currentDataVersion: arg_currentDataVersion).then(u
nittest.expectAsync1(((api.WriteResult response) { |
249 checkWriteResult(response); | 249 checkWriteResult(response); |
250 }))); | 250 }))); |
251 }); | 251 }); |
252 | 252 |
253 unittest.test("method--delete", () { | 253 unittest.test("method--delete", () { |
254 | 254 |
255 var mock = new HttpServerMock(); | 255 var mock = new HttpServerMock(); |
256 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 256 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
257 var arg_stateKey = 42; | 257 var arg_stateKey = 42; |
258 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 258 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
259 var path = (req.url).path; | 259 var path = (req.url).path; |
260 var pathOffset = 0; | 260 var pathOffset = 0; |
261 var index; | 261 var index; |
262 var subPart; | 262 var subPart; |
263 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 263 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
264 pathOffset += 1; | 264 pathOffset += 1; |
265 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); | 265 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); |
266 pathOffset += 12; | 266 pathOffset += 12; |
267 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("states/")); | 267 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("states/")); |
268 pathOffset += 7; | 268 pathOffset += 7; |
(...skipping 18 matching lines...) Expand all Loading... |
287 } | 287 } |
288 } | 288 } |
289 | 289 |
290 | 290 |
291 var h = { | 291 var h = { |
292 "content-type" : "application/json; charset=utf-8", | 292 "content-type" : "application/json; charset=utf-8", |
293 }; | 293 }; |
294 var resp = ""; | 294 var resp = ""; |
295 return new async.Future.value(stringResponse(200, h, resp)); | 295 return new async.Future.value(stringResponse(200, h, resp)); |
296 }), true); | 296 }), true); |
297 res.delete(arg_stateKey).then(unittest.expectAsync((_) {})); | 297 res.delete(arg_stateKey).then(unittest.expectAsync1((_) {})); |
298 }); | 298 }); |
299 | 299 |
300 unittest.test("method--get", () { | 300 unittest.test("method--get", () { |
301 | 301 |
302 var mock = new HttpServerMock(); | 302 var mock = new HttpServerMock(); |
303 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 303 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
304 var arg_stateKey = 42; | 304 var arg_stateKey = 42; |
305 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 305 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
306 var path = (req.url).path; | 306 var path = (req.url).path; |
307 var pathOffset = 0; | 307 var pathOffset = 0; |
308 var index; | 308 var index; |
309 var subPart; | 309 var subPart; |
310 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 310 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
311 pathOffset += 1; | 311 pathOffset += 1; |
312 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); | 312 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); |
313 pathOffset += 12; | 313 pathOffset += 12; |
314 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("states/")); | 314 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("states/")); |
315 pathOffset += 7; | 315 pathOffset += 7; |
(...skipping 18 matching lines...) Expand all Loading... |
334 } | 334 } |
335 } | 335 } |
336 | 336 |
337 | 337 |
338 var h = { | 338 var h = { |
339 "content-type" : "application/json; charset=utf-8", | 339 "content-type" : "application/json; charset=utf-8", |
340 }; | 340 }; |
341 var resp = convert.JSON.encode(buildGetResponse()); | 341 var resp = convert.JSON.encode(buildGetResponse()); |
342 return new async.Future.value(stringResponse(200, h, resp)); | 342 return new async.Future.value(stringResponse(200, h, resp)); |
343 }), true); | 343 }), true); |
344 res.get(arg_stateKey).then(unittest.expectAsync(((api.GetResponse response
) { | 344 res.get(arg_stateKey).then(unittest.expectAsync1(((api.GetResponse respons
e) { |
345 checkGetResponse(response); | 345 checkGetResponse(response); |
346 }))); | 346 }))); |
347 }); | 347 }); |
348 | 348 |
349 unittest.test("method--list", () { | 349 unittest.test("method--list", () { |
350 | 350 |
351 var mock = new HttpServerMock(); | 351 var mock = new HttpServerMock(); |
352 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 352 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
353 var arg_includeData = true; | 353 var arg_includeData = true; |
354 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 354 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
355 var path = (req.url).path; | 355 var path = (req.url).path; |
356 var pathOffset = 0; | 356 var pathOffset = 0; |
357 var index; | 357 var index; |
358 var subPart; | 358 var subPart; |
359 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 359 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
360 pathOffset += 1; | 360 pathOffset += 1; |
361 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); | 361 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); |
362 pathOffset += 12; | 362 pathOffset += 12; |
363 unittest.expect(path.substring(pathOffset, pathOffset + 6), unittest.equ
als("states")); | 363 unittest.expect(path.substring(pathOffset, pathOffset + 6), unittest.equ
als("states")); |
364 pathOffset += 6; | 364 pathOffset += 6; |
(...skipping 16 matching lines...) Expand all Loading... |
381 } | 381 } |
382 unittest.expect(queryMap["includeData"].first, unittest.equals("$arg_inc
ludeData")); | 382 unittest.expect(queryMap["includeData"].first, unittest.equals("$arg_inc
ludeData")); |
383 | 383 |
384 | 384 |
385 var h = { | 385 var h = { |
386 "content-type" : "application/json; charset=utf-8", | 386 "content-type" : "application/json; charset=utf-8", |
387 }; | 387 }; |
388 var resp = convert.JSON.encode(buildListResponse()); | 388 var resp = convert.JSON.encode(buildListResponse()); |
389 return new async.Future.value(stringResponse(200, h, resp)); | 389 return new async.Future.value(stringResponse(200, h, resp)); |
390 }), true); | 390 }), true); |
391 res.list(includeData: arg_includeData).then(unittest.expectAsync(((api.Lis
tResponse response) { | 391 res.list(includeData: arg_includeData).then(unittest.expectAsync1(((api.Li
stResponse response) { |
392 checkListResponse(response); | 392 checkListResponse(response); |
393 }))); | 393 }))); |
394 }); | 394 }); |
395 | 395 |
396 unittest.test("method--update", () { | 396 unittest.test("method--update", () { |
397 | 397 |
398 var mock = new HttpServerMock(); | 398 var mock = new HttpServerMock(); |
399 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 399 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
400 var arg_request = buildUpdateRequest(); | 400 var arg_request = buildUpdateRequest(); |
401 var arg_stateKey = 42; | 401 var arg_stateKey = 42; |
402 var arg_currentStateVersion = "foo"; | 402 var arg_currentStateVersion = "foo"; |
403 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 403 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
404 var obj = new api.UpdateRequest.fromJson(json); | 404 var obj = new api.UpdateRequest.fromJson(json); |
405 checkUpdateRequest(obj); | 405 checkUpdateRequest(obj); |
406 | 406 |
407 var path = (req.url).path; | 407 var path = (req.url).path; |
408 var pathOffset = 0; | 408 var pathOffset = 0; |
409 var index; | 409 var index; |
410 var subPart; | 410 var subPart; |
411 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 411 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
412 pathOffset += 1; | 412 pathOffset += 1; |
413 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); | 413 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("appstate/v1/")); |
(...skipping 22 matching lines...) Expand all Loading... |
436 } | 436 } |
437 unittest.expect(queryMap["currentStateVersion"].first, unittest.equals(a
rg_currentStateVersion)); | 437 unittest.expect(queryMap["currentStateVersion"].first, unittest.equals(a
rg_currentStateVersion)); |
438 | 438 |
439 | 439 |
440 var h = { | 440 var h = { |
441 "content-type" : "application/json; charset=utf-8", | 441 "content-type" : "application/json; charset=utf-8", |
442 }; | 442 }; |
443 var resp = convert.JSON.encode(buildWriteResult()); | 443 var resp = convert.JSON.encode(buildWriteResult()); |
444 return new async.Future.value(stringResponse(200, h, resp)); | 444 return new async.Future.value(stringResponse(200, h, resp)); |
445 }), true); | 445 }), true); |
446 res.update(arg_request, arg_stateKey, currentStateVersion: arg_currentStat
eVersion).then(unittest.expectAsync(((api.WriteResult response) { | 446 res.update(arg_request, arg_stateKey, currentStateVersion: arg_currentStat
eVersion).then(unittest.expectAsync1(((api.WriteResult response) { |
447 checkWriteResult(response); | 447 checkWriteResult(response); |
448 }))); | 448 }))); |
449 }); | 449 }); |
450 | 450 |
451 }); | 451 }); |
452 | 452 |
453 | 453 |
454 } | 454 } |
455 | 455 |
OLD | NEW |