| OLD | NEW |
| 1 library googleapis.groupsmigration.v1.test; | 1 library googleapis.groupsmigration.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/groupsmigration/v1.dart' as api; | 12 import 'package:googleapis/groupsmigration/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 buildCounterGroups = 0; | 54 core.int buildCounterGroups = 0; |
| 20 buildGroups() { | 55 buildGroups() { |
| 21 var o = new api.Groups(); | 56 var o = new api.Groups(); |
| 22 buildCounterGroups++; | 57 buildCounterGroups++; |
| 23 if (buildCounterGroups < 3) { | 58 if (buildCounterGroups < 3) { |
| 24 o.kind = "foo"; | 59 o.kind = "foo"; |
| 25 o.responseCode = "foo"; | 60 o.responseCode = "foo"; |
| 26 } | 61 } |
| 27 buildCounterGroups--; | 62 buildCounterGroups--; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 46 checkGroups(od); | 81 checkGroups(od); |
| 47 }); | 82 }); |
| 48 }); | 83 }); |
| 49 | 84 |
| 50 | 85 |
| 51 unittest.group("resource-ArchiveResourceApi", () { | 86 unittest.group("resource-ArchiveResourceApi", () { |
| 52 unittest.test("method--insert", () { | 87 unittest.test("method--insert", () { |
| 53 // TODO: Implement tests for media upload; | 88 // TODO: Implement tests for media upload; |
| 54 // TODO: Implement tests for media download; | 89 // TODO: Implement tests for media download; |
| 55 | 90 |
| 56 var mock = new common_test.HttpServerMock(); | 91 var mock = new HttpServerMock(); |
| 57 api.ArchiveResourceApi res = new api.GroupsmigrationApi(mock).archive; | 92 api.ArchiveResourceApi res = new api.GroupsmigrationApi(mock).archive; |
| 58 var arg_groupId = "foo"; | 93 var arg_groupId = "foo"; |
| 59 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 94 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 60 var path = (req.url).path; | 95 var path = (req.url).path; |
| 61 var pathOffset = 0; | 96 var pathOffset = 0; |
| 62 var index; | 97 var index; |
| 63 var subPart; | 98 var subPart; |
| 64 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 99 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 65 pathOffset += 1; | 100 pathOffset += 1; |
| 66 | 101 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 79 var keyvalue = part.split("="); | 114 var keyvalue = part.split("="); |
| 80 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 115 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 81 } | 116 } |
| 82 } | 117 } |
| 83 | 118 |
| 84 | 119 |
| 85 var h = { | 120 var h = { |
| 86 "content-type" : "application/json; charset=utf-8", | 121 "content-type" : "application/json; charset=utf-8", |
| 87 }; | 122 }; |
| 88 var resp = convert.JSON.encode(buildGroups()); | 123 var resp = convert.JSON.encode(buildGroups()); |
| 89 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 124 return new async.Future.value(stringResponse(200, h, resp)); |
| 90 }), true); | 125 }), true); |
| 91 res.insert(arg_groupId).then(unittest.expectAsync(((api.Groups response) { | 126 res.insert(arg_groupId).then(unittest.expectAsync(((api.Groups response) { |
| 92 checkGroups(response); | 127 checkGroups(response); |
| 93 }))); | 128 }))); |
| 94 }); | 129 }); |
| 95 | 130 |
| 96 }); | 131 }); |
| 97 | 132 |
| 98 | 133 |
| 99 } | 134 } |
| 100 | 135 |
| OLD | NEW |