| 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:test/test.dart' as unittest; |
| 11 | 11 |
| 12 import 'package:googleapis/urlshortener/v1.dart' as api; | 12 import 'package:googleapis/urlshortener/v1.dart' as api; |
| 13 | 13 |
| 14 class HttpServerMock extends http.BaseClient { | 14 class HttpServerMock extends http.BaseClient { |
| 15 core.Function _callback; | 15 core.Function _callback; |
| 16 core.bool _expectJson; | 16 core.bool _expectJson; |
| 17 | 17 |
| 18 void register(core.Function callback, core.bool expectJson) { | 18 void register(core.Function callback, core.bool expectJson) { |
| 19 _callback = callback; | 19 _callback = callback; |
| 20 _expectJson = expectJson; | 20 _expectJson = expectJson; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 } else { | 39 } else { |
| 40 return stream.toBytes().then((data) { | 40 return stream.toBytes().then((data) { |
| 41 return _callback(request, data); | 41 return _callback(request, data); |
| 42 }); | 42 }); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 http.StreamedResponse stringResponse( | 48 http.StreamedResponse stringResponse( |
| 49 core.int status, core.Map headers, core.String body) { | 49 core.int status, core.Map<core.String, core.String> headers, core.String bod
y) { |
| 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
| 51 return new http.StreamedResponse(stream, status, headers: headers); | 51 return new http.StreamedResponse(stream, status, headers: headers); |
| 52 } | 52 } |
| 53 | 53 |
| 54 buildUnnamed712() { | 54 buildUnnamed719() { |
| 55 var o = new core.List<api.StringCount>(); | 55 var o = new core.List<api.StringCount>(); |
| 56 o.add(buildStringCount()); | 56 o.add(buildStringCount()); |
| 57 o.add(buildStringCount()); | 57 o.add(buildStringCount()); |
| 58 return o; | 58 return o; |
| 59 } | 59 } |
| 60 | 60 |
| 61 checkUnnamed712(core.List<api.StringCount> o) { | 61 checkUnnamed719(core.List<api.StringCount> o) { |
| 62 unittest.expect(o, unittest.hasLength(2)); | 62 unittest.expect(o, unittest.hasLength(2)); |
| 63 checkStringCount(o[0]); | 63 checkStringCount(o[0]); |
| 64 checkStringCount(o[1]); | 64 checkStringCount(o[1]); |
| 65 } | 65 } |
| 66 | 66 |
| 67 buildUnnamed713() { | 67 buildUnnamed720() { |
| 68 var o = new core.List<api.StringCount>(); | 68 var o = new core.List<api.StringCount>(); |
| 69 o.add(buildStringCount()); | 69 o.add(buildStringCount()); |
| 70 o.add(buildStringCount()); | 70 o.add(buildStringCount()); |
| 71 return o; | 71 return o; |
| 72 } | 72 } |
| 73 | 73 |
| 74 checkUnnamed713(core.List<api.StringCount> o) { | 74 checkUnnamed720(core.List<api.StringCount> o) { |
| 75 unittest.expect(o, unittest.hasLength(2)); | 75 unittest.expect(o, unittest.hasLength(2)); |
| 76 checkStringCount(o[0]); | 76 checkStringCount(o[0]); |
| 77 checkStringCount(o[1]); | 77 checkStringCount(o[1]); |
| 78 } | 78 } |
| 79 | 79 |
| 80 buildUnnamed714() { | 80 buildUnnamed721() { |
| 81 var o = new core.List<api.StringCount>(); | 81 var o = new core.List<api.StringCount>(); |
| 82 o.add(buildStringCount()); | 82 o.add(buildStringCount()); |
| 83 o.add(buildStringCount()); | 83 o.add(buildStringCount()); |
| 84 return o; | 84 return o; |
| 85 } | 85 } |
| 86 | 86 |
| 87 checkUnnamed714(core.List<api.StringCount> o) { | 87 checkUnnamed721(core.List<api.StringCount> o) { |
| 88 unittest.expect(o, unittest.hasLength(2)); | 88 unittest.expect(o, unittest.hasLength(2)); |
| 89 checkStringCount(o[0]); | 89 checkStringCount(o[0]); |
| 90 checkStringCount(o[1]); | 90 checkStringCount(o[1]); |
| 91 } | 91 } |
| 92 | 92 |
| 93 buildUnnamed715() { | 93 buildUnnamed722() { |
| 94 var o = new core.List<api.StringCount>(); | 94 var o = new core.List<api.StringCount>(); |
| 95 o.add(buildStringCount()); | 95 o.add(buildStringCount()); |
| 96 o.add(buildStringCount()); | 96 o.add(buildStringCount()); |
| 97 return o; | 97 return o; |
| 98 } | 98 } |
| 99 | 99 |
| 100 checkUnnamed715(core.List<api.StringCount> o) { | 100 checkUnnamed722(core.List<api.StringCount> o) { |
| 101 unittest.expect(o, unittest.hasLength(2)); | 101 unittest.expect(o, unittest.hasLength(2)); |
| 102 checkStringCount(o[0]); | 102 checkStringCount(o[0]); |
| 103 checkStringCount(o[1]); | 103 checkStringCount(o[1]); |
| 104 } | 104 } |
| 105 | 105 |
| 106 core.int buildCounterAnalyticsSnapshot = 0; | 106 core.int buildCounterAnalyticsSnapshot = 0; |
| 107 buildAnalyticsSnapshot() { | 107 buildAnalyticsSnapshot() { |
| 108 var o = new api.AnalyticsSnapshot(); | 108 var o = new api.AnalyticsSnapshot(); |
| 109 buildCounterAnalyticsSnapshot++; | 109 buildCounterAnalyticsSnapshot++; |
| 110 if (buildCounterAnalyticsSnapshot < 3) { | 110 if (buildCounterAnalyticsSnapshot < 3) { |
| 111 o.browsers = buildUnnamed712(); | 111 o.browsers = buildUnnamed719(); |
| 112 o.countries = buildUnnamed713(); | 112 o.countries = buildUnnamed720(); |
| 113 o.longUrlClicks = "foo"; | 113 o.longUrlClicks = "foo"; |
| 114 o.platforms = buildUnnamed714(); | 114 o.platforms = buildUnnamed721(); |
| 115 o.referrers = buildUnnamed715(); | 115 o.referrers = buildUnnamed722(); |
| 116 o.shortUrlClicks = "foo"; | 116 o.shortUrlClicks = "foo"; |
| 117 } | 117 } |
| 118 buildCounterAnalyticsSnapshot--; | 118 buildCounterAnalyticsSnapshot--; |
| 119 return o; | 119 return o; |
| 120 } | 120 } |
| 121 | 121 |
| 122 checkAnalyticsSnapshot(api.AnalyticsSnapshot o) { | 122 checkAnalyticsSnapshot(api.AnalyticsSnapshot o) { |
| 123 buildCounterAnalyticsSnapshot++; | 123 buildCounterAnalyticsSnapshot++; |
| 124 if (buildCounterAnalyticsSnapshot < 3) { | 124 if (buildCounterAnalyticsSnapshot < 3) { |
| 125 checkUnnamed712(o.browsers); | 125 checkUnnamed719(o.browsers); |
| 126 checkUnnamed713(o.countries); | 126 checkUnnamed720(o.countries); |
| 127 unittest.expect(o.longUrlClicks, unittest.equals('foo')); | 127 unittest.expect(o.longUrlClicks, unittest.equals('foo')); |
| 128 checkUnnamed714(o.platforms); | 128 checkUnnamed721(o.platforms); |
| 129 checkUnnamed715(o.referrers); | 129 checkUnnamed722(o.referrers); |
| 130 unittest.expect(o.shortUrlClicks, unittest.equals('foo')); | 130 unittest.expect(o.shortUrlClicks, unittest.equals('foo')); |
| 131 } | 131 } |
| 132 buildCounterAnalyticsSnapshot--; | 132 buildCounterAnalyticsSnapshot--; |
| 133 } | 133 } |
| 134 | 134 |
| 135 core.int buildCounterAnalyticsSummary = 0; | 135 core.int buildCounterAnalyticsSummary = 0; |
| 136 buildAnalyticsSummary() { | 136 buildAnalyticsSummary() { |
| 137 var o = new api.AnalyticsSummary(); | 137 var o = new api.AnalyticsSummary(); |
| 138 buildCounterAnalyticsSummary++; | 138 buildCounterAnalyticsSummary++; |
| 139 if (buildCounterAnalyticsSummary < 3) { | 139 if (buildCounterAnalyticsSummary < 3) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 checkAnalyticsSummary(o.analytics); | 202 checkAnalyticsSummary(o.analytics); |
| 203 unittest.expect(o.created, unittest.equals('foo')); | 203 unittest.expect(o.created, unittest.equals('foo')); |
| 204 unittest.expect(o.id, unittest.equals('foo')); | 204 unittest.expect(o.id, unittest.equals('foo')); |
| 205 unittest.expect(o.kind, unittest.equals('foo')); | 205 unittest.expect(o.kind, unittest.equals('foo')); |
| 206 unittest.expect(o.longUrl, unittest.equals('foo')); | 206 unittest.expect(o.longUrl, unittest.equals('foo')); |
| 207 unittest.expect(o.status, unittest.equals('foo')); | 207 unittest.expect(o.status, unittest.equals('foo')); |
| 208 } | 208 } |
| 209 buildCounterUrl--; | 209 buildCounterUrl--; |
| 210 } | 210 } |
| 211 | 211 |
| 212 buildUnnamed716() { | 212 buildUnnamed723() { |
| 213 var o = new core.List<api.Url>(); | 213 var o = new core.List<api.Url>(); |
| 214 o.add(buildUrl()); | 214 o.add(buildUrl()); |
| 215 o.add(buildUrl()); | 215 o.add(buildUrl()); |
| 216 return o; | 216 return o; |
| 217 } | 217 } |
| 218 | 218 |
| 219 checkUnnamed716(core.List<api.Url> o) { | 219 checkUnnamed723(core.List<api.Url> o) { |
| 220 unittest.expect(o, unittest.hasLength(2)); | 220 unittest.expect(o, unittest.hasLength(2)); |
| 221 checkUrl(o[0]); | 221 checkUrl(o[0]); |
| 222 checkUrl(o[1]); | 222 checkUrl(o[1]); |
| 223 } | 223 } |
| 224 | 224 |
| 225 core.int buildCounterUrlHistory = 0; | 225 core.int buildCounterUrlHistory = 0; |
| 226 buildUrlHistory() { | 226 buildUrlHistory() { |
| 227 var o = new api.UrlHistory(); | 227 var o = new api.UrlHistory(); |
| 228 buildCounterUrlHistory++; | 228 buildCounterUrlHistory++; |
| 229 if (buildCounterUrlHistory < 3) { | 229 if (buildCounterUrlHistory < 3) { |
| 230 o.items = buildUnnamed716(); | 230 o.items = buildUnnamed723(); |
| 231 o.itemsPerPage = 42; | 231 o.itemsPerPage = 42; |
| 232 o.kind = "foo"; | 232 o.kind = "foo"; |
| 233 o.nextPageToken = "foo"; | 233 o.nextPageToken = "foo"; |
| 234 o.totalItems = 42; | 234 o.totalItems = 42; |
| 235 } | 235 } |
| 236 buildCounterUrlHistory--; | 236 buildCounterUrlHistory--; |
| 237 return o; | 237 return o; |
| 238 } | 238 } |
| 239 | 239 |
| 240 checkUrlHistory(api.UrlHistory o) { | 240 checkUrlHistory(api.UrlHistory o) { |
| 241 buildCounterUrlHistory++; | 241 buildCounterUrlHistory++; |
| 242 if (buildCounterUrlHistory < 3) { | 242 if (buildCounterUrlHistory < 3) { |
| 243 checkUnnamed716(o.items); | 243 checkUnnamed723(o.items); |
| 244 unittest.expect(o.itemsPerPage, unittest.equals(42)); | 244 unittest.expect(o.itemsPerPage, unittest.equals(42)); |
| 245 unittest.expect(o.kind, unittest.equals('foo')); | 245 unittest.expect(o.kind, unittest.equals('foo')); |
| 246 unittest.expect(o.nextPageToken, unittest.equals('foo')); | 246 unittest.expect(o.nextPageToken, unittest.equals('foo')); |
| 247 unittest.expect(o.totalItems, unittest.equals(42)); | 247 unittest.expect(o.totalItems, unittest.equals(42)); |
| 248 } | 248 } |
| 249 buildCounterUrlHistory--; | 249 buildCounterUrlHistory--; |
| 250 } | 250 } |
| 251 | 251 |
| 252 | 252 |
| 253 main() { | 253 main() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 }); | 296 }); |
| 297 | 297 |
| 298 | 298 |
| 299 unittest.group("resource-UrlResourceApi", () { | 299 unittest.group("resource-UrlResourceApi", () { |
| 300 unittest.test("method--get", () { | 300 unittest.test("method--get", () { |
| 301 | 301 |
| 302 var mock = new HttpServerMock(); | 302 var mock = new HttpServerMock(); |
| 303 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; | 303 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; |
| 304 var arg_shortUrl = "foo"; | 304 var arg_shortUrl = "foo"; |
| 305 var arg_projection = "foo"; | 305 var arg_projection = "foo"; |
| 306 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 306 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 307 var path = (req.url).path; | 307 var path = (req.url).path; |
| 308 var pathOffset = 0; | 308 var pathOffset = 0; |
| 309 var index; | 309 var index; |
| 310 var subPart; | 310 var subPart; |
| 311 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 311 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 312 pathOffset += 1; | 312 pathOffset += 1; |
| 313 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("urlshortener/v1/")); | 313 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("urlshortener/v1/")); |
| 314 pathOffset += 16; | 314 pathOffset += 16; |
| 315 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("url")); | 315 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("url")); |
| 316 pathOffset += 3; | 316 pathOffset += 3; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 334 unittest.expect(queryMap["shortUrl"].first, unittest.equals(arg_shortUrl
)); | 334 unittest.expect(queryMap["shortUrl"].first, unittest.equals(arg_shortUrl
)); |
| 335 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); | 335 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); |
| 336 | 336 |
| 337 | 337 |
| 338 var h = { | 338 var h = { |
| 339 "content-type" : "application/json; charset=utf-8", | 339 "content-type" : "application/json; charset=utf-8", |
| 340 }; | 340 }; |
| 341 var resp = convert.JSON.encode(buildUrl()); | 341 var resp = convert.JSON.encode(buildUrl()); |
| 342 return new async.Future.value(stringResponse(200, h, resp)); | 342 return new async.Future.value(stringResponse(200, h, resp)); |
| 343 }), true); | 343 }), true); |
| 344 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
c1(((api.Url response) { |
| 345 checkUrl(response); | 345 checkUrl(response); |
| 346 }))); | 346 }))); |
| 347 }); | 347 }); |
| 348 | 348 |
| 349 unittest.test("method--insert", () { | 349 unittest.test("method--insert", () { |
| 350 | 350 |
| 351 var mock = new HttpServerMock(); | 351 var mock = new HttpServerMock(); |
| 352 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; | 352 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; |
| 353 var arg_request = buildUrl(); | 353 var arg_request = buildUrl(); |
| 354 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 354 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 355 var obj = new api.Url.fromJson(json); | 355 var obj = new api.Url.fromJson(json); |
| 356 checkUrl(obj); | 356 checkUrl(obj); |
| 357 | 357 |
| 358 var path = (req.url).path; | 358 var path = (req.url).path; |
| 359 var pathOffset = 0; | 359 var pathOffset = 0; |
| 360 var index; | 360 var index; |
| 361 var subPart; | 361 var subPart; |
| 362 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 362 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 363 pathOffset += 1; | 363 pathOffset += 1; |
| 364 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("urlshortener/v1/")); | 364 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("urlshortener/v1/")); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 | 386 |
| 387 var h = { | 387 var h = { |
| 388 "content-type" : "application/json; charset=utf-8", | 388 "content-type" : "application/json; charset=utf-8", |
| 389 }; | 389 }; |
| 390 var resp = convert.JSON.encode(buildUrl()); | 390 var resp = convert.JSON.encode(buildUrl()); |
| 391 return new async.Future.value(stringResponse(200, h, resp)); | 391 return new async.Future.value(stringResponse(200, h, resp)); |
| 392 }), true); | 392 }), true); |
| 393 res.insert(arg_request).then(unittest.expectAsync(((api.Url response) { | 393 res.insert(arg_request).then(unittest.expectAsync1(((api.Url response) { |
| 394 checkUrl(response); | 394 checkUrl(response); |
| 395 }))); | 395 }))); |
| 396 }); | 396 }); |
| 397 | 397 |
| 398 unittest.test("method--list", () { | 398 unittest.test("method--list", () { |
| 399 | 399 |
| 400 var mock = new HttpServerMock(); | 400 var mock = new HttpServerMock(); |
| 401 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; | 401 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; |
| 402 var arg_projection = "foo"; | 402 var arg_projection = "foo"; |
| 403 var arg_start_token = "foo"; | 403 var arg_start_token = "foo"; |
| 404 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 404 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 405 var path = (req.url).path; | 405 var path = (req.url).path; |
| 406 var pathOffset = 0; | 406 var pathOffset = 0; |
| 407 var index; | 407 var index; |
| 408 var subPart; | 408 var subPart; |
| 409 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 409 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 410 pathOffset += 1; | 410 pathOffset += 1; |
| 411 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("urlshortener/v1/")); | 411 unittest.expect(path.substring(pathOffset, pathOffset + 16), unittest.eq
uals("urlshortener/v1/")); |
| 412 pathOffset += 16; | 412 pathOffset += 16; |
| 413 unittest.expect(path.substring(pathOffset, pathOffset + 11), unittest.eq
uals("url/history")); | 413 unittest.expect(path.substring(pathOffset, pathOffset + 11), unittest.eq
uals("url/history")); |
| 414 pathOffset += 11; | 414 pathOffset += 11; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 432 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); | 432 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); |
| 433 unittest.expect(queryMap["start-token"].first, unittest.equals(arg_start
_token)); | 433 unittest.expect(queryMap["start-token"].first, unittest.equals(arg_start
_token)); |
| 434 | 434 |
| 435 | 435 |
| 436 var h = { | 436 var h = { |
| 437 "content-type" : "application/json; charset=utf-8", | 437 "content-type" : "application/json; charset=utf-8", |
| 438 }; | 438 }; |
| 439 var resp = convert.JSON.encode(buildUrlHistory()); | 439 var resp = convert.JSON.encode(buildUrlHistory()); |
| 440 return new async.Future.value(stringResponse(200, h, resp)); | 440 return new async.Future.value(stringResponse(200, h, resp)); |
| 441 }), true); | 441 }), true); |
| 442 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.expectAsync1(((api.UrlHistory response) { |
| 443 checkUrlHistory(response); | 443 checkUrlHistory(response); |
| 444 }))); | 444 }))); |
| 445 }); | 445 }); |
| 446 | 446 |
| 447 }); | 447 }); |
| 448 | 448 |
| 449 | 449 |
| 450 } | 450 } |
| 451 | 451 |
| OLD | NEW |