| OLD | NEW |
| (Empty) |
| 1 library googleapis.urlshortener.v1.test; | |
| 2 | |
| 3 import "dart:core" as core; | |
| 4 import "dart:collection" as collection; | |
| 5 import "dart:async" as async; | |
| 6 import "dart:convert" as convert; | |
| 7 | |
| 8 import 'package:http/http.dart' as http; | |
| 9 import 'package:http/testing.dart' as http_testing; | |
| 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 | |
| 15 import 'package:googleapis/urlshortener/v1.dart' as api; | |
| 16 | |
| 17 | |
| 18 | |
| 19 buildUnnamed440() { | |
| 20 var o = new core.List<api.StringCount>(); | |
| 21 o.add(buildStringCount()); | |
| 22 o.add(buildStringCount()); | |
| 23 return o; | |
| 24 } | |
| 25 | |
| 26 checkUnnamed440(core.List<api.StringCount> o) { | |
| 27 unittest.expect(o, unittest.hasLength(2)); | |
| 28 checkStringCount(o[0]); | |
| 29 checkStringCount(o[1]); | |
| 30 } | |
| 31 | |
| 32 buildUnnamed441() { | |
| 33 var o = new core.List<api.StringCount>(); | |
| 34 o.add(buildStringCount()); | |
| 35 o.add(buildStringCount()); | |
| 36 return o; | |
| 37 } | |
| 38 | |
| 39 checkUnnamed441(core.List<api.StringCount> o) { | |
| 40 unittest.expect(o, unittest.hasLength(2)); | |
| 41 checkStringCount(o[0]); | |
| 42 checkStringCount(o[1]); | |
| 43 } | |
| 44 | |
| 45 buildUnnamed442() { | |
| 46 var o = new core.List<api.StringCount>(); | |
| 47 o.add(buildStringCount()); | |
| 48 o.add(buildStringCount()); | |
| 49 return o; | |
| 50 } | |
| 51 | |
| 52 checkUnnamed442(core.List<api.StringCount> o) { | |
| 53 unittest.expect(o, unittest.hasLength(2)); | |
| 54 checkStringCount(o[0]); | |
| 55 checkStringCount(o[1]); | |
| 56 } | |
| 57 | |
| 58 buildUnnamed443() { | |
| 59 var o = new core.List<api.StringCount>(); | |
| 60 o.add(buildStringCount()); | |
| 61 o.add(buildStringCount()); | |
| 62 return o; | |
| 63 } | |
| 64 | |
| 65 checkUnnamed443(core.List<api.StringCount> o) { | |
| 66 unittest.expect(o, unittest.hasLength(2)); | |
| 67 checkStringCount(o[0]); | |
| 68 checkStringCount(o[1]); | |
| 69 } | |
| 70 | |
| 71 core.int buildCounterAnalyticsSnapshot = 0; | |
| 72 buildAnalyticsSnapshot() { | |
| 73 var o = new api.AnalyticsSnapshot(); | |
| 74 buildCounterAnalyticsSnapshot++; | |
| 75 if (buildCounterAnalyticsSnapshot < 3) { | |
| 76 o.browsers = buildUnnamed440(); | |
| 77 o.countries = buildUnnamed441(); | |
| 78 o.longUrlClicks = "foo"; | |
| 79 o.platforms = buildUnnamed442(); | |
| 80 o.referrers = buildUnnamed443(); | |
| 81 o.shortUrlClicks = "foo"; | |
| 82 } | |
| 83 buildCounterAnalyticsSnapshot--; | |
| 84 return o; | |
| 85 } | |
| 86 | |
| 87 checkAnalyticsSnapshot(api.AnalyticsSnapshot o) { | |
| 88 buildCounterAnalyticsSnapshot++; | |
| 89 if (buildCounterAnalyticsSnapshot < 3) { | |
| 90 checkUnnamed440(o.browsers); | |
| 91 checkUnnamed441(o.countries); | |
| 92 unittest.expect(o.longUrlClicks, unittest.equals('foo')); | |
| 93 checkUnnamed442(o.platforms); | |
| 94 checkUnnamed443(o.referrers); | |
| 95 unittest.expect(o.shortUrlClicks, unittest.equals('foo')); | |
| 96 } | |
| 97 buildCounterAnalyticsSnapshot--; | |
| 98 } | |
| 99 | |
| 100 core.int buildCounterAnalyticsSummary = 0; | |
| 101 buildAnalyticsSummary() { | |
| 102 var o = new api.AnalyticsSummary(); | |
| 103 buildCounterAnalyticsSummary++; | |
| 104 if (buildCounterAnalyticsSummary < 3) { | |
| 105 o.allTime = buildAnalyticsSnapshot(); | |
| 106 o.day = buildAnalyticsSnapshot(); | |
| 107 o.month = buildAnalyticsSnapshot(); | |
| 108 o.twoHours = buildAnalyticsSnapshot(); | |
| 109 o.week = buildAnalyticsSnapshot(); | |
| 110 } | |
| 111 buildCounterAnalyticsSummary--; | |
| 112 return o; | |
| 113 } | |
| 114 | |
| 115 checkAnalyticsSummary(api.AnalyticsSummary o) { | |
| 116 buildCounterAnalyticsSummary++; | |
| 117 if (buildCounterAnalyticsSummary < 3) { | |
| 118 checkAnalyticsSnapshot(o.allTime); | |
| 119 checkAnalyticsSnapshot(o.day); | |
| 120 checkAnalyticsSnapshot(o.month); | |
| 121 checkAnalyticsSnapshot(o.twoHours); | |
| 122 checkAnalyticsSnapshot(o.week); | |
| 123 } | |
| 124 buildCounterAnalyticsSummary--; | |
| 125 } | |
| 126 | |
| 127 core.int buildCounterStringCount = 0; | |
| 128 buildStringCount() { | |
| 129 var o = new api.StringCount(); | |
| 130 buildCounterStringCount++; | |
| 131 if (buildCounterStringCount < 3) { | |
| 132 o.count = "foo"; | |
| 133 o.id = "foo"; | |
| 134 } | |
| 135 buildCounterStringCount--; | |
| 136 return o; | |
| 137 } | |
| 138 | |
| 139 checkStringCount(api.StringCount o) { | |
| 140 buildCounterStringCount++; | |
| 141 if (buildCounterStringCount < 3) { | |
| 142 unittest.expect(o.count, unittest.equals('foo')); | |
| 143 unittest.expect(o.id, unittest.equals('foo')); | |
| 144 } | |
| 145 buildCounterStringCount--; | |
| 146 } | |
| 147 | |
| 148 core.int buildCounterUrl = 0; | |
| 149 buildUrl() { | |
| 150 var o = new api.Url(); | |
| 151 buildCounterUrl++; | |
| 152 if (buildCounterUrl < 3) { | |
| 153 o.analytics = buildAnalyticsSummary(); | |
| 154 o.created = "foo"; | |
| 155 o.id = "foo"; | |
| 156 o.kind = "foo"; | |
| 157 o.longUrl = "foo"; | |
| 158 o.status = "foo"; | |
| 159 } | |
| 160 buildCounterUrl--; | |
| 161 return o; | |
| 162 } | |
| 163 | |
| 164 checkUrl(api.Url o) { | |
| 165 buildCounterUrl++; | |
| 166 if (buildCounterUrl < 3) { | |
| 167 checkAnalyticsSummary(o.analytics); | |
| 168 unittest.expect(o.created, unittest.equals('foo')); | |
| 169 unittest.expect(o.id, unittest.equals('foo')); | |
| 170 unittest.expect(o.kind, unittest.equals('foo')); | |
| 171 unittest.expect(o.longUrl, unittest.equals('foo')); | |
| 172 unittest.expect(o.status, unittest.equals('foo')); | |
| 173 } | |
| 174 buildCounterUrl--; | |
| 175 } | |
| 176 | |
| 177 buildUnnamed444() { | |
| 178 var o = new core.List<api.Url>(); | |
| 179 o.add(buildUrl()); | |
| 180 o.add(buildUrl()); | |
| 181 return o; | |
| 182 } | |
| 183 | |
| 184 checkUnnamed444(core.List<api.Url> o) { | |
| 185 unittest.expect(o, unittest.hasLength(2)); | |
| 186 checkUrl(o[0]); | |
| 187 checkUrl(o[1]); | |
| 188 } | |
| 189 | |
| 190 core.int buildCounterUrlHistory = 0; | |
| 191 buildUrlHistory() { | |
| 192 var o = new api.UrlHistory(); | |
| 193 buildCounterUrlHistory++; | |
| 194 if (buildCounterUrlHistory < 3) { | |
| 195 o.items = buildUnnamed444(); | |
| 196 o.itemsPerPage = 42; | |
| 197 o.kind = "foo"; | |
| 198 o.nextPageToken = "foo"; | |
| 199 o.totalItems = 42; | |
| 200 } | |
| 201 buildCounterUrlHistory--; | |
| 202 return o; | |
| 203 } | |
| 204 | |
| 205 checkUrlHistory(api.UrlHistory o) { | |
| 206 buildCounterUrlHistory++; | |
| 207 if (buildCounterUrlHistory < 3) { | |
| 208 checkUnnamed444(o.items); | |
| 209 unittest.expect(o.itemsPerPage, unittest.equals(42)); | |
| 210 unittest.expect(o.kind, unittest.equals('foo')); | |
| 211 unittest.expect(o.nextPageToken, unittest.equals('foo')); | |
| 212 unittest.expect(o.totalItems, unittest.equals(42)); | |
| 213 } | |
| 214 buildCounterUrlHistory--; | |
| 215 } | |
| 216 | |
| 217 | |
| 218 main() { | |
| 219 unittest.group("obj-schema-AnalyticsSnapshot", () { | |
| 220 unittest.test("to-json--from-json", () { | |
| 221 var o = buildAnalyticsSnapshot(); | |
| 222 var od = new api.AnalyticsSnapshot.fromJson(o.toJson()); | |
| 223 checkAnalyticsSnapshot(od); | |
| 224 }); | |
| 225 }); | |
| 226 | |
| 227 | |
| 228 unittest.group("obj-schema-AnalyticsSummary", () { | |
| 229 unittest.test("to-json--from-json", () { | |
| 230 var o = buildAnalyticsSummary(); | |
| 231 var od = new api.AnalyticsSummary.fromJson(o.toJson()); | |
| 232 checkAnalyticsSummary(od); | |
| 233 }); | |
| 234 }); | |
| 235 | |
| 236 | |
| 237 unittest.group("obj-schema-StringCount", () { | |
| 238 unittest.test("to-json--from-json", () { | |
| 239 var o = buildStringCount(); | |
| 240 var od = new api.StringCount.fromJson(o.toJson()); | |
| 241 checkStringCount(od); | |
| 242 }); | |
| 243 }); | |
| 244 | |
| 245 | |
| 246 unittest.group("obj-schema-Url", () { | |
| 247 unittest.test("to-json--from-json", () { | |
| 248 var o = buildUrl(); | |
| 249 var od = new api.Url.fromJson(o.toJson()); | |
| 250 checkUrl(od); | |
| 251 }); | |
| 252 }); | |
| 253 | |
| 254 | |
| 255 unittest.group("obj-schema-UrlHistory", () { | |
| 256 unittest.test("to-json--from-json", () { | |
| 257 var o = buildUrlHistory(); | |
| 258 var od = new api.UrlHistory.fromJson(o.toJson()); | |
| 259 checkUrlHistory(od); | |
| 260 }); | |
| 261 }); | |
| 262 | |
| 263 | |
| 264 unittest.group("resource-UrlResourceApi", () { | |
| 265 unittest.test("method--get", () { | |
| 266 | |
| 267 var mock = new common_test.HttpServerMock(); | |
| 268 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; | |
| 269 var arg_shortUrl = "foo"; | |
| 270 var arg_projection = "foo"; | |
| 271 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
| 272 var path = (req.url).path; | |
| 273 var pathOffset = 0; | |
| 274 var index; | |
| 275 var subPart; | |
| 276 unittest.expect(path.substring(pathOffset, pathOffset + 17), unittest.eq
uals("/urlshortener/v1/")); | |
| 277 pathOffset += 17; | |
| 278 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("url")); | |
| 279 pathOffset += 3; | |
| 280 | |
| 281 var query = (req.url).query; | |
| 282 var queryOffset = 0; | |
| 283 var queryMap = {}; | |
| 284 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
| 285 parseBool(n) { | |
| 286 if (n == "true") return true; | |
| 287 if (n == "false") return false; | |
| 288 if (n == null) return null; | |
| 289 throw new core.ArgumentError("Invalid boolean: $n"); | |
| 290 } | |
| 291 if (query.length > 0) { | |
| 292 for (var part in query.split("&")) { | |
| 293 var keyvalue = part.split("="); | |
| 294 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
| 295 } | |
| 296 } | |
| 297 unittest.expect(queryMap["shortUrl"].first, unittest.equals(arg_shortUrl
)); | |
| 298 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); | |
| 299 | |
| 300 | |
| 301 var h = { | |
| 302 "content-type" : "application/json; charset=utf-8", | |
| 303 }; | |
| 304 var resp = convert.JSON.encode(buildUrl()); | |
| 305 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
| 306 }), true); | |
| 307 res.get(arg_shortUrl, projection: arg_projection).then(unittest.expectAsyn
c(((api.Url response) { | |
| 308 checkUrl(response); | |
| 309 }))); | |
| 310 }); | |
| 311 | |
| 312 unittest.test("method--insert", () { | |
| 313 | |
| 314 var mock = new common_test.HttpServerMock(); | |
| 315 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; | |
| 316 var arg_request = buildUrl(); | |
| 317 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
| 318 var obj = new api.Url.fromJson(json); | |
| 319 checkUrl(obj); | |
| 320 | |
| 321 var path = (req.url).path; | |
| 322 var pathOffset = 0; | |
| 323 var index; | |
| 324 var subPart; | |
| 325 unittest.expect(path.substring(pathOffset, pathOffset + 17), unittest.eq
uals("/urlshortener/v1/")); | |
| 326 pathOffset += 17; | |
| 327 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("url")); | |
| 328 pathOffset += 3; | |
| 329 | |
| 330 var query = (req.url).query; | |
| 331 var queryOffset = 0; | |
| 332 var queryMap = {}; | |
| 333 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
| 334 parseBool(n) { | |
| 335 if (n == "true") return true; | |
| 336 if (n == "false") return false; | |
| 337 if (n == null) return null; | |
| 338 throw new core.ArgumentError("Invalid boolean: $n"); | |
| 339 } | |
| 340 if (query.length > 0) { | |
| 341 for (var part in query.split("&")) { | |
| 342 var keyvalue = part.split("="); | |
| 343 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
| 344 } | |
| 345 } | |
| 346 | |
| 347 | |
| 348 var h = { | |
| 349 "content-type" : "application/json; charset=utf-8", | |
| 350 }; | |
| 351 var resp = convert.JSON.encode(buildUrl()); | |
| 352 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
| 353 }), true); | |
| 354 res.insert(arg_request).then(unittest.expectAsync(((api.Url response) { | |
| 355 checkUrl(response); | |
| 356 }))); | |
| 357 }); | |
| 358 | |
| 359 unittest.test("method--list", () { | |
| 360 | |
| 361 var mock = new common_test.HttpServerMock(); | |
| 362 api.UrlResourceApi res = new api.UrlshortenerApi(mock).url; | |
| 363 var arg_projection = "foo"; | |
| 364 var arg_start_token = "foo"; | |
| 365 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
| 366 var path = (req.url).path; | |
| 367 var pathOffset = 0; | |
| 368 var index; | |
| 369 var subPart; | |
| 370 unittest.expect(path.substring(pathOffset, pathOffset + 17), unittest.eq
uals("/urlshortener/v1/")); | |
| 371 pathOffset += 17; | |
| 372 unittest.expect(path.substring(pathOffset, pathOffset + 11), unittest.eq
uals("url/history")); | |
| 373 pathOffset += 11; | |
| 374 | |
| 375 var query = (req.url).query; | |
| 376 var queryOffset = 0; | |
| 377 var queryMap = {}; | |
| 378 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
| 379 parseBool(n) { | |
| 380 if (n == "true") return true; | |
| 381 if (n == "false") return false; | |
| 382 if (n == null) return null; | |
| 383 throw new core.ArgumentError("Invalid boolean: $n"); | |
| 384 } | |
| 385 if (query.length > 0) { | |
| 386 for (var part in query.split("&")) { | |
| 387 var keyvalue = part.split("="); | |
| 388 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
| 389 } | |
| 390 } | |
| 391 unittest.expect(queryMap["projection"].first, unittest.equals(arg_projec
tion)); | |
| 392 unittest.expect(queryMap["start-token"].first, unittest.equals(arg_start
_token)); | |
| 393 | |
| 394 | |
| 395 var h = { | |
| 396 "content-type" : "application/json; charset=utf-8", | |
| 397 }; | |
| 398 var resp = convert.JSON.encode(buildUrlHistory()); | |
| 399 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
| 400 }), true); | |
| 401 res.list(projection: arg_projection, start_token: arg_start_token).then(un
ittest.expectAsync(((api.UrlHistory response) { | |
| 402 checkUrlHistory(response); | |
| 403 }))); | |
| 404 }); | |
| 405 | |
| 406 }); | |
| 407 | |
| 408 | |
| 409 } | |
| 410 | |
| OLD | NEW |