| OLD | NEW |
| (Empty) | |
| 1 library googleapis.cloudresourcemanager.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/cloudresourcemanager/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 buildUnnamed2140() { |
| 55 var o = new core.List<core.String>(); |
| 56 o.add("foo"); |
| 57 o.add("foo"); |
| 58 return o; |
| 59 } |
| 60 |
| 61 checkUnnamed2140(core.List<core.String> o) { |
| 62 unittest.expect(o, unittest.hasLength(2)); |
| 63 unittest.expect(o[0], unittest.equals('foo')); |
| 64 unittest.expect(o[1], unittest.equals('foo')); |
| 65 } |
| 66 |
| 67 core.int buildCounterBinding = 0; |
| 68 buildBinding() { |
| 69 var o = new api.Binding(); |
| 70 buildCounterBinding++; |
| 71 if (buildCounterBinding < 3) { |
| 72 o.members = buildUnnamed2140(); |
| 73 o.role = "foo"; |
| 74 } |
| 75 buildCounterBinding--; |
| 76 return o; |
| 77 } |
| 78 |
| 79 checkBinding(api.Binding o) { |
| 80 buildCounterBinding++; |
| 81 if (buildCounterBinding < 3) { |
| 82 checkUnnamed2140(o.members); |
| 83 unittest.expect(o.role, unittest.equals('foo')); |
| 84 } |
| 85 buildCounterBinding--; |
| 86 } |
| 87 |
| 88 core.int buildCounterEmpty = 0; |
| 89 buildEmpty() { |
| 90 var o = new api.Empty(); |
| 91 buildCounterEmpty++; |
| 92 if (buildCounterEmpty < 3) { |
| 93 } |
| 94 buildCounterEmpty--; |
| 95 return o; |
| 96 } |
| 97 |
| 98 checkEmpty(api.Empty o) { |
| 99 buildCounterEmpty++; |
| 100 if (buildCounterEmpty < 3) { |
| 101 } |
| 102 buildCounterEmpty--; |
| 103 } |
| 104 |
| 105 core.int buildCounterGetIamPolicyRequest = 0; |
| 106 buildGetIamPolicyRequest() { |
| 107 var o = new api.GetIamPolicyRequest(); |
| 108 buildCounterGetIamPolicyRequest++; |
| 109 if (buildCounterGetIamPolicyRequest < 3) { |
| 110 } |
| 111 buildCounterGetIamPolicyRequest--; |
| 112 return o; |
| 113 } |
| 114 |
| 115 checkGetIamPolicyRequest(api.GetIamPolicyRequest o) { |
| 116 buildCounterGetIamPolicyRequest++; |
| 117 if (buildCounterGetIamPolicyRequest < 3) { |
| 118 } |
| 119 buildCounterGetIamPolicyRequest--; |
| 120 } |
| 121 |
| 122 buildUnnamed2141() { |
| 123 var o = new core.List<api.Project>(); |
| 124 o.add(buildProject()); |
| 125 o.add(buildProject()); |
| 126 return o; |
| 127 } |
| 128 |
| 129 checkUnnamed2141(core.List<api.Project> o) { |
| 130 unittest.expect(o, unittest.hasLength(2)); |
| 131 checkProject(o[0]); |
| 132 checkProject(o[1]); |
| 133 } |
| 134 |
| 135 core.int buildCounterListProjectsResponse = 0; |
| 136 buildListProjectsResponse() { |
| 137 var o = new api.ListProjectsResponse(); |
| 138 buildCounterListProjectsResponse++; |
| 139 if (buildCounterListProjectsResponse < 3) { |
| 140 o.nextPageToken = "foo"; |
| 141 o.projects = buildUnnamed2141(); |
| 142 } |
| 143 buildCounterListProjectsResponse--; |
| 144 return o; |
| 145 } |
| 146 |
| 147 checkListProjectsResponse(api.ListProjectsResponse o) { |
| 148 buildCounterListProjectsResponse++; |
| 149 if (buildCounterListProjectsResponse < 3) { |
| 150 unittest.expect(o.nextPageToken, unittest.equals('foo')); |
| 151 checkUnnamed2141(o.projects); |
| 152 } |
| 153 buildCounterListProjectsResponse--; |
| 154 } |
| 155 |
| 156 buildUnnamed2142() { |
| 157 var o = new core.List<api.Binding>(); |
| 158 o.add(buildBinding()); |
| 159 o.add(buildBinding()); |
| 160 return o; |
| 161 } |
| 162 |
| 163 checkUnnamed2142(core.List<api.Binding> o) { |
| 164 unittest.expect(o, unittest.hasLength(2)); |
| 165 checkBinding(o[0]); |
| 166 checkBinding(o[1]); |
| 167 } |
| 168 |
| 169 core.int buildCounterPolicy = 0; |
| 170 buildPolicy() { |
| 171 var o = new api.Policy(); |
| 172 buildCounterPolicy++; |
| 173 if (buildCounterPolicy < 3) { |
| 174 o.bindings = buildUnnamed2142(); |
| 175 o.etag = "foo"; |
| 176 o.version = 42; |
| 177 } |
| 178 buildCounterPolicy--; |
| 179 return o; |
| 180 } |
| 181 |
| 182 checkPolicy(api.Policy o) { |
| 183 buildCounterPolicy++; |
| 184 if (buildCounterPolicy < 3) { |
| 185 checkUnnamed2142(o.bindings); |
| 186 unittest.expect(o.etag, unittest.equals('foo')); |
| 187 unittest.expect(o.version, unittest.equals(42)); |
| 188 } |
| 189 buildCounterPolicy--; |
| 190 } |
| 191 |
| 192 buildUnnamed2143() { |
| 193 var o = new core.Map<core.String, core.String>(); |
| 194 o["x"] = "foo"; |
| 195 o["y"] = "foo"; |
| 196 return o; |
| 197 } |
| 198 |
| 199 checkUnnamed2143(core.Map<core.String, core.String> o) { |
| 200 unittest.expect(o, unittest.hasLength(2)); |
| 201 unittest.expect(o["x"], unittest.equals('foo')); |
| 202 unittest.expect(o["y"], unittest.equals('foo')); |
| 203 } |
| 204 |
| 205 core.int buildCounterProject = 0; |
| 206 buildProject() { |
| 207 var o = new api.Project(); |
| 208 buildCounterProject++; |
| 209 if (buildCounterProject < 3) { |
| 210 o.createTime = "foo"; |
| 211 o.labels = buildUnnamed2143(); |
| 212 o.lifecycleState = "foo"; |
| 213 o.name = "foo"; |
| 214 o.parent = buildResourceId(); |
| 215 o.projectId = "foo"; |
| 216 o.projectNumber = "foo"; |
| 217 } |
| 218 buildCounterProject--; |
| 219 return o; |
| 220 } |
| 221 |
| 222 checkProject(api.Project o) { |
| 223 buildCounterProject++; |
| 224 if (buildCounterProject < 3) { |
| 225 unittest.expect(o.createTime, unittest.equals('foo')); |
| 226 checkUnnamed2143(o.labels); |
| 227 unittest.expect(o.lifecycleState, unittest.equals('foo')); |
| 228 unittest.expect(o.name, unittest.equals('foo')); |
| 229 checkResourceId(o.parent); |
| 230 unittest.expect(o.projectId, unittest.equals('foo')); |
| 231 unittest.expect(o.projectNumber, unittest.equals('foo')); |
| 232 } |
| 233 buildCounterProject--; |
| 234 } |
| 235 |
| 236 core.int buildCounterResourceId = 0; |
| 237 buildResourceId() { |
| 238 var o = new api.ResourceId(); |
| 239 buildCounterResourceId++; |
| 240 if (buildCounterResourceId < 3) { |
| 241 o.id = "foo"; |
| 242 o.type = "foo"; |
| 243 } |
| 244 buildCounterResourceId--; |
| 245 return o; |
| 246 } |
| 247 |
| 248 checkResourceId(api.ResourceId o) { |
| 249 buildCounterResourceId++; |
| 250 if (buildCounterResourceId < 3) { |
| 251 unittest.expect(o.id, unittest.equals('foo')); |
| 252 unittest.expect(o.type, unittest.equals('foo')); |
| 253 } |
| 254 buildCounterResourceId--; |
| 255 } |
| 256 |
| 257 core.int buildCounterSetIamPolicyRequest = 0; |
| 258 buildSetIamPolicyRequest() { |
| 259 var o = new api.SetIamPolicyRequest(); |
| 260 buildCounterSetIamPolicyRequest++; |
| 261 if (buildCounterSetIamPolicyRequest < 3) { |
| 262 o.policy = buildPolicy(); |
| 263 } |
| 264 buildCounterSetIamPolicyRequest--; |
| 265 return o; |
| 266 } |
| 267 |
| 268 checkSetIamPolicyRequest(api.SetIamPolicyRequest o) { |
| 269 buildCounterSetIamPolicyRequest++; |
| 270 if (buildCounterSetIamPolicyRequest < 3) { |
| 271 checkPolicy(o.policy); |
| 272 } |
| 273 buildCounterSetIamPolicyRequest--; |
| 274 } |
| 275 |
| 276 buildUnnamed2144() { |
| 277 var o = new core.List<core.String>(); |
| 278 o.add("foo"); |
| 279 o.add("foo"); |
| 280 return o; |
| 281 } |
| 282 |
| 283 checkUnnamed2144(core.List<core.String> o) { |
| 284 unittest.expect(o, unittest.hasLength(2)); |
| 285 unittest.expect(o[0], unittest.equals('foo')); |
| 286 unittest.expect(o[1], unittest.equals('foo')); |
| 287 } |
| 288 |
| 289 core.int buildCounterTestIamPermissionsRequest = 0; |
| 290 buildTestIamPermissionsRequest() { |
| 291 var o = new api.TestIamPermissionsRequest(); |
| 292 buildCounterTestIamPermissionsRequest++; |
| 293 if (buildCounterTestIamPermissionsRequest < 3) { |
| 294 o.permissions = buildUnnamed2144(); |
| 295 } |
| 296 buildCounterTestIamPermissionsRequest--; |
| 297 return o; |
| 298 } |
| 299 |
| 300 checkTestIamPermissionsRequest(api.TestIamPermissionsRequest o) { |
| 301 buildCounterTestIamPermissionsRequest++; |
| 302 if (buildCounterTestIamPermissionsRequest < 3) { |
| 303 checkUnnamed2144(o.permissions); |
| 304 } |
| 305 buildCounterTestIamPermissionsRequest--; |
| 306 } |
| 307 |
| 308 buildUnnamed2145() { |
| 309 var o = new core.List<core.String>(); |
| 310 o.add("foo"); |
| 311 o.add("foo"); |
| 312 return o; |
| 313 } |
| 314 |
| 315 checkUnnamed2145(core.List<core.String> o) { |
| 316 unittest.expect(o, unittest.hasLength(2)); |
| 317 unittest.expect(o[0], unittest.equals('foo')); |
| 318 unittest.expect(o[1], unittest.equals('foo')); |
| 319 } |
| 320 |
| 321 core.int buildCounterTestIamPermissionsResponse = 0; |
| 322 buildTestIamPermissionsResponse() { |
| 323 var o = new api.TestIamPermissionsResponse(); |
| 324 buildCounterTestIamPermissionsResponse++; |
| 325 if (buildCounterTestIamPermissionsResponse < 3) { |
| 326 o.permissions = buildUnnamed2145(); |
| 327 } |
| 328 buildCounterTestIamPermissionsResponse--; |
| 329 return o; |
| 330 } |
| 331 |
| 332 checkTestIamPermissionsResponse(api.TestIamPermissionsResponse o) { |
| 333 buildCounterTestIamPermissionsResponse++; |
| 334 if (buildCounterTestIamPermissionsResponse < 3) { |
| 335 checkUnnamed2145(o.permissions); |
| 336 } |
| 337 buildCounterTestIamPermissionsResponse--; |
| 338 } |
| 339 |
| 340 core.int buildCounterUndeleteProjectRequest = 0; |
| 341 buildUndeleteProjectRequest() { |
| 342 var o = new api.UndeleteProjectRequest(); |
| 343 buildCounterUndeleteProjectRequest++; |
| 344 if (buildCounterUndeleteProjectRequest < 3) { |
| 345 } |
| 346 buildCounterUndeleteProjectRequest--; |
| 347 return o; |
| 348 } |
| 349 |
| 350 checkUndeleteProjectRequest(api.UndeleteProjectRequest o) { |
| 351 buildCounterUndeleteProjectRequest++; |
| 352 if (buildCounterUndeleteProjectRequest < 3) { |
| 353 } |
| 354 buildCounterUndeleteProjectRequest--; |
| 355 } |
| 356 |
| 357 |
| 358 main() { |
| 359 unittest.group("obj-schema-Binding", () { |
| 360 unittest.test("to-json--from-json", () { |
| 361 var o = buildBinding(); |
| 362 var od = new api.Binding.fromJson(o.toJson()); |
| 363 checkBinding(od); |
| 364 }); |
| 365 }); |
| 366 |
| 367 |
| 368 unittest.group("obj-schema-Empty", () { |
| 369 unittest.test("to-json--from-json", () { |
| 370 var o = buildEmpty(); |
| 371 var od = new api.Empty.fromJson(o.toJson()); |
| 372 checkEmpty(od); |
| 373 }); |
| 374 }); |
| 375 |
| 376 |
| 377 unittest.group("obj-schema-GetIamPolicyRequest", () { |
| 378 unittest.test("to-json--from-json", () { |
| 379 var o = buildGetIamPolicyRequest(); |
| 380 var od = new api.GetIamPolicyRequest.fromJson(o.toJson()); |
| 381 checkGetIamPolicyRequest(od); |
| 382 }); |
| 383 }); |
| 384 |
| 385 |
| 386 unittest.group("obj-schema-ListProjectsResponse", () { |
| 387 unittest.test("to-json--from-json", () { |
| 388 var o = buildListProjectsResponse(); |
| 389 var od = new api.ListProjectsResponse.fromJson(o.toJson()); |
| 390 checkListProjectsResponse(od); |
| 391 }); |
| 392 }); |
| 393 |
| 394 |
| 395 unittest.group("obj-schema-Policy", () { |
| 396 unittest.test("to-json--from-json", () { |
| 397 var o = buildPolicy(); |
| 398 var od = new api.Policy.fromJson(o.toJson()); |
| 399 checkPolicy(od); |
| 400 }); |
| 401 }); |
| 402 |
| 403 |
| 404 unittest.group("obj-schema-Project", () { |
| 405 unittest.test("to-json--from-json", () { |
| 406 var o = buildProject(); |
| 407 var od = new api.Project.fromJson(o.toJson()); |
| 408 checkProject(od); |
| 409 }); |
| 410 }); |
| 411 |
| 412 |
| 413 unittest.group("obj-schema-ResourceId", () { |
| 414 unittest.test("to-json--from-json", () { |
| 415 var o = buildResourceId(); |
| 416 var od = new api.ResourceId.fromJson(o.toJson()); |
| 417 checkResourceId(od); |
| 418 }); |
| 419 }); |
| 420 |
| 421 |
| 422 unittest.group("obj-schema-SetIamPolicyRequest", () { |
| 423 unittest.test("to-json--from-json", () { |
| 424 var o = buildSetIamPolicyRequest(); |
| 425 var od = new api.SetIamPolicyRequest.fromJson(o.toJson()); |
| 426 checkSetIamPolicyRequest(od); |
| 427 }); |
| 428 }); |
| 429 |
| 430 |
| 431 unittest.group("obj-schema-TestIamPermissionsRequest", () { |
| 432 unittest.test("to-json--from-json", () { |
| 433 var o = buildTestIamPermissionsRequest(); |
| 434 var od = new api.TestIamPermissionsRequest.fromJson(o.toJson()); |
| 435 checkTestIamPermissionsRequest(od); |
| 436 }); |
| 437 }); |
| 438 |
| 439 |
| 440 unittest.group("obj-schema-TestIamPermissionsResponse", () { |
| 441 unittest.test("to-json--from-json", () { |
| 442 var o = buildTestIamPermissionsResponse(); |
| 443 var od = new api.TestIamPermissionsResponse.fromJson(o.toJson()); |
| 444 checkTestIamPermissionsResponse(od); |
| 445 }); |
| 446 }); |
| 447 |
| 448 |
| 449 unittest.group("obj-schema-UndeleteProjectRequest", () { |
| 450 unittest.test("to-json--from-json", () { |
| 451 var o = buildUndeleteProjectRequest(); |
| 452 var od = new api.UndeleteProjectRequest.fromJson(o.toJson()); |
| 453 checkUndeleteProjectRequest(od); |
| 454 }); |
| 455 }); |
| 456 |
| 457 |
| 458 unittest.group("resource-ProjectsResourceApi", () { |
| 459 unittest.test("method--delete", () { |
| 460 |
| 461 var mock = new HttpServerMock(); |
| 462 api.ProjectsResourceApi res = new api.CloudresourcemanagerApi(mock).projec
ts; |
| 463 var arg_projectId = "foo"; |
| 464 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 465 var path = (req.url).path; |
| 466 var pathOffset = 0; |
| 467 var index; |
| 468 var subPart; |
| 469 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 470 pathOffset += 1; |
| 471 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 472 pathOffset += 12; |
| 473 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset)); |
| 474 pathOffset = path.length; |
| 475 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 476 |
| 477 var query = (req.url).query; |
| 478 var queryOffset = 0; |
| 479 var queryMap = {}; |
| 480 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 481 parseBool(n) { |
| 482 if (n == "true") return true; |
| 483 if (n == "false") return false; |
| 484 if (n == null) return null; |
| 485 throw new core.ArgumentError("Invalid boolean: $n"); |
| 486 } |
| 487 if (query.length > 0) { |
| 488 for (var part in query.split("&")) { |
| 489 var keyvalue = part.split("="); |
| 490 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 491 } |
| 492 } |
| 493 |
| 494 |
| 495 var h = { |
| 496 "content-type" : "application/json; charset=utf-8", |
| 497 }; |
| 498 var resp = convert.JSON.encode(buildEmpty()); |
| 499 return new async.Future.value(stringResponse(200, h, resp)); |
| 500 }), true); |
| 501 res.delete(arg_projectId).then(unittest.expectAsync(((api.Empty response)
{ |
| 502 checkEmpty(response); |
| 503 }))); |
| 504 }); |
| 505 |
| 506 unittest.test("method--get", () { |
| 507 |
| 508 var mock = new HttpServerMock(); |
| 509 api.ProjectsResourceApi res = new api.CloudresourcemanagerApi(mock).projec
ts; |
| 510 var arg_projectId = "foo"; |
| 511 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 512 var path = (req.url).path; |
| 513 var pathOffset = 0; |
| 514 var index; |
| 515 var subPart; |
| 516 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 517 pathOffset += 1; |
| 518 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 519 pathOffset += 12; |
| 520 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset)); |
| 521 pathOffset = path.length; |
| 522 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 523 |
| 524 var query = (req.url).query; |
| 525 var queryOffset = 0; |
| 526 var queryMap = {}; |
| 527 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 528 parseBool(n) { |
| 529 if (n == "true") return true; |
| 530 if (n == "false") return false; |
| 531 if (n == null) return null; |
| 532 throw new core.ArgumentError("Invalid boolean: $n"); |
| 533 } |
| 534 if (query.length > 0) { |
| 535 for (var part in query.split("&")) { |
| 536 var keyvalue = part.split("="); |
| 537 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 538 } |
| 539 } |
| 540 |
| 541 |
| 542 var h = { |
| 543 "content-type" : "application/json; charset=utf-8", |
| 544 }; |
| 545 var resp = convert.JSON.encode(buildProject()); |
| 546 return new async.Future.value(stringResponse(200, h, resp)); |
| 547 }), true); |
| 548 res.get(arg_projectId).then(unittest.expectAsync(((api.Project response) { |
| 549 checkProject(response); |
| 550 }))); |
| 551 }); |
| 552 |
| 553 unittest.test("method--getIamPolicy", () { |
| 554 |
| 555 var mock = new HttpServerMock(); |
| 556 api.ProjectsResourceApi res = new api.CloudresourcemanagerApi(mock).projec
ts; |
| 557 var arg_request = buildGetIamPolicyRequest(); |
| 558 var arg_resource = "foo"; |
| 559 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 560 var obj = new api.GetIamPolicyRequest.fromJson(json); |
| 561 checkGetIamPolicyRequest(obj); |
| 562 |
| 563 var path = (req.url).path; |
| 564 var pathOffset = 0; |
| 565 var index; |
| 566 var subPart; |
| 567 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 568 pathOffset += 1; |
| 569 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 570 pathOffset += 12; |
| 571 index = path.indexOf(":getIamPolicy", pathOffset); |
| 572 unittest.expect(index >= 0, unittest.isTrue); |
| 573 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 574 pathOffset = index; |
| 575 unittest.expect(subPart, unittest.equals("$arg_resource")); |
| 576 unittest.expect(path.substring(pathOffset, pathOffset + 13), unittest.eq
uals(":getIamPolicy")); |
| 577 pathOffset += 13; |
| 578 |
| 579 var query = (req.url).query; |
| 580 var queryOffset = 0; |
| 581 var queryMap = {}; |
| 582 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 583 parseBool(n) { |
| 584 if (n == "true") return true; |
| 585 if (n == "false") return false; |
| 586 if (n == null) return null; |
| 587 throw new core.ArgumentError("Invalid boolean: $n"); |
| 588 } |
| 589 if (query.length > 0) { |
| 590 for (var part in query.split("&")) { |
| 591 var keyvalue = part.split("="); |
| 592 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 593 } |
| 594 } |
| 595 |
| 596 |
| 597 var h = { |
| 598 "content-type" : "application/json; charset=utf-8", |
| 599 }; |
| 600 var resp = convert.JSON.encode(buildPolicy()); |
| 601 return new async.Future.value(stringResponse(200, h, resp)); |
| 602 }), true); |
| 603 res.getIamPolicy(arg_request, arg_resource).then(unittest.expectAsync(((ap
i.Policy response) { |
| 604 checkPolicy(response); |
| 605 }))); |
| 606 }); |
| 607 |
| 608 unittest.test("method--list", () { |
| 609 |
| 610 var mock = new HttpServerMock(); |
| 611 api.ProjectsResourceApi res = new api.CloudresourcemanagerApi(mock).projec
ts; |
| 612 var arg_pageToken = "foo"; |
| 613 var arg_pageSize = 42; |
| 614 var arg_filter = "foo"; |
| 615 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 616 var path = (req.url).path; |
| 617 var pathOffset = 0; |
| 618 var index; |
| 619 var subPart; |
| 620 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 621 pathOffset += 1; |
| 622 unittest.expect(path.substring(pathOffset, pathOffset + 11), unittest.eq
uals("v1/projects")); |
| 623 pathOffset += 11; |
| 624 |
| 625 var query = (req.url).query; |
| 626 var queryOffset = 0; |
| 627 var queryMap = {}; |
| 628 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 629 parseBool(n) { |
| 630 if (n == "true") return true; |
| 631 if (n == "false") return false; |
| 632 if (n == null) return null; |
| 633 throw new core.ArgumentError("Invalid boolean: $n"); |
| 634 } |
| 635 if (query.length > 0) { |
| 636 for (var part in query.split("&")) { |
| 637 var keyvalue = part.split("="); |
| 638 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 639 } |
| 640 } |
| 641 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); |
| 642 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ
als(arg_pageSize)); |
| 643 unittest.expect(queryMap["filter"].first, unittest.equals(arg_filter)); |
| 644 |
| 645 |
| 646 var h = { |
| 647 "content-type" : "application/json; charset=utf-8", |
| 648 }; |
| 649 var resp = convert.JSON.encode(buildListProjectsResponse()); |
| 650 return new async.Future.value(stringResponse(200, h, resp)); |
| 651 }), true); |
| 652 res.list(pageToken: arg_pageToken, pageSize: arg_pageSize, filter: arg_fil
ter).then(unittest.expectAsync(((api.ListProjectsResponse response) { |
| 653 checkListProjectsResponse(response); |
| 654 }))); |
| 655 }); |
| 656 |
| 657 unittest.test("method--setIamPolicy", () { |
| 658 |
| 659 var mock = new HttpServerMock(); |
| 660 api.ProjectsResourceApi res = new api.CloudresourcemanagerApi(mock).projec
ts; |
| 661 var arg_request = buildSetIamPolicyRequest(); |
| 662 var arg_resource = "foo"; |
| 663 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 664 var obj = new api.SetIamPolicyRequest.fromJson(json); |
| 665 checkSetIamPolicyRequest(obj); |
| 666 |
| 667 var path = (req.url).path; |
| 668 var pathOffset = 0; |
| 669 var index; |
| 670 var subPart; |
| 671 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 672 pathOffset += 1; |
| 673 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 674 pathOffset += 12; |
| 675 index = path.indexOf(":setIamPolicy", pathOffset); |
| 676 unittest.expect(index >= 0, unittest.isTrue); |
| 677 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 678 pathOffset = index; |
| 679 unittest.expect(subPart, unittest.equals("$arg_resource")); |
| 680 unittest.expect(path.substring(pathOffset, pathOffset + 13), unittest.eq
uals(":setIamPolicy")); |
| 681 pathOffset += 13; |
| 682 |
| 683 var query = (req.url).query; |
| 684 var queryOffset = 0; |
| 685 var queryMap = {}; |
| 686 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 687 parseBool(n) { |
| 688 if (n == "true") return true; |
| 689 if (n == "false") return false; |
| 690 if (n == null) return null; |
| 691 throw new core.ArgumentError("Invalid boolean: $n"); |
| 692 } |
| 693 if (query.length > 0) { |
| 694 for (var part in query.split("&")) { |
| 695 var keyvalue = part.split("="); |
| 696 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 697 } |
| 698 } |
| 699 |
| 700 |
| 701 var h = { |
| 702 "content-type" : "application/json; charset=utf-8", |
| 703 }; |
| 704 var resp = convert.JSON.encode(buildPolicy()); |
| 705 return new async.Future.value(stringResponse(200, h, resp)); |
| 706 }), true); |
| 707 res.setIamPolicy(arg_request, arg_resource).then(unittest.expectAsync(((ap
i.Policy response) { |
| 708 checkPolicy(response); |
| 709 }))); |
| 710 }); |
| 711 |
| 712 unittest.test("method--testIamPermissions", () { |
| 713 |
| 714 var mock = new HttpServerMock(); |
| 715 api.ProjectsResourceApi res = new api.CloudresourcemanagerApi(mock).projec
ts; |
| 716 var arg_request = buildTestIamPermissionsRequest(); |
| 717 var arg_resource = "foo"; |
| 718 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 719 var obj = new api.TestIamPermissionsRequest.fromJson(json); |
| 720 checkTestIamPermissionsRequest(obj); |
| 721 |
| 722 var path = (req.url).path; |
| 723 var pathOffset = 0; |
| 724 var index; |
| 725 var subPart; |
| 726 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 727 pathOffset += 1; |
| 728 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 729 pathOffset += 12; |
| 730 index = path.indexOf(":testIamPermissions", pathOffset); |
| 731 unittest.expect(index >= 0, unittest.isTrue); |
| 732 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 733 pathOffset = index; |
| 734 unittest.expect(subPart, unittest.equals("$arg_resource")); |
| 735 unittest.expect(path.substring(pathOffset, pathOffset + 19), unittest.eq
uals(":testIamPermissions")); |
| 736 pathOffset += 19; |
| 737 |
| 738 var query = (req.url).query; |
| 739 var queryOffset = 0; |
| 740 var queryMap = {}; |
| 741 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 742 parseBool(n) { |
| 743 if (n == "true") return true; |
| 744 if (n == "false") return false; |
| 745 if (n == null) return null; |
| 746 throw new core.ArgumentError("Invalid boolean: $n"); |
| 747 } |
| 748 if (query.length > 0) { |
| 749 for (var part in query.split("&")) { |
| 750 var keyvalue = part.split("="); |
| 751 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 752 } |
| 753 } |
| 754 |
| 755 |
| 756 var h = { |
| 757 "content-type" : "application/json; charset=utf-8", |
| 758 }; |
| 759 var resp = convert.JSON.encode(buildTestIamPermissionsResponse()); |
| 760 return new async.Future.value(stringResponse(200, h, resp)); |
| 761 }), true); |
| 762 res.testIamPermissions(arg_request, arg_resource).then(unittest.expectAsyn
c(((api.TestIamPermissionsResponse response) { |
| 763 checkTestIamPermissionsResponse(response); |
| 764 }))); |
| 765 }); |
| 766 |
| 767 unittest.test("method--undelete", () { |
| 768 |
| 769 var mock = new HttpServerMock(); |
| 770 api.ProjectsResourceApi res = new api.CloudresourcemanagerApi(mock).projec
ts; |
| 771 var arg_request = buildUndeleteProjectRequest(); |
| 772 var arg_projectId = "foo"; |
| 773 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 774 var obj = new api.UndeleteProjectRequest.fromJson(json); |
| 775 checkUndeleteProjectRequest(obj); |
| 776 |
| 777 var path = (req.url).path; |
| 778 var pathOffset = 0; |
| 779 var index; |
| 780 var subPart; |
| 781 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 782 pathOffset += 1; |
| 783 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 784 pathOffset += 12; |
| 785 index = path.indexOf(":undelete", pathOffset); |
| 786 unittest.expect(index >= 0, unittest.isTrue); |
| 787 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 788 pathOffset = index; |
| 789 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 790 unittest.expect(path.substring(pathOffset, pathOffset + 9), unittest.equ
als(":undelete")); |
| 791 pathOffset += 9; |
| 792 |
| 793 var query = (req.url).query; |
| 794 var queryOffset = 0; |
| 795 var queryMap = {}; |
| 796 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 797 parseBool(n) { |
| 798 if (n == "true") return true; |
| 799 if (n == "false") return false; |
| 800 if (n == null) return null; |
| 801 throw new core.ArgumentError("Invalid boolean: $n"); |
| 802 } |
| 803 if (query.length > 0) { |
| 804 for (var part in query.split("&")) { |
| 805 var keyvalue = part.split("="); |
| 806 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 807 } |
| 808 } |
| 809 |
| 810 |
| 811 var h = { |
| 812 "content-type" : "application/json; charset=utf-8", |
| 813 }; |
| 814 var resp = convert.JSON.encode(buildEmpty()); |
| 815 return new async.Future.value(stringResponse(200, h, resp)); |
| 816 }), true); |
| 817 res.undelete(arg_request, arg_projectId).then(unittest.expectAsync(((api.E
mpty response) { |
| 818 checkEmpty(response); |
| 819 }))); |
| 820 }); |
| 821 |
| 822 unittest.test("method--update", () { |
| 823 |
| 824 var mock = new HttpServerMock(); |
| 825 api.ProjectsResourceApi res = new api.CloudresourcemanagerApi(mock).projec
ts; |
| 826 var arg_request = buildProject(); |
| 827 var arg_projectId = "foo"; |
| 828 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 829 var obj = new api.Project.fromJson(json); |
| 830 checkProject(obj); |
| 831 |
| 832 var path = (req.url).path; |
| 833 var pathOffset = 0; |
| 834 var index; |
| 835 var subPart; |
| 836 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 837 pathOffset += 1; |
| 838 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 839 pathOffset += 12; |
| 840 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset)); |
| 841 pathOffset = path.length; |
| 842 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 843 |
| 844 var query = (req.url).query; |
| 845 var queryOffset = 0; |
| 846 var queryMap = {}; |
| 847 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 848 parseBool(n) { |
| 849 if (n == "true") return true; |
| 850 if (n == "false") return false; |
| 851 if (n == null) return null; |
| 852 throw new core.ArgumentError("Invalid boolean: $n"); |
| 853 } |
| 854 if (query.length > 0) { |
| 855 for (var part in query.split("&")) { |
| 856 var keyvalue = part.split("="); |
| 857 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 858 } |
| 859 } |
| 860 |
| 861 |
| 862 var h = { |
| 863 "content-type" : "application/json; charset=utf-8", |
| 864 }; |
| 865 var resp = convert.JSON.encode(buildProject()); |
| 866 return new async.Future.value(stringResponse(200, h, resp)); |
| 867 }), true); |
| 868 res.update(arg_request, arg_projectId).then(unittest.expectAsync(((api.Pro
ject response) { |
| 869 checkProject(response); |
| 870 }))); |
| 871 }); |
| 872 |
| 873 }); |
| 874 |
| 875 |
| 876 } |
| 877 |
| OLD | NEW |