OLD | NEW |
(Empty) | |
| 1 library googleapis.cloudsearch.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/cloudsearch/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 buildUnnamed436() { |
| 55 var o = new core.Map<core.String, api.FieldValueList>(); |
| 56 o["x"] = buildFieldValueList(); |
| 57 o["y"] = buildFieldValueList(); |
| 58 return o; |
| 59 } |
| 60 |
| 61 checkUnnamed436(core.Map<core.String, api.FieldValueList> o) { |
| 62 unittest.expect(o, unittest.hasLength(2)); |
| 63 checkFieldValueList(o["x"]); |
| 64 checkFieldValueList(o["y"]); |
| 65 } |
| 66 |
| 67 core.int buildCounterDocument = 0; |
| 68 buildDocument() { |
| 69 var o = new api.Document(); |
| 70 buildCounterDocument++; |
| 71 if (buildCounterDocument < 3) { |
| 72 o.docId = "foo"; |
| 73 o.fields = buildUnnamed436(); |
| 74 o.rank = 42; |
| 75 } |
| 76 buildCounterDocument--; |
| 77 return o; |
| 78 } |
| 79 |
| 80 checkDocument(api.Document o) { |
| 81 buildCounterDocument++; |
| 82 if (buildCounterDocument < 3) { |
| 83 unittest.expect(o.docId, unittest.equals('foo')); |
| 84 checkUnnamed436(o.fields); |
| 85 unittest.expect(o.rank, unittest.equals(42)); |
| 86 } |
| 87 buildCounterDocument--; |
| 88 } |
| 89 |
| 90 core.int buildCounterEmpty = 0; |
| 91 buildEmpty() { |
| 92 var o = new api.Empty(); |
| 93 buildCounterEmpty++; |
| 94 if (buildCounterEmpty < 3) { |
| 95 } |
| 96 buildCounterEmpty--; |
| 97 return o; |
| 98 } |
| 99 |
| 100 checkEmpty(api.Empty o) { |
| 101 buildCounterEmpty++; |
| 102 if (buildCounterEmpty < 3) { |
| 103 } |
| 104 buildCounterEmpty--; |
| 105 } |
| 106 |
| 107 buildUnnamed437() { |
| 108 var o = new core.List<core.String>(); |
| 109 o.add("foo"); |
| 110 o.add("foo"); |
| 111 return o; |
| 112 } |
| 113 |
| 114 checkUnnamed437(core.List<core.String> o) { |
| 115 unittest.expect(o, unittest.hasLength(2)); |
| 116 unittest.expect(o[0], unittest.equals('foo')); |
| 117 unittest.expect(o[1], unittest.equals('foo')); |
| 118 } |
| 119 |
| 120 buildUnnamed438() { |
| 121 var o = new core.List<core.String>(); |
| 122 o.add("foo"); |
| 123 o.add("foo"); |
| 124 return o; |
| 125 } |
| 126 |
| 127 checkUnnamed438(core.List<core.String> o) { |
| 128 unittest.expect(o, unittest.hasLength(2)); |
| 129 unittest.expect(o[0], unittest.equals('foo')); |
| 130 unittest.expect(o[1], unittest.equals('foo')); |
| 131 } |
| 132 |
| 133 buildUnnamed439() { |
| 134 var o = new core.List<core.String>(); |
| 135 o.add("foo"); |
| 136 o.add("foo"); |
| 137 return o; |
| 138 } |
| 139 |
| 140 checkUnnamed439(core.List<core.String> o) { |
| 141 unittest.expect(o, unittest.hasLength(2)); |
| 142 unittest.expect(o[0], unittest.equals('foo')); |
| 143 unittest.expect(o[1], unittest.equals('foo')); |
| 144 } |
| 145 |
| 146 buildUnnamed440() { |
| 147 var o = new core.List<core.String>(); |
| 148 o.add("foo"); |
| 149 o.add("foo"); |
| 150 return o; |
| 151 } |
| 152 |
| 153 checkUnnamed440(core.List<core.String> o) { |
| 154 unittest.expect(o, unittest.hasLength(2)); |
| 155 unittest.expect(o[0], unittest.equals('foo')); |
| 156 unittest.expect(o[1], unittest.equals('foo')); |
| 157 } |
| 158 |
| 159 buildUnnamed441() { |
| 160 var o = new core.List<core.String>(); |
| 161 o.add("foo"); |
| 162 o.add("foo"); |
| 163 return o; |
| 164 } |
| 165 |
| 166 checkUnnamed441(core.List<core.String> o) { |
| 167 unittest.expect(o, unittest.hasLength(2)); |
| 168 unittest.expect(o[0], unittest.equals('foo')); |
| 169 unittest.expect(o[1], unittest.equals('foo')); |
| 170 } |
| 171 |
| 172 buildUnnamed442() { |
| 173 var o = new core.List<core.String>(); |
| 174 o.add("foo"); |
| 175 o.add("foo"); |
| 176 return o; |
| 177 } |
| 178 |
| 179 checkUnnamed442(core.List<core.String> o) { |
| 180 unittest.expect(o, unittest.hasLength(2)); |
| 181 unittest.expect(o[0], unittest.equals('foo')); |
| 182 unittest.expect(o[1], unittest.equals('foo')); |
| 183 } |
| 184 |
| 185 core.int buildCounterFieldNames = 0; |
| 186 buildFieldNames() { |
| 187 var o = new api.FieldNames(); |
| 188 buildCounterFieldNames++; |
| 189 if (buildCounterFieldNames < 3) { |
| 190 o.atomFields = buildUnnamed437(); |
| 191 o.dateFields = buildUnnamed438(); |
| 192 o.geoFields = buildUnnamed439(); |
| 193 o.htmlFields = buildUnnamed440(); |
| 194 o.numberFields = buildUnnamed441(); |
| 195 o.textFields = buildUnnamed442(); |
| 196 } |
| 197 buildCounterFieldNames--; |
| 198 return o; |
| 199 } |
| 200 |
| 201 checkFieldNames(api.FieldNames o) { |
| 202 buildCounterFieldNames++; |
| 203 if (buildCounterFieldNames < 3) { |
| 204 checkUnnamed437(o.atomFields); |
| 205 checkUnnamed438(o.dateFields); |
| 206 checkUnnamed439(o.geoFields); |
| 207 checkUnnamed440(o.htmlFields); |
| 208 checkUnnamed441(o.numberFields); |
| 209 checkUnnamed442(o.textFields); |
| 210 } |
| 211 buildCounterFieldNames--; |
| 212 } |
| 213 |
| 214 core.int buildCounterFieldValue = 0; |
| 215 buildFieldValue() { |
| 216 var o = new api.FieldValue(); |
| 217 buildCounterFieldValue++; |
| 218 if (buildCounterFieldValue < 3) { |
| 219 o.geoValue = "foo"; |
| 220 o.lang = "foo"; |
| 221 o.numberValue = 42.0; |
| 222 o.stringFormat = "foo"; |
| 223 o.stringValue = "foo"; |
| 224 o.timestampValue = "foo"; |
| 225 } |
| 226 buildCounterFieldValue--; |
| 227 return o; |
| 228 } |
| 229 |
| 230 checkFieldValue(api.FieldValue o) { |
| 231 buildCounterFieldValue++; |
| 232 if (buildCounterFieldValue < 3) { |
| 233 unittest.expect(o.geoValue, unittest.equals('foo')); |
| 234 unittest.expect(o.lang, unittest.equals('foo')); |
| 235 unittest.expect(o.numberValue, unittest.equals(42.0)); |
| 236 unittest.expect(o.stringFormat, unittest.equals('foo')); |
| 237 unittest.expect(o.stringValue, unittest.equals('foo')); |
| 238 unittest.expect(o.timestampValue, unittest.equals('foo')); |
| 239 } |
| 240 buildCounterFieldValue--; |
| 241 } |
| 242 |
| 243 buildUnnamed443() { |
| 244 var o = new core.List<api.FieldValue>(); |
| 245 o.add(buildFieldValue()); |
| 246 o.add(buildFieldValue()); |
| 247 return o; |
| 248 } |
| 249 |
| 250 checkUnnamed443(core.List<api.FieldValue> o) { |
| 251 unittest.expect(o, unittest.hasLength(2)); |
| 252 checkFieldValue(o[0]); |
| 253 checkFieldValue(o[1]); |
| 254 } |
| 255 |
| 256 core.int buildCounterFieldValueList = 0; |
| 257 buildFieldValueList() { |
| 258 var o = new api.FieldValueList(); |
| 259 buildCounterFieldValueList++; |
| 260 if (buildCounterFieldValueList < 3) { |
| 261 o.values = buildUnnamed443(); |
| 262 } |
| 263 buildCounterFieldValueList--; |
| 264 return o; |
| 265 } |
| 266 |
| 267 checkFieldValueList(api.FieldValueList o) { |
| 268 buildCounterFieldValueList++; |
| 269 if (buildCounterFieldValueList < 3) { |
| 270 checkUnnamed443(o.values); |
| 271 } |
| 272 buildCounterFieldValueList--; |
| 273 } |
| 274 |
| 275 core.int buildCounterIndexInfo = 0; |
| 276 buildIndexInfo() { |
| 277 var o = new api.IndexInfo(); |
| 278 buildCounterIndexInfo++; |
| 279 if (buildCounterIndexInfo < 3) { |
| 280 o.indexId = "foo"; |
| 281 o.indexedField = buildFieldNames(); |
| 282 o.projectId = "foo"; |
| 283 } |
| 284 buildCounterIndexInfo--; |
| 285 return o; |
| 286 } |
| 287 |
| 288 checkIndexInfo(api.IndexInfo o) { |
| 289 buildCounterIndexInfo++; |
| 290 if (buildCounterIndexInfo < 3) { |
| 291 unittest.expect(o.indexId, unittest.equals('foo')); |
| 292 checkFieldNames(o.indexedField); |
| 293 unittest.expect(o.projectId, unittest.equals('foo')); |
| 294 } |
| 295 buildCounterIndexInfo--; |
| 296 } |
| 297 |
| 298 buildUnnamed444() { |
| 299 var o = new core.List<api.Document>(); |
| 300 o.add(buildDocument()); |
| 301 o.add(buildDocument()); |
| 302 return o; |
| 303 } |
| 304 |
| 305 checkUnnamed444(core.List<api.Document> o) { |
| 306 unittest.expect(o, unittest.hasLength(2)); |
| 307 checkDocument(o[0]); |
| 308 checkDocument(o[1]); |
| 309 } |
| 310 |
| 311 core.int buildCounterListDocumentsResponse = 0; |
| 312 buildListDocumentsResponse() { |
| 313 var o = new api.ListDocumentsResponse(); |
| 314 buildCounterListDocumentsResponse++; |
| 315 if (buildCounterListDocumentsResponse < 3) { |
| 316 o.documents = buildUnnamed444(); |
| 317 o.nextPageToken = "foo"; |
| 318 } |
| 319 buildCounterListDocumentsResponse--; |
| 320 return o; |
| 321 } |
| 322 |
| 323 checkListDocumentsResponse(api.ListDocumentsResponse o) { |
| 324 buildCounterListDocumentsResponse++; |
| 325 if (buildCounterListDocumentsResponse < 3) { |
| 326 checkUnnamed444(o.documents); |
| 327 unittest.expect(o.nextPageToken, unittest.equals('foo')); |
| 328 } |
| 329 buildCounterListDocumentsResponse--; |
| 330 } |
| 331 |
| 332 buildUnnamed445() { |
| 333 var o = new core.List<api.IndexInfo>(); |
| 334 o.add(buildIndexInfo()); |
| 335 o.add(buildIndexInfo()); |
| 336 return o; |
| 337 } |
| 338 |
| 339 checkUnnamed445(core.List<api.IndexInfo> o) { |
| 340 unittest.expect(o, unittest.hasLength(2)); |
| 341 checkIndexInfo(o[0]); |
| 342 checkIndexInfo(o[1]); |
| 343 } |
| 344 |
| 345 core.int buildCounterListIndexesResponse = 0; |
| 346 buildListIndexesResponse() { |
| 347 var o = new api.ListIndexesResponse(); |
| 348 buildCounterListIndexesResponse++; |
| 349 if (buildCounterListIndexesResponse < 3) { |
| 350 o.indexes = buildUnnamed445(); |
| 351 o.nextPageToken = "foo"; |
| 352 } |
| 353 buildCounterListIndexesResponse--; |
| 354 return o; |
| 355 } |
| 356 |
| 357 checkListIndexesResponse(api.ListIndexesResponse o) { |
| 358 buildCounterListIndexesResponse++; |
| 359 if (buildCounterListIndexesResponse < 3) { |
| 360 checkUnnamed445(o.indexes); |
| 361 unittest.expect(o.nextPageToken, unittest.equals('foo')); |
| 362 } |
| 363 buildCounterListIndexesResponse--; |
| 364 } |
| 365 |
| 366 buildUnnamed446() { |
| 367 var o = new core.List<api.SearchResult>(); |
| 368 o.add(buildSearchResult()); |
| 369 o.add(buildSearchResult()); |
| 370 return o; |
| 371 } |
| 372 |
| 373 checkUnnamed446(core.List<api.SearchResult> o) { |
| 374 unittest.expect(o, unittest.hasLength(2)); |
| 375 checkSearchResult(o[0]); |
| 376 checkSearchResult(o[1]); |
| 377 } |
| 378 |
| 379 core.int buildCounterSearchResponse = 0; |
| 380 buildSearchResponse() { |
| 381 var o = new api.SearchResponse(); |
| 382 buildCounterSearchResponse++; |
| 383 if (buildCounterSearchResponse < 3) { |
| 384 o.matchedCount = "foo"; |
| 385 o.results = buildUnnamed446(); |
| 386 } |
| 387 buildCounterSearchResponse--; |
| 388 return o; |
| 389 } |
| 390 |
| 391 checkSearchResponse(api.SearchResponse o) { |
| 392 buildCounterSearchResponse++; |
| 393 if (buildCounterSearchResponse < 3) { |
| 394 unittest.expect(o.matchedCount, unittest.equals('foo')); |
| 395 checkUnnamed446(o.results); |
| 396 } |
| 397 buildCounterSearchResponse--; |
| 398 } |
| 399 |
| 400 buildUnnamed447() { |
| 401 var o = new core.Map<core.String, api.FieldValueList>(); |
| 402 o["x"] = buildFieldValueList(); |
| 403 o["y"] = buildFieldValueList(); |
| 404 return o; |
| 405 } |
| 406 |
| 407 checkUnnamed447(core.Map<core.String, api.FieldValueList> o) { |
| 408 unittest.expect(o, unittest.hasLength(2)); |
| 409 checkFieldValueList(o["x"]); |
| 410 checkFieldValueList(o["y"]); |
| 411 } |
| 412 |
| 413 core.int buildCounterSearchResult = 0; |
| 414 buildSearchResult() { |
| 415 var o = new api.SearchResult(); |
| 416 buildCounterSearchResult++; |
| 417 if (buildCounterSearchResult < 3) { |
| 418 o.docId = "foo"; |
| 419 o.fields = buildUnnamed447(); |
| 420 o.nextPageToken = "foo"; |
| 421 } |
| 422 buildCounterSearchResult--; |
| 423 return o; |
| 424 } |
| 425 |
| 426 checkSearchResult(api.SearchResult o) { |
| 427 buildCounterSearchResult++; |
| 428 if (buildCounterSearchResult < 3) { |
| 429 unittest.expect(o.docId, unittest.equals('foo')); |
| 430 checkUnnamed447(o.fields); |
| 431 unittest.expect(o.nextPageToken, unittest.equals('foo')); |
| 432 } |
| 433 buildCounterSearchResult--; |
| 434 } |
| 435 |
| 436 buildUnnamed448() { |
| 437 var o = new core.List<core.String>(); |
| 438 o.add("foo"); |
| 439 o.add("foo"); |
| 440 return o; |
| 441 } |
| 442 |
| 443 checkUnnamed448(core.List<core.String> o) { |
| 444 unittest.expect(o, unittest.hasLength(2)); |
| 445 unittest.expect(o[0], unittest.equals('foo')); |
| 446 unittest.expect(o[1], unittest.equals('foo')); |
| 447 } |
| 448 |
| 449 buildUnnamed449() { |
| 450 var o = new core.List<core.String>(); |
| 451 o.add("foo"); |
| 452 o.add("foo"); |
| 453 return o; |
| 454 } |
| 455 |
| 456 checkUnnamed449(core.List<core.String> o) { |
| 457 unittest.expect(o, unittest.hasLength(2)); |
| 458 unittest.expect(o[0], unittest.equals('foo')); |
| 459 unittest.expect(o[1], unittest.equals('foo')); |
| 460 } |
| 461 |
| 462 |
| 463 main() { |
| 464 unittest.group("obj-schema-Document", () { |
| 465 unittest.test("to-json--from-json", () { |
| 466 var o = buildDocument(); |
| 467 var od = new api.Document.fromJson(o.toJson()); |
| 468 checkDocument(od); |
| 469 }); |
| 470 }); |
| 471 |
| 472 |
| 473 unittest.group("obj-schema-Empty", () { |
| 474 unittest.test("to-json--from-json", () { |
| 475 var o = buildEmpty(); |
| 476 var od = new api.Empty.fromJson(o.toJson()); |
| 477 checkEmpty(od); |
| 478 }); |
| 479 }); |
| 480 |
| 481 |
| 482 unittest.group("obj-schema-FieldNames", () { |
| 483 unittest.test("to-json--from-json", () { |
| 484 var o = buildFieldNames(); |
| 485 var od = new api.FieldNames.fromJson(o.toJson()); |
| 486 checkFieldNames(od); |
| 487 }); |
| 488 }); |
| 489 |
| 490 |
| 491 unittest.group("obj-schema-FieldValue", () { |
| 492 unittest.test("to-json--from-json", () { |
| 493 var o = buildFieldValue(); |
| 494 var od = new api.FieldValue.fromJson(o.toJson()); |
| 495 checkFieldValue(od); |
| 496 }); |
| 497 }); |
| 498 |
| 499 |
| 500 unittest.group("obj-schema-FieldValueList", () { |
| 501 unittest.test("to-json--from-json", () { |
| 502 var o = buildFieldValueList(); |
| 503 var od = new api.FieldValueList.fromJson(o.toJson()); |
| 504 checkFieldValueList(od); |
| 505 }); |
| 506 }); |
| 507 |
| 508 |
| 509 unittest.group("obj-schema-IndexInfo", () { |
| 510 unittest.test("to-json--from-json", () { |
| 511 var o = buildIndexInfo(); |
| 512 var od = new api.IndexInfo.fromJson(o.toJson()); |
| 513 checkIndexInfo(od); |
| 514 }); |
| 515 }); |
| 516 |
| 517 |
| 518 unittest.group("obj-schema-ListDocumentsResponse", () { |
| 519 unittest.test("to-json--from-json", () { |
| 520 var o = buildListDocumentsResponse(); |
| 521 var od = new api.ListDocumentsResponse.fromJson(o.toJson()); |
| 522 checkListDocumentsResponse(od); |
| 523 }); |
| 524 }); |
| 525 |
| 526 |
| 527 unittest.group("obj-schema-ListIndexesResponse", () { |
| 528 unittest.test("to-json--from-json", () { |
| 529 var o = buildListIndexesResponse(); |
| 530 var od = new api.ListIndexesResponse.fromJson(o.toJson()); |
| 531 checkListIndexesResponse(od); |
| 532 }); |
| 533 }); |
| 534 |
| 535 |
| 536 unittest.group("obj-schema-SearchResponse", () { |
| 537 unittest.test("to-json--from-json", () { |
| 538 var o = buildSearchResponse(); |
| 539 var od = new api.SearchResponse.fromJson(o.toJson()); |
| 540 checkSearchResponse(od); |
| 541 }); |
| 542 }); |
| 543 |
| 544 |
| 545 unittest.group("obj-schema-SearchResult", () { |
| 546 unittest.test("to-json--from-json", () { |
| 547 var o = buildSearchResult(); |
| 548 var od = new api.SearchResult.fromJson(o.toJson()); |
| 549 checkSearchResult(od); |
| 550 }); |
| 551 }); |
| 552 |
| 553 |
| 554 unittest.group("resource-ProjectsIndexesResourceApi", () { |
| 555 unittest.test("method--list", () { |
| 556 |
| 557 var mock = new HttpServerMock(); |
| 558 api.ProjectsIndexesResourceApi res = new api.CloudsearchApi(mock).projects
.indexes; |
| 559 var arg_projectId = "foo"; |
| 560 var arg_indexNamePrefix = "foo"; |
| 561 var arg_pageSize = 42; |
| 562 var arg_pageToken = "foo"; |
| 563 var arg_view = "foo"; |
| 564 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 565 var path = (req.url).path; |
| 566 var pathOffset = 0; |
| 567 var index; |
| 568 var subPart; |
| 569 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 570 pathOffset += 1; |
| 571 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 572 pathOffset += 12; |
| 573 index = path.indexOf("/indexes", pathOffset); |
| 574 unittest.expect(index >= 0, unittest.isTrue); |
| 575 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 576 pathOffset = index; |
| 577 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 578 unittest.expect(path.substring(pathOffset, pathOffset + 8), unittest.equ
als("/indexes")); |
| 579 pathOffset += 8; |
| 580 |
| 581 var query = (req.url).query; |
| 582 var queryOffset = 0; |
| 583 var queryMap = {}; |
| 584 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 585 parseBool(n) { |
| 586 if (n == "true") return true; |
| 587 if (n == "false") return false; |
| 588 if (n == null) return null; |
| 589 throw new core.ArgumentError("Invalid boolean: $n"); |
| 590 } |
| 591 if (query.length > 0) { |
| 592 for (var part in query.split("&")) { |
| 593 var keyvalue = part.split("="); |
| 594 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 595 } |
| 596 } |
| 597 unittest.expect(queryMap["indexNamePrefix"].first, unittest.equals(arg_i
ndexNamePrefix)); |
| 598 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ
als(arg_pageSize)); |
| 599 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); |
| 600 unittest.expect(queryMap["view"].first, unittest.equals(arg_view)); |
| 601 |
| 602 |
| 603 var h = { |
| 604 "content-type" : "application/json; charset=utf-8", |
| 605 }; |
| 606 var resp = convert.JSON.encode(buildListIndexesResponse()); |
| 607 return new async.Future.value(stringResponse(200, h, resp)); |
| 608 }), true); |
| 609 res.list(arg_projectId, indexNamePrefix: arg_indexNamePrefix, pageSize: ar
g_pageSize, pageToken: arg_pageToken, view: arg_view).then(unittest.expectAsync(
((api.ListIndexesResponse response) { |
| 610 checkListIndexesResponse(response); |
| 611 }))); |
| 612 }); |
| 613 |
| 614 unittest.test("method--search", () { |
| 615 |
| 616 var mock = new HttpServerMock(); |
| 617 api.ProjectsIndexesResourceApi res = new api.CloudsearchApi(mock).projects
.indexes; |
| 618 var arg_projectId = "foo"; |
| 619 var arg_indexId = "foo"; |
| 620 var arg_query = "foo"; |
| 621 var arg_fieldExpressions = buildUnnamed448(); |
| 622 var arg_pageSize = 42; |
| 623 var arg_pageToken = "foo"; |
| 624 var arg_offset = 42; |
| 625 var arg_matchedCountAccuracy = 42; |
| 626 var arg_orderBy = "foo"; |
| 627 var arg_scorer = "foo"; |
| 628 var arg_scorerSize = 42; |
| 629 var arg_returnFields = buildUnnamed449(); |
| 630 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 631 var path = (req.url).path; |
| 632 var pathOffset = 0; |
| 633 var index; |
| 634 var subPart; |
| 635 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 636 pathOffset += 1; |
| 637 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 638 pathOffset += 12; |
| 639 index = path.indexOf("/indexes/", pathOffset); |
| 640 unittest.expect(index >= 0, unittest.isTrue); |
| 641 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 642 pathOffset = index; |
| 643 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 644 unittest.expect(path.substring(pathOffset, pathOffset + 9), unittest.equ
als("/indexes/")); |
| 645 pathOffset += 9; |
| 646 index = path.indexOf("/search", pathOffset); |
| 647 unittest.expect(index >= 0, unittest.isTrue); |
| 648 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 649 pathOffset = index; |
| 650 unittest.expect(subPart, unittest.equals("$arg_indexId")); |
| 651 unittest.expect(path.substring(pathOffset, pathOffset + 7), unittest.equ
als("/search")); |
| 652 pathOffset += 7; |
| 653 |
| 654 var query = (req.url).query; |
| 655 var queryOffset = 0; |
| 656 var queryMap = {}; |
| 657 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 658 parseBool(n) { |
| 659 if (n == "true") return true; |
| 660 if (n == "false") return false; |
| 661 if (n == null) return null; |
| 662 throw new core.ArgumentError("Invalid boolean: $n"); |
| 663 } |
| 664 if (query.length > 0) { |
| 665 for (var part in query.split("&")) { |
| 666 var keyvalue = part.split("="); |
| 667 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 668 } |
| 669 } |
| 670 unittest.expect(queryMap["query"].first, unittest.equals(arg_query)); |
| 671 unittest.expect(queryMap["fieldExpressions"], unittest.equals(arg_fieldE
xpressions)); |
| 672 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ
als(arg_pageSize)); |
| 673 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); |
| 674 unittest.expect(core.int.parse(queryMap["offset"].first), unittest.equal
s(arg_offset)); |
| 675 unittest.expect(core.int.parse(queryMap["matchedCountAccuracy"].first),
unittest.equals(arg_matchedCountAccuracy)); |
| 676 unittest.expect(queryMap["orderBy"].first, unittest.equals(arg_orderBy))
; |
| 677 unittest.expect(queryMap["scorer"].first, unittest.equals(arg_scorer)); |
| 678 unittest.expect(core.int.parse(queryMap["scorerSize"].first), unittest.e
quals(arg_scorerSize)); |
| 679 unittest.expect(queryMap["returnFields"], unittest.equals(arg_returnFiel
ds)); |
| 680 |
| 681 |
| 682 var h = { |
| 683 "content-type" : "application/json; charset=utf-8", |
| 684 }; |
| 685 var resp = convert.JSON.encode(buildSearchResponse()); |
| 686 return new async.Future.value(stringResponse(200, h, resp)); |
| 687 }), true); |
| 688 res.search(arg_projectId, arg_indexId, query: arg_query, fieldExpressions:
arg_fieldExpressions, pageSize: arg_pageSize, pageToken: arg_pageToken, offset:
arg_offset, matchedCountAccuracy: arg_matchedCountAccuracy, orderBy: arg_orderB
y, scorer: arg_scorer, scorerSize: arg_scorerSize, returnFields: arg_returnField
s).then(unittest.expectAsync(((api.SearchResponse response) { |
| 689 checkSearchResponse(response); |
| 690 }))); |
| 691 }); |
| 692 |
| 693 }); |
| 694 |
| 695 |
| 696 unittest.group("resource-ProjectsIndexesDocumentsResourceApi", () { |
| 697 unittest.test("method--create", () { |
| 698 |
| 699 var mock = new HttpServerMock(); |
| 700 api.ProjectsIndexesDocumentsResourceApi res = new api.CloudsearchApi(mock)
.projects.indexes.documents; |
| 701 var arg_request = buildDocument(); |
| 702 var arg_projectId = "foo"; |
| 703 var arg_indexId = "foo"; |
| 704 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 705 var obj = new api.Document.fromJson(json); |
| 706 checkDocument(obj); |
| 707 |
| 708 var path = (req.url).path; |
| 709 var pathOffset = 0; |
| 710 var index; |
| 711 var subPart; |
| 712 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 713 pathOffset += 1; |
| 714 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 715 pathOffset += 12; |
| 716 index = path.indexOf("/indexes/", pathOffset); |
| 717 unittest.expect(index >= 0, unittest.isTrue); |
| 718 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 719 pathOffset = index; |
| 720 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 721 unittest.expect(path.substring(pathOffset, pathOffset + 9), unittest.equ
als("/indexes/")); |
| 722 pathOffset += 9; |
| 723 index = path.indexOf("/documents", pathOffset); |
| 724 unittest.expect(index >= 0, unittest.isTrue); |
| 725 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 726 pathOffset = index; |
| 727 unittest.expect(subPart, unittest.equals("$arg_indexId")); |
| 728 unittest.expect(path.substring(pathOffset, pathOffset + 10), unittest.eq
uals("/documents")); |
| 729 pathOffset += 10; |
| 730 |
| 731 var query = (req.url).query; |
| 732 var queryOffset = 0; |
| 733 var queryMap = {}; |
| 734 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 735 parseBool(n) { |
| 736 if (n == "true") return true; |
| 737 if (n == "false") return false; |
| 738 if (n == null) return null; |
| 739 throw new core.ArgumentError("Invalid boolean: $n"); |
| 740 } |
| 741 if (query.length > 0) { |
| 742 for (var part in query.split("&")) { |
| 743 var keyvalue = part.split("="); |
| 744 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 745 } |
| 746 } |
| 747 |
| 748 |
| 749 var h = { |
| 750 "content-type" : "application/json; charset=utf-8", |
| 751 }; |
| 752 var resp = convert.JSON.encode(buildDocument()); |
| 753 return new async.Future.value(stringResponse(200, h, resp)); |
| 754 }), true); |
| 755 res.create(arg_request, arg_projectId, arg_indexId).then(unittest.expectAs
ync(((api.Document response) { |
| 756 checkDocument(response); |
| 757 }))); |
| 758 }); |
| 759 |
| 760 unittest.test("method--delete", () { |
| 761 |
| 762 var mock = new HttpServerMock(); |
| 763 api.ProjectsIndexesDocumentsResourceApi res = new api.CloudsearchApi(mock)
.projects.indexes.documents; |
| 764 var arg_projectId = "foo"; |
| 765 var arg_indexId = "foo"; |
| 766 var arg_docId = "foo"; |
| 767 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 768 var path = (req.url).path; |
| 769 var pathOffset = 0; |
| 770 var index; |
| 771 var subPart; |
| 772 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 773 pathOffset += 1; |
| 774 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 775 pathOffset += 12; |
| 776 index = path.indexOf("/indexes/", pathOffset); |
| 777 unittest.expect(index >= 0, unittest.isTrue); |
| 778 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 779 pathOffset = index; |
| 780 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 781 unittest.expect(path.substring(pathOffset, pathOffset + 9), unittest.equ
als("/indexes/")); |
| 782 pathOffset += 9; |
| 783 index = path.indexOf("/documents/", pathOffset); |
| 784 unittest.expect(index >= 0, unittest.isTrue); |
| 785 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 786 pathOffset = index; |
| 787 unittest.expect(subPart, unittest.equals("$arg_indexId")); |
| 788 unittest.expect(path.substring(pathOffset, pathOffset + 11), unittest.eq
uals("/documents/")); |
| 789 pathOffset += 11; |
| 790 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset)); |
| 791 pathOffset = path.length; |
| 792 unittest.expect(subPart, unittest.equals("$arg_docId")); |
| 793 |
| 794 var query = (req.url).query; |
| 795 var queryOffset = 0; |
| 796 var queryMap = {}; |
| 797 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 798 parseBool(n) { |
| 799 if (n == "true") return true; |
| 800 if (n == "false") return false; |
| 801 if (n == null) return null; |
| 802 throw new core.ArgumentError("Invalid boolean: $n"); |
| 803 } |
| 804 if (query.length > 0) { |
| 805 for (var part in query.split("&")) { |
| 806 var keyvalue = part.split("="); |
| 807 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 808 } |
| 809 } |
| 810 |
| 811 |
| 812 var h = { |
| 813 "content-type" : "application/json; charset=utf-8", |
| 814 }; |
| 815 var resp = convert.JSON.encode(buildEmpty()); |
| 816 return new async.Future.value(stringResponse(200, h, resp)); |
| 817 }), true); |
| 818 res.delete(arg_projectId, arg_indexId, arg_docId).then(unittest.expectAsyn
c(((api.Empty response) { |
| 819 checkEmpty(response); |
| 820 }))); |
| 821 }); |
| 822 |
| 823 unittest.test("method--get", () { |
| 824 |
| 825 var mock = new HttpServerMock(); |
| 826 api.ProjectsIndexesDocumentsResourceApi res = new api.CloudsearchApi(mock)
.projects.indexes.documents; |
| 827 var arg_projectId = "foo"; |
| 828 var arg_indexId = "foo"; |
| 829 var arg_docId = "foo"; |
| 830 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 831 var path = (req.url).path; |
| 832 var pathOffset = 0; |
| 833 var index; |
| 834 var subPart; |
| 835 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 836 pathOffset += 1; |
| 837 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 838 pathOffset += 12; |
| 839 index = path.indexOf("/indexes/", pathOffset); |
| 840 unittest.expect(index >= 0, unittest.isTrue); |
| 841 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 842 pathOffset = index; |
| 843 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 844 unittest.expect(path.substring(pathOffset, pathOffset + 9), unittest.equ
als("/indexes/")); |
| 845 pathOffset += 9; |
| 846 index = path.indexOf("/documents/", pathOffset); |
| 847 unittest.expect(index >= 0, unittest.isTrue); |
| 848 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 849 pathOffset = index; |
| 850 unittest.expect(subPart, unittest.equals("$arg_indexId")); |
| 851 unittest.expect(path.substring(pathOffset, pathOffset + 11), unittest.eq
uals("/documents/")); |
| 852 pathOffset += 11; |
| 853 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset)); |
| 854 pathOffset = path.length; |
| 855 unittest.expect(subPart, unittest.equals("$arg_docId")); |
| 856 |
| 857 var query = (req.url).query; |
| 858 var queryOffset = 0; |
| 859 var queryMap = {}; |
| 860 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 861 parseBool(n) { |
| 862 if (n == "true") return true; |
| 863 if (n == "false") return false; |
| 864 if (n == null) return null; |
| 865 throw new core.ArgumentError("Invalid boolean: $n"); |
| 866 } |
| 867 if (query.length > 0) { |
| 868 for (var part in query.split("&")) { |
| 869 var keyvalue = part.split("="); |
| 870 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 871 } |
| 872 } |
| 873 |
| 874 |
| 875 var h = { |
| 876 "content-type" : "application/json; charset=utf-8", |
| 877 }; |
| 878 var resp = convert.JSON.encode(buildDocument()); |
| 879 return new async.Future.value(stringResponse(200, h, resp)); |
| 880 }), true); |
| 881 res.get(arg_projectId, arg_indexId, arg_docId).then(unittest.expectAsync((
(api.Document response) { |
| 882 checkDocument(response); |
| 883 }))); |
| 884 }); |
| 885 |
| 886 unittest.test("method--list", () { |
| 887 |
| 888 var mock = new HttpServerMock(); |
| 889 api.ProjectsIndexesDocumentsResourceApi res = new api.CloudsearchApi(mock)
.projects.indexes.documents; |
| 890 var arg_projectId = "foo"; |
| 891 var arg_indexId = "foo"; |
| 892 var arg_pageSize = 42; |
| 893 var arg_pageToken = "foo"; |
| 894 var arg_view = "foo"; |
| 895 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 896 var path = (req.url).path; |
| 897 var pathOffset = 0; |
| 898 var index; |
| 899 var subPart; |
| 900 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 901 pathOffset += 1; |
| 902 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("v1/projects/")); |
| 903 pathOffset += 12; |
| 904 index = path.indexOf("/indexes/", pathOffset); |
| 905 unittest.expect(index >= 0, unittest.isTrue); |
| 906 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 907 pathOffset = index; |
| 908 unittest.expect(subPart, unittest.equals("$arg_projectId")); |
| 909 unittest.expect(path.substring(pathOffset, pathOffset + 9), unittest.equ
als("/indexes/")); |
| 910 pathOffset += 9; |
| 911 index = path.indexOf("/documents", pathOffset); |
| 912 unittest.expect(index >= 0, unittest.isTrue); |
| 913 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 914 pathOffset = index; |
| 915 unittest.expect(subPart, unittest.equals("$arg_indexId")); |
| 916 unittest.expect(path.substring(pathOffset, pathOffset + 10), unittest.eq
uals("/documents")); |
| 917 pathOffset += 10; |
| 918 |
| 919 var query = (req.url).query; |
| 920 var queryOffset = 0; |
| 921 var queryMap = {}; |
| 922 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 923 parseBool(n) { |
| 924 if (n == "true") return true; |
| 925 if (n == "false") return false; |
| 926 if (n == null) return null; |
| 927 throw new core.ArgumentError("Invalid boolean: $n"); |
| 928 } |
| 929 if (query.length > 0) { |
| 930 for (var part in query.split("&")) { |
| 931 var keyvalue = part.split("="); |
| 932 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 933 } |
| 934 } |
| 935 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ
als(arg_pageSize)); |
| 936 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); |
| 937 unittest.expect(queryMap["view"].first, unittest.equals(arg_view)); |
| 938 |
| 939 |
| 940 var h = { |
| 941 "content-type" : "application/json; charset=utf-8", |
| 942 }; |
| 943 var resp = convert.JSON.encode(buildListDocumentsResponse()); |
| 944 return new async.Future.value(stringResponse(200, h, resp)); |
| 945 }), true); |
| 946 res.list(arg_projectId, arg_indexId, pageSize: arg_pageSize, pageToken: ar
g_pageToken, view: arg_view).then(unittest.expectAsync(((api.ListDocumentsRespon
se response) { |
| 947 checkListDocumentsResponse(response); |
| 948 }))); |
| 949 }); |
| 950 |
| 951 }); |
| 952 |
| 953 |
| 954 } |
| 955 |
OLD | NEW |