| OLD | NEW |
| 1 library googleapis.groupssettings.v1.test; | 1 library googleapis.groupssettings.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/groupssettings/v1.dart' as api; | 12 import 'package:googleapis/groupssettings/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.allowExternalMembers = "foo"; | 59 o.allowExternalMembers = "foo"; |
| 25 o.allowGoogleCommunication = "foo"; | 60 o.allowGoogleCommunication = "foo"; |
| 26 o.allowWebPosting = "foo"; | 61 o.allowWebPosting = "foo"; |
| 27 o.archiveOnly = "foo"; | 62 o.archiveOnly = "foo"; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 var o = buildGroups(); | 131 var o = buildGroups(); |
| 97 var od = new api.Groups.fromJson(o.toJson()); | 132 var od = new api.Groups.fromJson(o.toJson()); |
| 98 checkGroups(od); | 133 checkGroups(od); |
| 99 }); | 134 }); |
| 100 }); | 135 }); |
| 101 | 136 |
| 102 | 137 |
| 103 unittest.group("resource-GroupsResourceApi", () { | 138 unittest.group("resource-GroupsResourceApi", () { |
| 104 unittest.test("method--get", () { | 139 unittest.test("method--get", () { |
| 105 | 140 |
| 106 var mock = new common_test.HttpServerMock(); | 141 var mock = new HttpServerMock(); |
| 107 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; | 142 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; |
| 108 var arg_groupUniqueId = "foo"; | 143 var arg_groupUniqueId = "foo"; |
| 109 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 144 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 110 var path = (req.url).path; | 145 var path = (req.url).path; |
| 111 var pathOffset = 0; | 146 var pathOffset = 0; |
| 112 var index; | 147 var index; |
| 113 var subPart; | 148 var subPart; |
| 114 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 149 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 115 pathOffset += 1; | 150 pathOffset += 1; |
| 116 | 151 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 129 var keyvalue = part.split("="); | 164 var keyvalue = part.split("="); |
| 130 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 165 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 131 } | 166 } |
| 132 } | 167 } |
| 133 | 168 |
| 134 | 169 |
| 135 var h = { | 170 var h = { |
| 136 "content-type" : "application/json; charset=utf-8", | 171 "content-type" : "application/json; charset=utf-8", |
| 137 }; | 172 }; |
| 138 var resp = convert.JSON.encode(buildGroups()); | 173 var resp = convert.JSON.encode(buildGroups()); |
| 139 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 174 return new async.Future.value(stringResponse(200, h, resp)); |
| 140 }), true); | 175 }), true); |
| 141 res.get(arg_groupUniqueId).then(unittest.expectAsync(((api.Groups response
) { | 176 res.get(arg_groupUniqueId).then(unittest.expectAsync(((api.Groups response
) { |
| 142 checkGroups(response); | 177 checkGroups(response); |
| 143 }))); | 178 }))); |
| 144 }); | 179 }); |
| 145 | 180 |
| 146 unittest.test("method--patch", () { | 181 unittest.test("method--patch", () { |
| 147 | 182 |
| 148 var mock = new common_test.HttpServerMock(); | 183 var mock = new HttpServerMock(); |
| 149 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; | 184 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; |
| 150 var arg_request = buildGroups(); | 185 var arg_request = buildGroups(); |
| 151 var arg_groupUniqueId = "foo"; | 186 var arg_groupUniqueId = "foo"; |
| 152 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 187 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 153 var obj = new api.Groups.fromJson(json); | 188 var obj = new api.Groups.fromJson(json); |
| 154 checkGroups(obj); | 189 checkGroups(obj); |
| 155 | 190 |
| 156 var path = (req.url).path; | 191 var path = (req.url).path; |
| 157 var pathOffset = 0; | 192 var pathOffset = 0; |
| 158 var index; | 193 var index; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 175 var keyvalue = part.split("="); | 210 var keyvalue = part.split("="); |
| 176 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 211 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 177 } | 212 } |
| 178 } | 213 } |
| 179 | 214 |
| 180 | 215 |
| 181 var h = { | 216 var h = { |
| 182 "content-type" : "application/json; charset=utf-8", | 217 "content-type" : "application/json; charset=utf-8", |
| 183 }; | 218 }; |
| 184 var resp = convert.JSON.encode(buildGroups()); | 219 var resp = convert.JSON.encode(buildGroups()); |
| 185 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 220 return new async.Future.value(stringResponse(200, h, resp)); |
| 186 }), true); | 221 }), true); |
| 187 res.patch(arg_request, arg_groupUniqueId).then(unittest.expectAsync(((api.
Groups response) { | 222 res.patch(arg_request, arg_groupUniqueId).then(unittest.expectAsync(((api.
Groups response) { |
| 188 checkGroups(response); | 223 checkGroups(response); |
| 189 }))); | 224 }))); |
| 190 }); | 225 }); |
| 191 | 226 |
| 192 unittest.test("method--update", () { | 227 unittest.test("method--update", () { |
| 193 | 228 |
| 194 var mock = new common_test.HttpServerMock(); | 229 var mock = new HttpServerMock(); |
| 195 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; | 230 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; |
| 196 var arg_request = buildGroups(); | 231 var arg_request = buildGroups(); |
| 197 var arg_groupUniqueId = "foo"; | 232 var arg_groupUniqueId = "foo"; |
| 198 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 233 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 199 var obj = new api.Groups.fromJson(json); | 234 var obj = new api.Groups.fromJson(json); |
| 200 checkGroups(obj); | 235 checkGroups(obj); |
| 201 | 236 |
| 202 var path = (req.url).path; | 237 var path = (req.url).path; |
| 203 var pathOffset = 0; | 238 var pathOffset = 0; |
| 204 var index; | 239 var index; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 221 var keyvalue = part.split("="); | 256 var keyvalue = part.split("="); |
| 222 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 257 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 223 } | 258 } |
| 224 } | 259 } |
| 225 | 260 |
| 226 | 261 |
| 227 var h = { | 262 var h = { |
| 228 "content-type" : "application/json; charset=utf-8", | 263 "content-type" : "application/json; charset=utf-8", |
| 229 }; | 264 }; |
| 230 var resp = convert.JSON.encode(buildGroups()); | 265 var resp = convert.JSON.encode(buildGroups()); |
| 231 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 266 return new async.Future.value(stringResponse(200, h, resp)); |
| 232 }), true); | 267 }), true); |
| 233 res.update(arg_request, arg_groupUniqueId).then(unittest.expectAsync(((api
.Groups response) { | 268 res.update(arg_request, arg_groupUniqueId).then(unittest.expectAsync(((api
.Groups response) { |
| 234 checkGroups(response); | 269 checkGroups(response); |
| 235 }))); | 270 }))); |
| 236 }); | 271 }); |
| 237 | 272 |
| 238 }); | 273 }); |
| 239 | 274 |
| 240 | 275 |
| 241 } | 276 } |
| 242 | 277 |
| OLD | NEW |