OLD | NEW |
(Empty) | |
| 1 library googleapis.runtimeconfig.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/runtimeconfig/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 buildCounterCancelOperationRequest = 0; |
| 55 buildCancelOperationRequest() { |
| 56 var o = new api.CancelOperationRequest(); |
| 57 buildCounterCancelOperationRequest++; |
| 58 if (buildCounterCancelOperationRequest < 3) { |
| 59 } |
| 60 buildCounterCancelOperationRequest--; |
| 61 return o; |
| 62 } |
| 63 |
| 64 checkCancelOperationRequest(api.CancelOperationRequest o) { |
| 65 buildCounterCancelOperationRequest++; |
| 66 if (buildCounterCancelOperationRequest < 3) { |
| 67 } |
| 68 buildCounterCancelOperationRequest--; |
| 69 } |
| 70 |
| 71 core.int buildCounterEmpty = 0; |
| 72 buildEmpty() { |
| 73 var o = new api.Empty(); |
| 74 buildCounterEmpty++; |
| 75 if (buildCounterEmpty < 3) { |
| 76 } |
| 77 buildCounterEmpty--; |
| 78 return o; |
| 79 } |
| 80 |
| 81 checkEmpty(api.Empty o) { |
| 82 buildCounterEmpty++; |
| 83 if (buildCounterEmpty < 3) { |
| 84 } |
| 85 buildCounterEmpty--; |
| 86 } |
| 87 |
| 88 buildUnnamed2011() { |
| 89 var o = new core.List<api.Operation>(); |
| 90 o.add(buildOperation()); |
| 91 o.add(buildOperation()); |
| 92 return o; |
| 93 } |
| 94 |
| 95 checkUnnamed2011(core.List<api.Operation> o) { |
| 96 unittest.expect(o, unittest.hasLength(2)); |
| 97 checkOperation(o[0]); |
| 98 checkOperation(o[1]); |
| 99 } |
| 100 |
| 101 core.int buildCounterListOperationsResponse = 0; |
| 102 buildListOperationsResponse() { |
| 103 var o = new api.ListOperationsResponse(); |
| 104 buildCounterListOperationsResponse++; |
| 105 if (buildCounterListOperationsResponse < 3) { |
| 106 o.nextPageToken = "foo"; |
| 107 o.operations = buildUnnamed2011(); |
| 108 } |
| 109 buildCounterListOperationsResponse--; |
| 110 return o; |
| 111 } |
| 112 |
| 113 checkListOperationsResponse(api.ListOperationsResponse o) { |
| 114 buildCounterListOperationsResponse++; |
| 115 if (buildCounterListOperationsResponse < 3) { |
| 116 unittest.expect(o.nextPageToken, unittest.equals('foo')); |
| 117 checkUnnamed2011(o.operations); |
| 118 } |
| 119 buildCounterListOperationsResponse--; |
| 120 } |
| 121 |
| 122 buildUnnamed2012() { |
| 123 var o = new core.Map<core.String, core.Object>(); |
| 124 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 125 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 126 return o; |
| 127 } |
| 128 |
| 129 checkUnnamed2012(core.Map<core.String, core.Object> o) { |
| 130 unittest.expect(o, unittest.hasLength(2)); |
| 131 var casted1 = (o["x"]) as core.Map; unittest.expect(casted1, unittest.hasLengt
h(3)); unittest.expect(casted1["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted1["bool"], unittest.equals(true)); unittest.expect(casted1["string"],
unittest.equals('foo')); |
| 132 var casted2 = (o["y"]) as core.Map; unittest.expect(casted2, unittest.hasLengt
h(3)); unittest.expect(casted2["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted2["bool"], unittest.equals(true)); unittest.expect(casted2["string"],
unittest.equals('foo')); |
| 133 } |
| 134 |
| 135 buildUnnamed2013() { |
| 136 var o = new core.Map<core.String, core.Object>(); |
| 137 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 138 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 139 return o; |
| 140 } |
| 141 |
| 142 checkUnnamed2013(core.Map<core.String, core.Object> o) { |
| 143 unittest.expect(o, unittest.hasLength(2)); |
| 144 var casted3 = (o["x"]) as core.Map; unittest.expect(casted3, unittest.hasLengt
h(3)); unittest.expect(casted3["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted3["bool"], unittest.equals(true)); unittest.expect(casted3["string"],
unittest.equals('foo')); |
| 145 var casted4 = (o["y"]) as core.Map; unittest.expect(casted4, unittest.hasLengt
h(3)); unittest.expect(casted4["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted4["bool"], unittest.equals(true)); unittest.expect(casted4["string"],
unittest.equals('foo')); |
| 146 } |
| 147 |
| 148 core.int buildCounterOperation = 0; |
| 149 buildOperation() { |
| 150 var o = new api.Operation(); |
| 151 buildCounterOperation++; |
| 152 if (buildCounterOperation < 3) { |
| 153 o.done = true; |
| 154 o.error = buildStatus(); |
| 155 o.metadata = buildUnnamed2012(); |
| 156 o.name = "foo"; |
| 157 o.response = buildUnnamed2013(); |
| 158 } |
| 159 buildCounterOperation--; |
| 160 return o; |
| 161 } |
| 162 |
| 163 checkOperation(api.Operation o) { |
| 164 buildCounterOperation++; |
| 165 if (buildCounterOperation < 3) { |
| 166 unittest.expect(o.done, unittest.isTrue); |
| 167 checkStatus(o.error); |
| 168 checkUnnamed2012(o.metadata); |
| 169 unittest.expect(o.name, unittest.equals('foo')); |
| 170 checkUnnamed2013(o.response); |
| 171 } |
| 172 buildCounterOperation--; |
| 173 } |
| 174 |
| 175 buildUnnamed2014() { |
| 176 var o = new core.Map<core.String, core.Object>(); |
| 177 o["x"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 178 o["y"] = {'list' : [1, 2, 3], 'bool' : true, 'string' : 'foo'}; |
| 179 return o; |
| 180 } |
| 181 |
| 182 checkUnnamed2014(core.Map<core.String, core.Object> o) { |
| 183 unittest.expect(o, unittest.hasLength(2)); |
| 184 var casted5 = (o["x"]) as core.Map; unittest.expect(casted5, unittest.hasLengt
h(3)); unittest.expect(casted5["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted5["bool"], unittest.equals(true)); unittest.expect(casted5["string"],
unittest.equals('foo')); |
| 185 var casted6 = (o["y"]) as core.Map; unittest.expect(casted6, unittest.hasLengt
h(3)); unittest.expect(casted6["list"], unittest.equals([1, 2, 3])); unittest.ex
pect(casted6["bool"], unittest.equals(true)); unittest.expect(casted6["string"],
unittest.equals('foo')); |
| 186 } |
| 187 |
| 188 buildUnnamed2015() { |
| 189 var o = new core.List<core.Map<core.String, core.Object>>(); |
| 190 o.add(buildUnnamed2014()); |
| 191 o.add(buildUnnamed2014()); |
| 192 return o; |
| 193 } |
| 194 |
| 195 checkUnnamed2015(core.List<core.Map<core.String, core.Object>> o) { |
| 196 unittest.expect(o, unittest.hasLength(2)); |
| 197 checkUnnamed2014(o[0]); |
| 198 checkUnnamed2014(o[1]); |
| 199 } |
| 200 |
| 201 core.int buildCounterStatus = 0; |
| 202 buildStatus() { |
| 203 var o = new api.Status(); |
| 204 buildCounterStatus++; |
| 205 if (buildCounterStatus < 3) { |
| 206 o.code = 42; |
| 207 o.details = buildUnnamed2015(); |
| 208 o.message = "foo"; |
| 209 } |
| 210 buildCounterStatus--; |
| 211 return o; |
| 212 } |
| 213 |
| 214 checkStatus(api.Status o) { |
| 215 buildCounterStatus++; |
| 216 if (buildCounterStatus < 3) { |
| 217 unittest.expect(o.code, unittest.equals(42)); |
| 218 checkUnnamed2015(o.details); |
| 219 unittest.expect(o.message, unittest.equals('foo')); |
| 220 } |
| 221 buildCounterStatus--; |
| 222 } |
| 223 |
| 224 |
| 225 main() { |
| 226 unittest.group("obj-schema-CancelOperationRequest", () { |
| 227 unittest.test("to-json--from-json", () { |
| 228 var o = buildCancelOperationRequest(); |
| 229 var od = new api.CancelOperationRequest.fromJson(o.toJson()); |
| 230 checkCancelOperationRequest(od); |
| 231 }); |
| 232 }); |
| 233 |
| 234 |
| 235 unittest.group("obj-schema-Empty", () { |
| 236 unittest.test("to-json--from-json", () { |
| 237 var o = buildEmpty(); |
| 238 var od = new api.Empty.fromJson(o.toJson()); |
| 239 checkEmpty(od); |
| 240 }); |
| 241 }); |
| 242 |
| 243 |
| 244 unittest.group("obj-schema-ListOperationsResponse", () { |
| 245 unittest.test("to-json--from-json", () { |
| 246 var o = buildListOperationsResponse(); |
| 247 var od = new api.ListOperationsResponse.fromJson(o.toJson()); |
| 248 checkListOperationsResponse(od); |
| 249 }); |
| 250 }); |
| 251 |
| 252 |
| 253 unittest.group("obj-schema-Operation", () { |
| 254 unittest.test("to-json--from-json", () { |
| 255 var o = buildOperation(); |
| 256 var od = new api.Operation.fromJson(o.toJson()); |
| 257 checkOperation(od); |
| 258 }); |
| 259 }); |
| 260 |
| 261 |
| 262 unittest.group("obj-schema-Status", () { |
| 263 unittest.test("to-json--from-json", () { |
| 264 var o = buildStatus(); |
| 265 var od = new api.Status.fromJson(o.toJson()); |
| 266 checkStatus(od); |
| 267 }); |
| 268 }); |
| 269 |
| 270 |
| 271 unittest.group("resource-OperationsResourceApi", () { |
| 272 unittest.test("method--cancel", () { |
| 273 |
| 274 var mock = new HttpServerMock(); |
| 275 api.OperationsResourceApi res = new api.RuntimeconfigApi(mock).operations; |
| 276 var arg_request = buildCancelOperationRequest(); |
| 277 var arg_name = "foo"; |
| 278 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 279 var obj = new api.CancelOperationRequest.fromJson(json); |
| 280 checkCancelOperationRequest(obj); |
| 281 |
| 282 var path = (req.url).path; |
| 283 var pathOffset = 0; |
| 284 var index; |
| 285 var subPart; |
| 286 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 287 pathOffset += 1; |
| 288 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); |
| 289 pathOffset += 3; |
| 290 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; |
| 291 |
| 292 var query = (req.url).query; |
| 293 var queryOffset = 0; |
| 294 var queryMap = {}; |
| 295 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 296 parseBool(n) { |
| 297 if (n == "true") return true; |
| 298 if (n == "false") return false; |
| 299 if (n == null) return null; |
| 300 throw new core.ArgumentError("Invalid boolean: $n"); |
| 301 } |
| 302 if (query.length > 0) { |
| 303 for (var part in query.split("&")) { |
| 304 var keyvalue = part.split("="); |
| 305 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 306 } |
| 307 } |
| 308 |
| 309 |
| 310 var h = { |
| 311 "content-type" : "application/json; charset=utf-8", |
| 312 }; |
| 313 var resp = convert.JSON.encode(buildEmpty()); |
| 314 return new async.Future.value(stringResponse(200, h, resp)); |
| 315 }), true); |
| 316 res.cancel(arg_request, arg_name).then(unittest.expectAsync(((api.Empty re
sponse) { |
| 317 checkEmpty(response); |
| 318 }))); |
| 319 }); |
| 320 |
| 321 unittest.test("method--delete", () { |
| 322 |
| 323 var mock = new HttpServerMock(); |
| 324 api.OperationsResourceApi res = new api.RuntimeconfigApi(mock).operations; |
| 325 var arg_name = "foo"; |
| 326 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 327 var path = (req.url).path; |
| 328 var pathOffset = 0; |
| 329 var index; |
| 330 var subPart; |
| 331 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 332 pathOffset += 1; |
| 333 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); |
| 334 pathOffset += 3; |
| 335 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; |
| 336 |
| 337 var query = (req.url).query; |
| 338 var queryOffset = 0; |
| 339 var queryMap = {}; |
| 340 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 341 parseBool(n) { |
| 342 if (n == "true") return true; |
| 343 if (n == "false") return false; |
| 344 if (n == null) return null; |
| 345 throw new core.ArgumentError("Invalid boolean: $n"); |
| 346 } |
| 347 if (query.length > 0) { |
| 348 for (var part in query.split("&")) { |
| 349 var keyvalue = part.split("="); |
| 350 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 351 } |
| 352 } |
| 353 |
| 354 |
| 355 var h = { |
| 356 "content-type" : "application/json; charset=utf-8", |
| 357 }; |
| 358 var resp = convert.JSON.encode(buildEmpty()); |
| 359 return new async.Future.value(stringResponse(200, h, resp)); |
| 360 }), true); |
| 361 res.delete(arg_name).then(unittest.expectAsync(((api.Empty response) { |
| 362 checkEmpty(response); |
| 363 }))); |
| 364 }); |
| 365 |
| 366 unittest.test("method--list", () { |
| 367 |
| 368 var mock = new HttpServerMock(); |
| 369 api.OperationsResourceApi res = new api.RuntimeconfigApi(mock).operations; |
| 370 var arg_name = "foo"; |
| 371 var arg_pageSize = 42; |
| 372 var arg_filter = "foo"; |
| 373 var arg_pageToken = "foo"; |
| 374 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 375 var path = (req.url).path; |
| 376 var pathOffset = 0; |
| 377 var index; |
| 378 var subPart; |
| 379 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 380 pathOffset += 1; |
| 381 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); |
| 382 pathOffset += 3; |
| 383 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; |
| 384 |
| 385 var query = (req.url).query; |
| 386 var queryOffset = 0; |
| 387 var queryMap = {}; |
| 388 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 389 parseBool(n) { |
| 390 if (n == "true") return true; |
| 391 if (n == "false") return false; |
| 392 if (n == null) return null; |
| 393 throw new core.ArgumentError("Invalid boolean: $n"); |
| 394 } |
| 395 if (query.length > 0) { |
| 396 for (var part in query.split("&")) { |
| 397 var keyvalue = part.split("="); |
| 398 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 399 } |
| 400 } |
| 401 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ
als(arg_pageSize)); |
| 402 unittest.expect(queryMap["filter"].first, unittest.equals(arg_filter)); |
| 403 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); |
| 404 |
| 405 |
| 406 var h = { |
| 407 "content-type" : "application/json; charset=utf-8", |
| 408 }; |
| 409 var resp = convert.JSON.encode(buildListOperationsResponse()); |
| 410 return new async.Future.value(stringResponse(200, h, resp)); |
| 411 }), true); |
| 412 res.list(arg_name, pageSize: arg_pageSize, filter: arg_filter, pageToken:
arg_pageToken).then(unittest.expectAsync(((api.ListOperationsResponse response)
{ |
| 413 checkListOperationsResponse(response); |
| 414 }))); |
| 415 }); |
| 416 |
| 417 }); |
| 418 |
| 419 |
| 420 } |
| 421 |
OLD | NEW |