| OLD | NEW |
| 1 library googleapis.urlshortener.v1.test; | 1 library googleapis.urlshortener.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/urlshortener/v1.dart' as api; | 12 import 'package:googleapis/urlshortener/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 } |
| 18 | 22 |
| 19 buildUnnamed742() { | 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 buildUnnamed1393() { |
| 20 var o = new core.List<api.StringCount>(); | 55 var o = new core.List<api.StringCount>(); |
| 21 o.add(buildStringCount()); | 56 o.add(buildStringCount()); |
| 22 o.add(buildStringCount()); | 57 o.add(buildStringCount()); |
| 23 return o; | 58 return o; |
| 24 } | 59 } |
| 25 | 60 |
| 26 checkUnnamed742(core.List<api.StringCount> o) { | 61 checkUnnamed1393(core.List<api.StringCount> o) { |
| 27 unittest.expect(o, unittest.hasLength(2)); | 62 unittest.expect(o, unittest.hasLength(2)); |
| 28 checkStringCount(o[0]); | 63 checkStringCount(o[0]); |
| 29 checkStringCount(o[1]); | 64 checkStringCount(o[1]); |
| 30 } | 65 } |
| 31 | 66 |
| 32 buildUnnamed743() { | 67 buildUnnamed1394() { |
| 33 var o = new core.List<api.StringCount>(); | 68 var o = new core.List<api.StringCount>(); |
| 34 o.add(buildStringCount()); | 69 o.add(buildStringCount()); |
| 35 o.add(buildStringCount()); | 70 o.add(buildStringCount()); |
| 36 return o; | 71 return o; |
| 37 } | 72 } |
| 38 | 73 |
| 39 checkUnnamed743(core.List<api.StringCount> o) { | 74 checkUnnamed1394(core.List<api.StringCount> o) { |
| 40 unittest.expect(o, unittest.hasLength(2)); | 75 unittest.expect(o, unittest.hasLength(2)); |
| 41 checkStringCount(o[0]); | 76 checkStringCount(o[0]); |
| 42 checkStringCount(o[1]); | 77 checkStringCount(o[1]); |
| 43 } | 78 } |
| 44 | 79 |
| 45 buildUnnamed744() { | 80 buildUnnamed1395() { |
| 46 var o = new core.List<api.StringCount>(); | 81 var o = new core.List<api.StringCount>(); |
| 47 o.add(buildStringCount()); | 82 o.add(buildStringCount()); |
| 48 o.add(buildStringCount()); | 83 o.add(buildStringCount()); |
| 49 return o; | 84 return o; |
| 50 } | 85 } |
| 51 | 86 |
| 52 checkUnnamed744(core.List<api.StringCount> o) { | 87 checkUnnamed1395(core.List<api.StringCount> o) { |
| 53 unittest.expect(o, unittest.hasLength(2)); | 88 unittest.expect(o, unittest.hasLength(2)); |
| 54 checkStringCount(o[0]); | 89 checkStringCount(o[0]); |
| 55 checkStringCount(o[1]); | 90 checkStringCount(o[1]); |
| 56 } | 91 } |
| 57 | 92 |
| 58 buildUnnamed745() { | 93 buildUnnamed1396() { |
| 59 var o = new core.List<api.StringCount>(); | 94 var o = new core.List<api.StringCount>(); |
| 60 o.add(buildStringCount()); | 95 o.add(buildStringCount()); |
| 61 o.add(buildStringCount()); | 96 o.add(buildStringCount()); |
| 62 return o; | 97 return o; |
| 63 } | 98 } |
| 64 | 99 |
| 65 checkUnnamed745(core.List<api.StringCount> o) { | 100 checkUnnamed1396(core.List<api.StringCount> o) { |
| 66 unittest.expect(o, unittest.hasLength(2)); | 101 unittest.expect(o, unittest.hasLength(2)); |
| 67 checkStringCount(o[0]); | 102 checkStringCount(o[0]); |
| 68 checkStringCount(o[1]); | 103 checkStringCount(o[1]); |
| 69 } | 104 } |
| 70 | 105 |
| 71 core.int buildCounterAnalyticsSnapshot = 0; | 106 core.int buildCounterAnalyticsSnapshot = 0; |
| 72 buildAnalyticsSnapshot() { | 107 buildAnalyticsSnapshot() { |
| 73 var o = new api.AnalyticsSnapshot(); | 108 var o = new api.AnalyticsSnapshot(); |
| 74 buildCounterAnalyticsSnapshot++; | 109 buildCounterAnalyticsSnapshot++; |
| 75 if (buildCounterAnalyticsSnapshot < 3) { | 110 if (buildCounterAnalyticsSnapshot < 3) { |
| 76 o.browsers = buildUnnamed742(); | 111 o.browsers = buildUnnamed1393(); |
| 77 o.countries = buildUnnamed743(); | 112 o.countries = buildUnnamed1394(); |
| 78 o.longUrlClicks = "foo"; | 113 o.longUrlClicks = "foo"; |
| 79 o.platforms = buildUnnamed744(); | 114 o.platforms = buildUnnamed1395(); |
| 80 o.referrers = buildUnnamed745(); | 115 o.referrers = buildUnnamed1396(); |
| 81 o.shortUrlClicks = "foo"; | 116 o.shortUrlClicks = "foo"; |
| 82 } | 117 } |
| 83 buildCounterAnalyticsSnapshot--; | 118 buildCounterAnalyticsSnapshot--; |
| 84 return o; | 119 return o; |
| 85 } | 120 } |
| 86 | 121 |
| 87 checkAnalyticsSnapshot(api.AnalyticsSnapshot o) { | 122 checkAnalyticsSnapshot(api.AnalyticsSnapshot o) { |
| 88 buildCounterAnalyticsSnapshot++; | 123 buildCounterAnalyticsSnapshot++; |
| 89 if (buildCounterAnalyticsSnapshot < 3) { | 124 if (buildCounterAnalyticsSnapshot < 3) { |
| 90 checkUnnamed742(o.browsers); | 125 checkUnnamed1393(o.browsers); |
| 91 checkUnnamed743(o.countries); | 126 checkUnnamed1394(o.countries); |
| 92 unittest.expect(o.longUrlClicks, unittest.equals('foo')); | 127 unittest.expect(o.longUrlClicks, unittest.equals('foo')); |
| 93 checkUnnamed744(o.platforms); | 128 checkUnnamed1395(o.platforms); |
| 94 checkUnnamed745(o.referrers); | 129 checkUnnamed1396(o.referrers); |
| 95 unittest.expect(o.shortUrlClicks, unittest.equals('foo')); | 130 unittest.expect(o.shortUrlClicks, unittest.equals('foo')); |
| 96 } | 131 } |
| 97 buildCounterAnalyticsSnapshot--; | 132 buildCounterAnalyticsSnapshot--; |
| 98 } | 133 } |
| 99 | 134 |
| 100 core.int buildCounterAnalyticsSummary = 0; | 135 core.int buildCounterAnalyticsSummary = 0; |
| 101 buildAnalyticsSummary() { | 136 buildAnalyticsSummary() { |
| 102 var o = new api.AnalyticsSummary(); | 137 var o = new api.AnalyticsSummary(); |
| 103 buildCounterAnalyticsSummary++; | 138 buildCounterAnalyticsSummary++; |
| 104 if (buildCounterAnalyticsSummary < 3) { | 139 if (buildCounterAnalyticsSummary < 3) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 checkAnalyticsSummary(o.analytics); | 202 checkAnalyticsSummary(o.analytics); |
| 168 unittest.expect(o.created, unittest.equals('foo')); | 203 unittest.expect(o.created, unittest.equals('foo')); |
| 169 unittest.expect(o.id, unittest.equals('foo')); | 204 unittest.expect(o.id, unittest.equals('foo')); |
| 170 unittest.expect(o.kind, unittest.equals('foo')); | 205 unittest.expect(o.kind, unittest.equals('foo')); |
| 171 unittest.expect(o.longUrl, unittest.equals('foo')); | 206 unittest.expect(o.longUrl, unittest.equals('foo')); |
| 172 unittest.expect(o.status, unittest.equals('foo')); | 207 unittest.expect(o.status, unittest.equals('foo')); |
| 173 } | 208 } |
| 174 buildCounterUrl--; | 209 buildCounterUrl--; |
| 175 } | 210 } |
| 176 | 211 |
| 177 buildUnnamed746() { | 212 buildUnnamed1397() { |
| 178 var o = new core.List<api.Url>(); | 213 var o = new core.List<api.Url>(); |
| 179 o.add(buildUrl()); | 214 o.add(buildUrl()); |
| 180 o.add(buildUrl()); | 215 o.add(buildUrl()); |
| 181 return o; | 216 return o; |
| 182 } | 217 } |
| 183 | 218 |
| 184 checkUnnamed746(core.List<api.Url> o) { | 219 checkUnnamed1397(core.List<api.Url> o) { |
| 185 unittest.expect(o, unittest.hasLength(2)); | 220 unittest.expect(o, unittest.hasLength(2)); |
| 186 checkUrl(o[0]); | 221 checkUrl(o[0]); |
| 187 checkUrl(o[1]); | 222 checkUrl(o[1]); |
| 188 } | 223 } |
| 189 | 224 |
| 190 core.int buildCounterUrlHistory = 0; | 225 core.int buildCounterUrlHistory = 0; |
| 191 buildUrlHistory() { | 226 buildUrlHistory() { |
| 192 var o = new api.UrlHistory(); | 227 var o = new api.UrlHistory(); |
| 193 buildCounterUrlHistory++; | 228 buildCounterUrlHistory++; |
| 194 if (buildCounterUrlHistory < 3) { | 229 if (buildCounterUrlHistory < 3) { |
| 195 o.items = buildUnnamed746(); | 230 o.items = buildUnnamed1397(); |
| 196 o.itemsPerPage = 42; | 231 o.itemsPerPage = 42; |
| 197 o.kind = "foo"; | 232 o.kind = "foo"; |
| 198 o.nextPageToken = "foo"; | 233 o.nextPageToken = "foo"; |
| 199 o.totalItems = 42; | 234 o.totalItems = 42; |
| 200 } | 235 } |
| 201 buildCounterUrlHistory--; | 236 buildCounterUrlHistory--; |
| 202 return o; | 237 return o; |
| 203 } | 238 } |
| 204 | 239 |
| 205 checkUrlHistory(api.UrlHistory o) { | 240 checkUrlHistory(api.UrlHistory o) { |
| 206 buildCounterUrlHistory++; | 241 buildCounterUrlHistory++; |
| 207 if (buildCounterUrlHistory < 3) { | 242 if (buildCounterUrlHistory < 3) { |
| 208 checkUnnamed746(o.items); | 243 checkUnnamed1397(o.items); |
| 209 unittest.expect(o.itemsPerPage, unittest.equals(42)); | 244 unittest.expect(o.itemsPerPage, unittest.equals(42)); |
| 210 unittest.expect(o.kind, unittest.equals('foo')); | 245 unittest.expect(o.kind, unittest.equals('foo')); |
| 211 unittest.expect(o.nextPageToken, unittest.equals('foo')); | 246 unittest.expect(o.nextPageToken, unittest.equals('foo')); |
| 212 unittest.expect(o.totalItems, unittest.equals(42)); | 247 unittest.expect(o.totalItems, unittest.equals(42)); |
| 213 } | 248 } |
| 214 buildCounterUrlHistory--; | 249 buildCounterUrlHistory--; |
| 215 } | 250 } |
| 216 | 251 |
| 217 | 252 |
| 218 main() { | 253 main() { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 var o = buildUrlHistory(); | 292 var o = buildUrlHistory(); |
| 258 var od = new api.UrlHistory.fromJson(o.toJson()); | 293 var od = new api.UrlHistory.fromJson(o.toJson()); |
| 259 checkUrlHistory(od); | 294 checkUrlHistory(od); |
| 260 }); | 295 }); |
| 261 }); | 296 }); |
| 262 | 297 |
| 263 | 298 |
| 264 unittest.group("resource-UrlResourceApi", () { | 299 unittest.group("resource-UrlResourceApi", () { |
| 265 unittest.test("method--get", () { | 300 unittest.test("method--get", () { |
| 266 | 301 |
| 267 var mock = new common_test.HttpServerMock(); | 302 var mock = new HttpServerMock(); |
| 268 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; | 303 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; |
| 269 var arg_shortUrl = "foo"; | 304 var arg_shortUrl = "foo"; |
| 270 var arg_projection = "foo"; | 305 var arg_projection = "foo"; |
| 271 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 306 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 272 var path = (req.url).path; | 307 var path = (req.url).path; |
| 273 var pathOffset = 0; | 308 var pathOffset = 0; |
| 274 var index; | 309 var index; |
| 275 var subPart; | 310 var subPart; |
| 276 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 311 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 277 pathOffset += 1; | 312 pathOffset += 1; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 297 } | 332 } |
| 298 } | 333 } |
| 299 unittest.expect(queryMap["shortUrl"].first, unittest.equals(arg_shortUrl
)); | 334 unittest.expect(queryMap["shortUrl"].first, unittest.equals(arg_shortUrl
)); |
| 300 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); | 335 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); |
| 301 | 336 |
| 302 | 337 |
| 303 var h = { | 338 var h = { |
| 304 "content-type" : "application/json; charset=utf-8", | 339 "content-type" : "application/json; charset=utf-8", |
| 305 }; | 340 }; |
| 306 var resp = convert.JSON.encode(buildUrl()); | 341 var resp = convert.JSON.encode(buildUrl()); |
| 307 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 342 return new async.Future.value(stringResponse(200, h, resp)); |
| 308 }), true); | 343 }), true); |
| 309 res.get(arg_shortUrl, projection: arg_projection).then(unittest.expectAsyn
c(((api.Url response) { | 344 res.get(arg_shortUrl, projection: arg_projection).then(unittest.expectAsyn
c(((api.Url response) { |
| 310 checkUrl(response); | 345 checkUrl(response); |
| 311 }))); | 346 }))); |
| 312 }); | 347 }); |
| 313 | 348 |
| 314 unittest.test("method--insert", () { | 349 unittest.test("method--insert", () { |
| 315 | 350 |
| 316 var mock = new common_test.HttpServerMock(); | 351 var mock = new HttpServerMock(); |
| 317 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; | 352 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; |
| 318 var arg_request = buildUrl(); | 353 var arg_request = buildUrl(); |
| 319 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 354 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 320 var obj = new api.Url.fromJson(json); | 355 var obj = new api.Url.fromJson(json); |
| 321 checkUrl(obj); | 356 checkUrl(obj); |
| 322 | 357 |
| 323 var path = (req.url).path; | 358 var path = (req.url).path; |
| 324 var pathOffset = 0; | 359 var pathOffset = 0; |
| 325 var index; | 360 var index; |
| 326 var subPart; | 361 var subPart; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 346 var keyvalue = part.split("="); | 381 var keyvalue = part.split("="); |
| 347 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 382 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 348 } | 383 } |
| 349 } | 384 } |
| 350 | 385 |
| 351 | 386 |
| 352 var h = { | 387 var h = { |
| 353 "content-type" : "application/json; charset=utf-8", | 388 "content-type" : "application/json; charset=utf-8", |
| 354 }; | 389 }; |
| 355 var resp = convert.JSON.encode(buildUrl()); | 390 var resp = convert.JSON.encode(buildUrl()); |
| 356 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 391 return new async.Future.value(stringResponse(200, h, resp)); |
| 357 }), true); | 392 }), true); |
| 358 res.insert(arg_request).then(unittest.expectAsync(((api.Url response) { | 393 res.insert(arg_request).then(unittest.expectAsync(((api.Url response) { |
| 359 checkUrl(response); | 394 checkUrl(response); |
| 360 }))); | 395 }))); |
| 361 }); | 396 }); |
| 362 | 397 |
| 363 unittest.test("method--list", () { | 398 unittest.test("method--list", () { |
| 364 | 399 |
| 365 var mock = new common_test.HttpServerMock(); | 400 var mock = new HttpServerMock(); |
| 366 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; | 401 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; |
| 367 var arg_projection = "foo"; | 402 var arg_projection = "foo"; |
| 368 var arg_start_token = "foo"; | 403 var arg_start_token = "foo"; |
| 369 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 404 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 370 var path = (req.url).path; | 405 var path = (req.url).path; |
| 371 var pathOffset = 0; | 406 var pathOffset = 0; |
| 372 var index; | 407 var index; |
| 373 var subPart; | 408 var subPart; |
| 374 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 409 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 375 pathOffset += 1; | 410 pathOffset += 1; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 395 } | 430 } |
| 396 } | 431 } |
| 397 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); | 432 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); |
| 398 unittest.expect(queryMap["start-token"].first, unittest.equals(arg_start
_token)); | 433 unittest.expect(queryMap["start-token"].first, unittest.equals(arg_start
_token)); |
| 399 | 434 |
| 400 | 435 |
| 401 var h = { | 436 var h = { |
| 402 "content-type" : "application/json; charset=utf-8", | 437 "content-type" : "application/json; charset=utf-8", |
| 403 }; | 438 }; |
| 404 var resp = convert.JSON.encode(buildUrlHistory()); | 439 var resp = convert.JSON.encode(buildUrlHistory()); |
| 405 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 440 return new async.Future.value(stringResponse(200, h, resp)); |
| 406 }), true); | 441 }), true); |
| 407 res.list(projection: arg_projection, start_token: arg_start_token).then(un
ittest.expectAsync(((api.UrlHistory response) { | 442 res.list(projection: arg_projection, start_token: arg_start_token).then(un
ittest.expectAsync(((api.UrlHistory response) { |
| 408 checkUrlHistory(response); | 443 checkUrlHistory(response); |
| 409 }))); | 444 }))); |
| 410 }); | 445 }); |
| 411 | 446 |
| 412 }); | 447 }); |
| 413 | 448 |
| 414 | 449 |
| 415 } | 450 } |
| 416 | 451 |
| OLD | NEW |