| 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; | |
| 5 import "dart:async" as async; | 4 import "dart:async" as async; |
| 6 import "dart:convert" as convert; | 5 import "dart:convert" as convert; |
| 7 | 6 |
| 8 import 'package:http/http.dart' as http; | 7 import 'package:http/http.dart' as http; |
| 9 import 'package:http/testing.dart' as http_testing; | |
| 10 import 'package:test/test.dart' as unittest; | 8 import 'package:test/test.dart' as unittest; |
| 11 | 9 |
| 12 import 'package:googleapis/groupssettings/v1.dart' as api; | 10 import 'package:googleapis/groupssettings/v1.dart' as api; |
| 13 | 11 |
| 14 class HttpServerMock extends http.BaseClient { | 12 class HttpServerMock extends http.BaseClient { |
| 15 core.Function _callback; | 13 core.Function _callback; |
| 16 core.bool _expectJson; | 14 core.bool _expectJson; |
| 17 | 15 |
| 18 void register(core.Function callback, core.bool expectJson) { | 16 void register(core.Function callback, core.bool expectJson) { |
| 19 _callback = callback; | 17 _callback = callback; |
| 20 _expectJson = expectJson; | 18 _expectJson = expectJson; |
| 21 } | 19 } |
| 22 | 20 |
| 23 async.Future<http.StreamedResponse> send(http.BaseRequest request) { | 21 async.Future<http.StreamedResponse> send(http.BaseRequest request) { |
| 24 if (_expectJson) { | 22 if (_expectJson) { |
| 25 return request.finalize() | 23 return request |
| 24 .finalize() |
| 26 .transform(convert.UTF8.decoder) | 25 .transform(convert.UTF8.decoder) |
| 27 .join('') | 26 .join('') |
| 28 .then((core.String jsonString) { | 27 .then((core.String jsonString) { |
| 29 if (jsonString.isEmpty) { | 28 if (jsonString.isEmpty) { |
| 30 return _callback(request, null); | 29 return _callback(request, null); |
| 31 } else { | 30 } else { |
| 32 return _callback(request, convert.JSON.decode(jsonString)); | 31 return _callback(request, convert.JSON.decode(jsonString)); |
| 33 } | 32 } |
| 34 }); | 33 }); |
| 35 } else { | 34 } else { |
| 36 var stream = request.finalize(); | 35 var stream = request.finalize(); |
| 37 if (stream == null) { | 36 if (stream == null) { |
| 38 return _callback(request, []); | 37 return _callback(request, []); |
| 39 } else { | 38 } else { |
| 40 return stream.toBytes().then((data) { | 39 return stream.toBytes().then((data) { |
| 41 return _callback(request, data); | 40 return _callback(request, data); |
| 42 }); | 41 }); |
| 43 } | 42 } |
| 44 } | 43 } |
| 45 } | 44 } |
| 46 } | 45 } |
| 47 | 46 |
| 48 http.StreamedResponse stringResponse( | 47 http.StreamedResponse stringResponse(core.int status, |
| 49 core.int status, core.Map<core.String, core.String> headers, core.String bod
y) { | 48 core.Map<core.String, core.String> headers, core.String body) { |
| 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | 49 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
| 51 return new http.StreamedResponse(stream, status, headers: headers); | 50 return new http.StreamedResponse(stream, status, headers: headers); |
| 52 } | 51 } |
| 53 | 52 |
| 54 core.int buildCounterGroups = 0; | 53 core.int buildCounterGroups = 0; |
| 55 buildGroups() { | 54 buildGroups() { |
| 56 var o = new api.Groups(); | 55 var o = new api.Groups(); |
| 57 buildCounterGroups++; | 56 buildCounterGroups++; |
| 58 if (buildCounterGroups < 3) { | 57 if (buildCounterGroups < 3) { |
| 59 o.allowExternalMembers = "foo"; | 58 o.allowExternalMembers = "foo"; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 93 |
| 95 checkGroups(api.Groups o) { | 94 checkGroups(api.Groups o) { |
| 96 buildCounterGroups++; | 95 buildCounterGroups++; |
| 97 if (buildCounterGroups < 3) { | 96 if (buildCounterGroups < 3) { |
| 98 unittest.expect(o.allowExternalMembers, unittest.equals('foo')); | 97 unittest.expect(o.allowExternalMembers, unittest.equals('foo')); |
| 99 unittest.expect(o.allowGoogleCommunication, unittest.equals('foo')); | 98 unittest.expect(o.allowGoogleCommunication, unittest.equals('foo')); |
| 100 unittest.expect(o.allowWebPosting, unittest.equals('foo')); | 99 unittest.expect(o.allowWebPosting, unittest.equals('foo')); |
| 101 unittest.expect(o.archiveOnly, unittest.equals('foo')); | 100 unittest.expect(o.archiveOnly, unittest.equals('foo')); |
| 102 unittest.expect(o.customFooterText, unittest.equals('foo')); | 101 unittest.expect(o.customFooterText, unittest.equals('foo')); |
| 103 unittest.expect(o.customReplyTo, unittest.equals('foo')); | 102 unittest.expect(o.customReplyTo, unittest.equals('foo')); |
| 104 unittest.expect(o.defaultMessageDenyNotificationText, unittest.equals('foo')
); | 103 unittest.expect( |
| 104 o.defaultMessageDenyNotificationText, unittest.equals('foo')); |
| 105 unittest.expect(o.description, unittest.equals('foo')); | 105 unittest.expect(o.description, unittest.equals('foo')); |
| 106 unittest.expect(o.email, unittest.equals('foo')); | 106 unittest.expect(o.email, unittest.equals('foo')); |
| 107 unittest.expect(o.includeCustomFooter, unittest.equals('foo')); | 107 unittest.expect(o.includeCustomFooter, unittest.equals('foo')); |
| 108 unittest.expect(o.includeInGlobalAddressList, unittest.equals('foo')); | 108 unittest.expect(o.includeInGlobalAddressList, unittest.equals('foo')); |
| 109 unittest.expect(o.isArchived, unittest.equals('foo')); | 109 unittest.expect(o.isArchived, unittest.equals('foo')); |
| 110 unittest.expect(o.kind, unittest.equals('foo')); | 110 unittest.expect(o.kind, unittest.equals('foo')); |
| 111 unittest.expect(o.maxMessageBytes, unittest.equals(42)); | 111 unittest.expect(o.maxMessageBytes, unittest.equals(42)); |
| 112 unittest.expect(o.membersCanPostAsTheGroup, unittest.equals('foo')); | 112 unittest.expect(o.membersCanPostAsTheGroup, unittest.equals('foo')); |
| 113 unittest.expect(o.messageDisplayFont, unittest.equals('foo')); | 113 unittest.expect(o.messageDisplayFont, unittest.equals('foo')); |
| 114 unittest.expect(o.messageModerationLevel, unittest.equals('foo')); | 114 unittest.expect(o.messageModerationLevel, unittest.equals('foo')); |
| 115 unittest.expect(o.name, unittest.equals('foo')); | 115 unittest.expect(o.name, unittest.equals('foo')); |
| 116 unittest.expect(o.primaryLanguage, unittest.equals('foo')); | 116 unittest.expect(o.primaryLanguage, unittest.equals('foo')); |
| 117 unittest.expect(o.replyTo, unittest.equals('foo')); | 117 unittest.expect(o.replyTo, unittest.equals('foo')); |
| 118 unittest.expect(o.sendMessageDenyNotification, unittest.equals('foo')); | 118 unittest.expect(o.sendMessageDenyNotification, unittest.equals('foo')); |
| 119 unittest.expect(o.showInGroupDirectory, unittest.equals('foo')); | 119 unittest.expect(o.showInGroupDirectory, unittest.equals('foo')); |
| 120 unittest.expect(o.spamModerationLevel, unittest.equals('foo')); | 120 unittest.expect(o.spamModerationLevel, unittest.equals('foo')); |
| 121 unittest.expect(o.whoCanAdd, unittest.equals('foo')); | 121 unittest.expect(o.whoCanAdd, unittest.equals('foo')); |
| 122 unittest.expect(o.whoCanContactOwner, unittest.equals('foo')); | 122 unittest.expect(o.whoCanContactOwner, unittest.equals('foo')); |
| 123 unittest.expect(o.whoCanInvite, unittest.equals('foo')); | 123 unittest.expect(o.whoCanInvite, unittest.equals('foo')); |
| 124 unittest.expect(o.whoCanJoin, unittest.equals('foo')); | 124 unittest.expect(o.whoCanJoin, unittest.equals('foo')); |
| 125 unittest.expect(o.whoCanLeaveGroup, unittest.equals('foo')); | 125 unittest.expect(o.whoCanLeaveGroup, unittest.equals('foo')); |
| 126 unittest.expect(o.whoCanPostMessage, unittest.equals('foo')); | 126 unittest.expect(o.whoCanPostMessage, unittest.equals('foo')); |
| 127 unittest.expect(o.whoCanViewGroup, unittest.equals('foo')); | 127 unittest.expect(o.whoCanViewGroup, unittest.equals('foo')); |
| 128 unittest.expect(o.whoCanViewMembership, unittest.equals('foo')); | 128 unittest.expect(o.whoCanViewMembership, unittest.equals('foo')); |
| 129 } | 129 } |
| 130 buildCounterGroups--; | 130 buildCounterGroups--; |
| 131 } | 131 } |
| 132 | 132 |
| 133 | |
| 134 main() { | 133 main() { |
| 135 unittest.group("obj-schema-Groups", () { | 134 unittest.group("obj-schema-Groups", () { |
| 136 unittest.test("to-json--from-json", () { | 135 unittest.test("to-json--from-json", () { |
| 137 var o = buildGroups(); | 136 var o = buildGroups(); |
| 138 var od = new api.Groups.fromJson(o.toJson()); | 137 var od = new api.Groups.fromJson(o.toJson()); |
| 139 checkGroups(od); | 138 checkGroups(od); |
| 140 }); | 139 }); |
| 141 }); | 140 }); |
| 142 | 141 |
| 143 | |
| 144 unittest.group("resource-GroupsResourceApi", () { | 142 unittest.group("resource-GroupsResourceApi", () { |
| 145 unittest.test("method--get", () { | 143 unittest.test("method--get", () { |
| 146 | |
| 147 var mock = new HttpServerMock(); | 144 var mock = new HttpServerMock(); |
| 148 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; | 145 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; |
| 149 var arg_groupUniqueId = "foo"; | 146 var arg_groupUniqueId = "foo"; |
| 150 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { | 147 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 151 var path = (req.url).path; | 148 var path = (req.url).path; |
| 152 var pathOffset = 0; | 149 var pathOffset = 0; |
| 153 var index; | 150 var index; |
| 154 var subPart; | 151 var subPart; |
| 155 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 152 unittest.expect( |
| 153 path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| 156 pathOffset += 1; | 154 pathOffset += 1; |
| 157 | 155 |
| 158 var query = (req.url).query; | 156 var query = (req.url).query; |
| 159 var queryOffset = 0; | 157 var queryOffset = 0; |
| 160 var queryMap = {}; | 158 var queryMap = {}; |
| 161 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | 159 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 162 parseBool(n) { | 160 parseBool(n) { |
| 163 if (n == "true") return true; | 161 if (n == "true") return true; |
| 164 if (n == "false") return false; | 162 if (n == "false") return false; |
| 165 if (n == null) return null; | 163 if (n == null) return null; |
| 166 throw new core.ArgumentError("Invalid boolean: $n"); | 164 throw new core.ArgumentError("Invalid boolean: $n"); |
| 167 } | 165 } |
| 166 |
| 168 if (query.length > 0) { | 167 if (query.length > 0) { |
| 169 for (var part in query.split("&")) { | 168 for (var part in query.split("&")) { |
| 170 var keyvalue = part.split("="); | 169 var keyvalue = part.split("="); |
| 171 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 170 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), |
| 171 core.Uri.decodeQueryComponent(keyvalue[1])); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 | |
| 176 var h = { | 175 var h = { |
| 177 "content-type" : "application/json; charset=utf-8", | 176 "content-type": "application/json; charset=utf-8", |
| 178 }; | 177 }; |
| 179 var resp = convert.JSON.encode(buildGroups()); | 178 var resp = convert.JSON.encode(buildGroups()); |
| 180 return new async.Future.value(stringResponse(200, h, resp)); | 179 return new async.Future.value(stringResponse(200, h, resp)); |
| 181 }), true); | 180 }), true); |
| 182 res.get(arg_groupUniqueId).then(unittest.expectAsync1(((api.Groups respons
e) { | 181 res |
| 182 .get(arg_groupUniqueId) |
| 183 .then(unittest.expectAsync1(((api.Groups response) { |
| 183 checkGroups(response); | 184 checkGroups(response); |
| 184 }))); | 185 }))); |
| 185 }); | 186 }); |
| 186 | 187 |
| 187 unittest.test("method--patch", () { | 188 unittest.test("method--patch", () { |
| 188 | |
| 189 var mock = new HttpServerMock(); | 189 var mock = new HttpServerMock(); |
| 190 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; | 190 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; |
| 191 var arg_request = buildGroups(); | 191 var arg_request = buildGroups(); |
| 192 var arg_groupUniqueId = "foo"; | 192 var arg_groupUniqueId = "foo"; |
| 193 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { | 193 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 194 var obj = new api.Groups.fromJson(json); | 194 var obj = new api.Groups.fromJson(json); |
| 195 checkGroups(obj); | 195 checkGroups(obj); |
| 196 | 196 |
| 197 var path = (req.url).path; | 197 var path = (req.url).path; |
| 198 var pathOffset = 0; | 198 var pathOffset = 0; |
| 199 var index; | 199 var index; |
| 200 var subPart; | 200 var subPart; |
| 201 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 201 unittest.expect( |
| 202 path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| 202 pathOffset += 1; | 203 pathOffset += 1; |
| 203 | 204 |
| 204 var query = (req.url).query; | 205 var query = (req.url).query; |
| 205 var queryOffset = 0; | 206 var queryOffset = 0; |
| 206 var queryMap = {}; | 207 var queryMap = {}; |
| 207 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | 208 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 208 parseBool(n) { | 209 parseBool(n) { |
| 209 if (n == "true") return true; | 210 if (n == "true") return true; |
| 210 if (n == "false") return false; | 211 if (n == "false") return false; |
| 211 if (n == null) return null; | 212 if (n == null) return null; |
| 212 throw new core.ArgumentError("Invalid boolean: $n"); | 213 throw new core.ArgumentError("Invalid boolean: $n"); |
| 213 } | 214 } |
| 215 |
| 214 if (query.length > 0) { | 216 if (query.length > 0) { |
| 215 for (var part in query.split("&")) { | 217 for (var part in query.split("&")) { |
| 216 var keyvalue = part.split("="); | 218 var keyvalue = part.split("="); |
| 217 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 219 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), |
| 220 core.Uri.decodeQueryComponent(keyvalue[1])); |
| 218 } | 221 } |
| 219 } | 222 } |
| 220 | 223 |
| 221 | |
| 222 var h = { | 224 var h = { |
| 223 "content-type" : "application/json; charset=utf-8", | 225 "content-type": "application/json; charset=utf-8", |
| 224 }; | 226 }; |
| 225 var resp = convert.JSON.encode(buildGroups()); | 227 var resp = convert.JSON.encode(buildGroups()); |
| 226 return new async.Future.value(stringResponse(200, h, resp)); | 228 return new async.Future.value(stringResponse(200, h, resp)); |
| 227 }), true); | 229 }), true); |
| 228 res.patch(arg_request, arg_groupUniqueId).then(unittest.expectAsync1(((api
.Groups response) { | 230 res |
| 231 .patch(arg_request, arg_groupUniqueId) |
| 232 .then(unittest.expectAsync1(((api.Groups response) { |
| 229 checkGroups(response); | 233 checkGroups(response); |
| 230 }))); | 234 }))); |
| 231 }); | 235 }); |
| 232 | 236 |
| 233 unittest.test("method--update", () { | 237 unittest.test("method--update", () { |
| 234 | |
| 235 var mock = new HttpServerMock(); | 238 var mock = new HttpServerMock(); |
| 236 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; | 239 api.GroupsResourceApi res = new api.GroupssettingsApi(mock).groups; |
| 237 var arg_request = buildGroups(); | 240 var arg_request = buildGroups(); |
| 238 var arg_groupUniqueId = "foo"; | 241 var arg_groupUniqueId = "foo"; |
| 239 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { | 242 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 240 var obj = new api.Groups.fromJson(json); | 243 var obj = new api.Groups.fromJson(json); |
| 241 checkGroups(obj); | 244 checkGroups(obj); |
| 242 | 245 |
| 243 var path = (req.url).path; | 246 var path = (req.url).path; |
| 244 var pathOffset = 0; | 247 var pathOffset = 0; |
| 245 var index; | 248 var index; |
| 246 var subPart; | 249 var subPart; |
| 247 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 250 unittest.expect( |
| 251 path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| 248 pathOffset += 1; | 252 pathOffset += 1; |
| 249 | 253 |
| 250 var query = (req.url).query; | 254 var query = (req.url).query; |
| 251 var queryOffset = 0; | 255 var queryOffset = 0; |
| 252 var queryMap = {}; | 256 var queryMap = {}; |
| 253 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | 257 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 254 parseBool(n) { | 258 parseBool(n) { |
| 255 if (n == "true") return true; | 259 if (n == "true") return true; |
| 256 if (n == "false") return false; | 260 if (n == "false") return false; |
| 257 if (n == null) return null; | 261 if (n == null) return null; |
| 258 throw new core.ArgumentError("Invalid boolean: $n"); | 262 throw new core.ArgumentError("Invalid boolean: $n"); |
| 259 } | 263 } |
| 264 |
| 260 if (query.length > 0) { | 265 if (query.length > 0) { |
| 261 for (var part in query.split("&")) { | 266 for (var part in query.split("&")) { |
| 262 var keyvalue = part.split("="); | 267 var keyvalue = part.split("="); |
| 263 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 268 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), |
| 269 core.Uri.decodeQueryComponent(keyvalue[1])); |
| 264 } | 270 } |
| 265 } | 271 } |
| 266 | 272 |
| 267 | |
| 268 var h = { | 273 var h = { |
| 269 "content-type" : "application/json; charset=utf-8", | 274 "content-type": "application/json; charset=utf-8", |
| 270 }; | 275 }; |
| 271 var resp = convert.JSON.encode(buildGroups()); | 276 var resp = convert.JSON.encode(buildGroups()); |
| 272 return new async.Future.value(stringResponse(200, h, resp)); | 277 return new async.Future.value(stringResponse(200, h, resp)); |
| 273 }), true); | 278 }), true); |
| 274 res.update(arg_request, arg_groupUniqueId).then(unittest.expectAsync1(((ap
i.Groups response) { | 279 res |
| 280 .update(arg_request, arg_groupUniqueId) |
| 281 .then(unittest.expectAsync1(((api.Groups response) { |
| 275 checkGroups(response); | 282 checkGroups(response); |
| 276 }))); | 283 }))); |
| 277 }); | 284 }); |
| 278 | |
| 279 }); | 285 }); |
| 280 | |
| 281 | |
| 282 } | 286 } |
| 283 | |
| OLD | NEW |