OLD | NEW |
(Empty) | |
| 1 library googleapis.groupsmigration.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 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 |
| 15 import 'package:googleapis/groupsmigration/v1.dart' as api; |
| 16 |
| 17 |
| 18 |
| 19 core.int buildCounterGroups = 0; |
| 20 buildGroups() { |
| 21 var o = new api.Groups(); |
| 22 buildCounterGroups++; |
| 23 if (buildCounterGroups < 3) { |
| 24 o.kind = "foo"; |
| 25 o.responseCode = "foo"; |
| 26 } |
| 27 buildCounterGroups--; |
| 28 return o; |
| 29 } |
| 30 |
| 31 checkGroups(api.Groups o) { |
| 32 buildCounterGroups++; |
| 33 if (buildCounterGroups < 3) { |
| 34 unittest.expect(o.kind, unittest.equals('foo')); |
| 35 unittest.expect(o.responseCode, unittest.equals('foo')); |
| 36 } |
| 37 buildCounterGroups--; |
| 38 } |
| 39 |
| 40 |
| 41 main() { |
| 42 unittest.group("obj-schema-Groups", () { |
| 43 unittest.test("to-json--from-json", () { |
| 44 var o = buildGroups(); |
| 45 var od = new api.Groups.fromJson(o.toJson()); |
| 46 checkGroups(od); |
| 47 }); |
| 48 }); |
| 49 |
| 50 |
| 51 unittest.group("resource-ArchiveResourceApi", () { |
| 52 unittest.test("method--insert", () { |
| 53 // TODO: Implement tests for media upload; |
| 54 // TODO: Implement tests for media download; |
| 55 |
| 56 var mock = new common_test.HttpServerMock(); |
| 57 api.ArchiveResourceApi res = new api.GroupsmigrationApi(mock).archive; |
| 58 var arg_groupId = "foo"; |
| 59 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 60 var path = (req.url).path; |
| 61 var pathOffset = 0; |
| 62 var index; |
| 63 var subPart; |
| 64 unittest.expect(path.substring(pathOffset, pathOffset + 18), unittest.eq
uals("/groups/v1/groups/")); |
| 65 pathOffset += 18; |
| 66 index = path.indexOf("/archive", pathOffset); |
| 67 unittest.expect(index >= 0, unittest.isTrue); |
| 68 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 69 pathOffset = index; |
| 70 unittest.expect(subPart, unittest.equals("$arg_groupId")); |
| 71 unittest.expect(path.substring(pathOffset, pathOffset + 8), unittest.equ
als("/archive")); |
| 72 pathOffset += 8; |
| 73 |
| 74 var query = (req.url).query; |
| 75 var queryOffset = 0; |
| 76 var queryMap = {}; |
| 77 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 78 parseBool(n) { |
| 79 if (n == "true") return true; |
| 80 if (n == "false") return false; |
| 81 if (n == null) return null; |
| 82 throw new core.ArgumentError("Invalid boolean: $n"); |
| 83 } |
| 84 if (query.length > 0) { |
| 85 for (var part in query.split("&")) { |
| 86 var keyvalue = part.split("="); |
| 87 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 88 } |
| 89 } |
| 90 |
| 91 |
| 92 var h = { |
| 93 "content-type" : "application/json; charset=utf-8", |
| 94 }; |
| 95 var resp = convert.JSON.encode(buildGroups()); |
| 96 return new async.Future.value(common_test.stringResponse(200, h, resp)); |
| 97 }), true); |
| 98 res.insert(arg_groupId).then(unittest.expectAsync(((api.Groups response) { |
| 99 checkGroups(response); |
| 100 }))); |
| 101 }); |
| 102 |
| 103 }); |
| 104 |
| 105 |
| 106 } |
| 107 |
OLD | NEW |