| 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:unittest/unittest.dart' as unittest; |
| 11 import 'package:googleapis/common/common.dart' as common; | |
| 12 import 'package:googleapis/src/common_internal.dart' as common_internal; | |
| 13 import '../common/common_internal_test.dart' as common_test; | |
| 14 | 11 |
| 15 import 'package:googleapis/appstate/v1.dart' as api; | 12 import 'package:googleapis/appstate/v1.dart' as api; |
| 16 | 13 |
| 14 class HttpServerMock extends http.BaseClient { |
| 15 core.Function _callback; |
| 16 core.bool _expectJson; |
| 17 | 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 } |
| 18 | 53 |
| 19 core.int buildCounterGetResponse = 0; | 54 core.int buildCounterGetResponse = 0; |
| 20 buildGetResponse() { | 55 buildGetResponse() { |
| 21 var o = new api.GetResponse(); | 56 var o = new api.GetResponse(); |
| 22 buildCounterGetResponse++; | 57 buildCounterGetResponse++; |
| 23 if (buildCounterGetResponse < 3) { | 58 if (buildCounterGetResponse < 3) { |
| 24 o.currentStateVersion = "foo"; | 59 o.currentStateVersion = "foo"; |
| 25 o.data = "foo"; | 60 o.data = "foo"; |
| 26 o.kind = "foo"; | 61 o.kind = "foo"; |
| 27 o.stateKey = 42; | 62 o.stateKey = 42; |
| 28 } | 63 } |
| 29 buildCounterGetResponse--; | 64 buildCounterGetResponse--; |
| 30 return o; | 65 return o; |
| 31 } | 66 } |
| 32 | 67 |
| 33 checkGetResponse(api.GetResponse o) { | 68 checkGetResponse(api.GetResponse o) { |
| 34 buildCounterGetResponse++; | 69 buildCounterGetResponse++; |
| 35 if (buildCounterGetResponse < 3) { | 70 if (buildCounterGetResponse < 3) { |
| 36 unittest.expect(o.currentStateVersion, unittest.equals('foo')); | 71 unittest.expect(o.currentStateVersion, unittest.equals('foo')); |
| 37 unittest.expect(o.data, unittest.equals('foo')); | 72 unittest.expect(o.data, unittest.equals('foo')); |
| 38 unittest.expect(o.kind, unittest.equals('foo')); | 73 unittest.expect(o.kind, unittest.equals('foo')); |
| 39 unittest.expect(o.stateKey, unittest.equals(42)); | 74 unittest.expect(o.stateKey, unittest.equals(42)); |
| 40 } | 75 } |
| 41 buildCounterGetResponse--; | 76 buildCounterGetResponse--; |
| 42 } | 77 } |
| 43 | 78 |
| 44 buildUnnamed1382() { | 79 buildUnnamed284() { |
| 45 var o = new core.List<api.GetResponse>(); | 80 var o = new core.List<api.GetResponse>(); |
| 46 o.add(buildGetResponse()); | 81 o.add(buildGetResponse()); |
| 47 o.add(buildGetResponse()); | 82 o.add(buildGetResponse()); |
| 48 return o; | 83 return o; |
| 49 } | 84 } |
| 50 | 85 |
| 51 checkUnnamed1382(core.List<api.GetResponse> o) { | 86 checkUnnamed284(core.List<api.GetResponse> o) { |
| 52 unittest.expect(o, unittest.hasLength(2)); | 87 unittest.expect(o, unittest.hasLength(2)); |
| 53 checkGetResponse(o[0]); | 88 checkGetResponse(o[0]); |
| 54 checkGetResponse(o[1]); | 89 checkGetResponse(o[1]); |
| 55 } | 90 } |
| 56 | 91 |
| 57 core.int buildCounterListResponse = 0; | 92 core.int buildCounterListResponse = 0; |
| 58 buildListResponse() { | 93 buildListResponse() { |
| 59 var o = new api.ListResponse(); | 94 var o = new api.ListResponse(); |
| 60 buildCounterListResponse++; | 95 buildCounterListResponse++; |
| 61 if (buildCounterListResponse < 3) { | 96 if (buildCounterListResponse < 3) { |
| 62 o.items = buildUnnamed1382(); | 97 o.items = buildUnnamed284(); |
| 63 o.kind = "foo"; | 98 o.kind = "foo"; |
| 64 o.maximumKeyCount = 42; | 99 o.maximumKeyCount = 42; |
| 65 } | 100 } |
| 66 buildCounterListResponse--; | 101 buildCounterListResponse--; |
| 67 return o; | 102 return o; |
| 68 } | 103 } |
| 69 | 104 |
| 70 checkListResponse(api.ListResponse o) { | 105 checkListResponse(api.ListResponse o) { |
| 71 buildCounterListResponse++; | 106 buildCounterListResponse++; |
| 72 if (buildCounterListResponse < 3) { | 107 if (buildCounterListResponse < 3) { |
| 73 checkUnnamed1382(o.items); | 108 checkUnnamed284(o.items); |
| 74 unittest.expect(o.kind, unittest.equals('foo')); | 109 unittest.expect(o.kind, unittest.equals('foo')); |
| 75 unittest.expect(o.maximumKeyCount, unittest.equals(42)); | 110 unittest.expect(o.maximumKeyCount, unittest.equals(42)); |
| 76 } | 111 } |
| 77 buildCounterListResponse--; | 112 buildCounterListResponse--; |
| 78 } | 113 } |
| 79 | 114 |
| 80 core.int buildCounterUpdateRequest = 0; | 115 core.int buildCounterUpdateRequest = 0; |
| 81 buildUpdateRequest() { | 116 buildUpdateRequest() { |
| 82 var o = new api.UpdateRequest(); | 117 var o = new api.UpdateRequest(); |
| 83 buildCounterUpdateRequest++; | 118 buildCounterUpdateRequest++; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 var o = buildWriteResult(); | 190 var o = buildWriteResult(); |
| 156 var od = new api.WriteResult.fromJson(o.toJson()); | 191 var od = new api.WriteResult.fromJson(o.toJson()); |
| 157 checkWriteResult(od); | 192 checkWriteResult(od); |
| 158 }); | 193 }); |
| 159 }); | 194 }); |
| 160 | 195 |
| 161 | 196 |
| 162 unittest.group("resource-StatesResourceApi", () { | 197 unittest.group("resource-StatesResourceApi", () { |
| 163 unittest.test("method--clear", () { | 198 unittest.test("method--clear", () { |
| 164 | 199 |
| 165 var mock = new common_test.HttpServerMock(); | 200 var mock = new HttpServerMock(); |
| 166 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 201 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
| 167 var arg_stateKey = 42; | 202 var arg_stateKey = 42; |
| 168 var arg_currentDataVersion = "foo"; | 203 var arg_currentDataVersion = "foo"; |
| 169 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 204 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 170 var path = (req.url).path; | 205 var path = (req.url).path; |
| 171 var pathOffset = 0; | 206 var pathOffset = 0; |
| 172 var index; | 207 var index; |
| 173 var subPart; | 208 var subPart; |
| 174 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 209 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 175 pathOffset += 1; | 210 pathOffset += 1; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 201 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 236 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 202 } | 237 } |
| 203 } | 238 } |
| 204 unittest.expect(queryMap["currentDataVersion"].first, unittest.equals(ar
g_currentDataVersion)); | 239 unittest.expect(queryMap["currentDataVersion"].first, unittest.equals(ar
g_currentDataVersion)); |
| 205 | 240 |
| 206 | 241 |
| 207 var h = { | 242 var h = { |
| 208 "content-type" : "application/json; charset=utf-8", | 243 "content-type" : "application/json; charset=utf-8", |
| 209 }; | 244 }; |
| 210 var resp = convert.JSON.encode(buildWriteResult()); | 245 var resp = convert.JSON.encode(buildWriteResult()); |
| 211 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 246 return new async.Future.value(stringResponse(200, h, resp)); |
| 212 }), true); | 247 }), true); |
| 213 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.expectAsync(((api.WriteResult response) { |
| 214 checkWriteResult(response); | 249 checkWriteResult(response); |
| 215 }))); | 250 }))); |
| 216 }); | 251 }); |
| 217 | 252 |
| 218 unittest.test("method--delete", () { | 253 unittest.test("method--delete", () { |
| 219 | 254 |
| 220 var mock = new common_test.HttpServerMock(); | 255 var mock = new HttpServerMock(); |
| 221 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 256 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
| 222 var arg_stateKey = 42; | 257 var arg_stateKey = 42; |
| 223 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 258 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 224 var path = (req.url).path; | 259 var path = (req.url).path; |
| 225 var pathOffset = 0; | 260 var pathOffset = 0; |
| 226 var index; | 261 var index; |
| 227 var subPart; | 262 var subPart; |
| 228 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 263 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 229 pathOffset += 1; | 264 pathOffset += 1; |
| 230 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/")); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 250 var keyvalue = part.split("="); | 285 var keyvalue = part.split("="); |
| 251 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 286 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 252 } | 287 } |
| 253 } | 288 } |
| 254 | 289 |
| 255 | 290 |
| 256 var h = { | 291 var h = { |
| 257 "content-type" : "application/json; charset=utf-8", | 292 "content-type" : "application/json; charset=utf-8", |
| 258 }; | 293 }; |
| 259 var resp = ""; | 294 var resp = ""; |
| 260 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 295 return new async.Future.value(stringResponse(200, h, resp)); |
| 261 }), true); | 296 }), true); |
| 262 res.delete(arg_stateKey).then(unittest.expectAsync((_) {})); | 297 res.delete(arg_stateKey).then(unittest.expectAsync((_) {})); |
| 263 }); | 298 }); |
| 264 | 299 |
| 265 unittest.test("method--get", () { | 300 unittest.test("method--get", () { |
| 266 | 301 |
| 267 var mock = new common_test.HttpServerMock(); | 302 var mock = new HttpServerMock(); |
| 268 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 303 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
| 269 var arg_stateKey = 42; | 304 var arg_stateKey = 42; |
| 270 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 305 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 271 var path = (req.url).path; | 306 var path = (req.url).path; |
| 272 var pathOffset = 0; | 307 var pathOffset = 0; |
| 273 var index; | 308 var index; |
| 274 var subPart; | 309 var subPart; |
| 275 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 310 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 276 pathOffset += 1; | 311 pathOffset += 1; |
| 277 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/")); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 297 var keyvalue = part.split("="); | 332 var keyvalue = part.split("="); |
| 298 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 333 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 299 } | 334 } |
| 300 } | 335 } |
| 301 | 336 |
| 302 | 337 |
| 303 var h = { | 338 var h = { |
| 304 "content-type" : "application/json; charset=utf-8", | 339 "content-type" : "application/json; charset=utf-8", |
| 305 }; | 340 }; |
| 306 var resp = convert.JSON.encode(buildGetResponse()); | 341 var resp = convert.JSON.encode(buildGetResponse()); |
| 307 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 342 return new async.Future.value(stringResponse(200, h, resp)); |
| 308 }), true); | 343 }), true); |
| 309 res.get(arg_stateKey).then(unittest.expectAsync(((api.GetResponse response
) { | 344 res.get(arg_stateKey).then(unittest.expectAsync(((api.GetResponse response
) { |
| 310 checkGetResponse(response); | 345 checkGetResponse(response); |
| 311 }))); | 346 }))); |
| 312 }); | 347 }); |
| 313 | 348 |
| 314 unittest.test("method--list", () { | 349 unittest.test("method--list", () { |
| 315 | 350 |
| 316 var mock = new common_test.HttpServerMock(); | 351 var mock = new HttpServerMock(); |
| 317 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 352 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
| 318 var arg_includeData = true; | 353 var arg_includeData = true; |
| 319 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 354 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 320 var path = (req.url).path; | 355 var path = (req.url).path; |
| 321 var pathOffset = 0; | 356 var pathOffset = 0; |
| 322 var index; | 357 var index; |
| 323 var subPart; | 358 var subPart; |
| 324 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 359 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 325 pathOffset += 1; | 360 pathOffset += 1; |
| 326 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/")); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 344 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 379 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 345 } | 380 } |
| 346 } | 381 } |
| 347 unittest.expect(queryMap["includeData"].first, unittest.equals("$arg_inc
ludeData")); | 382 unittest.expect(queryMap["includeData"].first, unittest.equals("$arg_inc
ludeData")); |
| 348 | 383 |
| 349 | 384 |
| 350 var h = { | 385 var h = { |
| 351 "content-type" : "application/json; charset=utf-8", | 386 "content-type" : "application/json; charset=utf-8", |
| 352 }; | 387 }; |
| 353 var resp = convert.JSON.encode(buildListResponse()); | 388 var resp = convert.JSON.encode(buildListResponse()); |
| 354 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 389 return new async.Future.value(stringResponse(200, h, resp)); |
| 355 }), true); | 390 }), true); |
| 356 res.list(includeData: arg_includeData).then(unittest.expectAsync(((api.Lis
tResponse response) { | 391 res.list(includeData: arg_includeData).then(unittest.expectAsync(((api.Lis
tResponse response) { |
| 357 checkListResponse(response); | 392 checkListResponse(response); |
| 358 }))); | 393 }))); |
| 359 }); | 394 }); |
| 360 | 395 |
| 361 unittest.test("method--update", () { | 396 unittest.test("method--update", () { |
| 362 | 397 |
| 363 var mock = new common_test.HttpServerMock(); | 398 var mock = new HttpServerMock(); |
| 364 api.StatesResourceApi res = new api.AppstateApi(mock).states; | 399 api.StatesResourceApi res = new api.AppstateApi(mock).states; |
| 365 var arg_request = buildUpdateRequest(); | 400 var arg_request = buildUpdateRequest(); |
| 366 var arg_stateKey = 42; | 401 var arg_stateKey = 42; |
| 367 var arg_currentStateVersion = "foo"; | 402 var arg_currentStateVersion = "foo"; |
| 368 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 403 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 369 var obj = new api.UpdateRequest.fromJson(json); | 404 var obj = new api.UpdateRequest.fromJson(json); |
| 370 checkUpdateRequest(obj); | 405 checkUpdateRequest(obj); |
| 371 | 406 |
| 372 var path = (req.url).path; | 407 var path = (req.url).path; |
| 373 var pathOffset = 0; | 408 var pathOffset = 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 399 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 434 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 400 } | 435 } |
| 401 } | 436 } |
| 402 unittest.expect(queryMap["currentStateVersion"].first, unittest.equals(a
rg_currentStateVersion)); | 437 unittest.expect(queryMap["currentStateVersion"].first, unittest.equals(a
rg_currentStateVersion)); |
| 403 | 438 |
| 404 | 439 |
| 405 var h = { | 440 var h = { |
| 406 "content-type" : "application/json; charset=utf-8", | 441 "content-type" : "application/json; charset=utf-8", |
| 407 }; | 442 }; |
| 408 var resp = convert.JSON.encode(buildWriteResult()); | 443 var resp = convert.JSON.encode(buildWriteResult()); |
| 409 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 444 return new async.Future.value(stringResponse(200, h, resp)); |
| 410 }), true); | 445 }), true); |
| 411 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.expectAsync(((api.WriteResult response) { |
| 412 checkWriteResult(response); | 447 checkWriteResult(response); |
| 413 }))); | 448 }))); |
| 414 }); | 449 }); |
| 415 | 450 |
| 416 }); | 451 }); |
| 417 | 452 |
| 418 | 453 |
| 419 } | 454 } |
| 420 | 455 |
| OLD | NEW |