OLD | NEW |
(Empty) | |
| 1 library googleapis.firebasedynamiclinks.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 |
| 12 import 'package:googleapis/firebasedynamiclinks/v1.dart' as api; |
| 13 |
| 14 class HttpServerMock extends http.BaseClient { |
| 15 core.Function _callback; |
| 16 core.bool _expectJson; |
| 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 } |
| 53 |
| 54 core.int buildCounterAnalyticsInfo = 0; |
| 55 buildAnalyticsInfo() { |
| 56 var o = new api.AnalyticsInfo(); |
| 57 buildCounterAnalyticsInfo++; |
| 58 if (buildCounterAnalyticsInfo < 3) { |
| 59 o.googlePlayAnalytics = buildGooglePlayAnalytics(); |
| 60 o.itunesConnectAnalytics = buildITunesConnectAnalytics(); |
| 61 } |
| 62 buildCounterAnalyticsInfo--; |
| 63 return o; |
| 64 } |
| 65 |
| 66 checkAnalyticsInfo(api.AnalyticsInfo o) { |
| 67 buildCounterAnalyticsInfo++; |
| 68 if (buildCounterAnalyticsInfo < 3) { |
| 69 checkGooglePlayAnalytics(o.googlePlayAnalytics); |
| 70 checkITunesConnectAnalytics(o.itunesConnectAnalytics); |
| 71 } |
| 72 buildCounterAnalyticsInfo--; |
| 73 } |
| 74 |
| 75 core.int buildCounterAndroidInfo = 0; |
| 76 buildAndroidInfo() { |
| 77 var o = new api.AndroidInfo(); |
| 78 buildCounterAndroidInfo++; |
| 79 if (buildCounterAndroidInfo < 3) { |
| 80 o.androidFallbackLink = "foo"; |
| 81 o.androidLink = "foo"; |
| 82 o.androidMinPackageVersionCode = "foo"; |
| 83 o.androidPackageName = "foo"; |
| 84 } |
| 85 buildCounterAndroidInfo--; |
| 86 return o; |
| 87 } |
| 88 |
| 89 checkAndroidInfo(api.AndroidInfo o) { |
| 90 buildCounterAndroidInfo++; |
| 91 if (buildCounterAndroidInfo < 3) { |
| 92 unittest.expect(o.androidFallbackLink, unittest.equals('foo')); |
| 93 unittest.expect(o.androidLink, unittest.equals('foo')); |
| 94 unittest.expect(o.androidMinPackageVersionCode, unittest.equals('foo')); |
| 95 unittest.expect(o.androidPackageName, unittest.equals('foo')); |
| 96 } |
| 97 buildCounterAndroidInfo--; |
| 98 } |
| 99 |
| 100 core.int buildCounterCreateShortDynamicLinkRequest = 0; |
| 101 buildCreateShortDynamicLinkRequest() { |
| 102 var o = new api.CreateShortDynamicLinkRequest(); |
| 103 buildCounterCreateShortDynamicLinkRequest++; |
| 104 if (buildCounterCreateShortDynamicLinkRequest < 3) { |
| 105 o.dynamicLinkInfo = buildDynamicLinkInfo(); |
| 106 o.longDynamicLink = "foo"; |
| 107 o.suffix = buildSuffix(); |
| 108 } |
| 109 buildCounterCreateShortDynamicLinkRequest--; |
| 110 return o; |
| 111 } |
| 112 |
| 113 checkCreateShortDynamicLinkRequest(api.CreateShortDynamicLinkRequest o) { |
| 114 buildCounterCreateShortDynamicLinkRequest++; |
| 115 if (buildCounterCreateShortDynamicLinkRequest < 3) { |
| 116 checkDynamicLinkInfo(o.dynamicLinkInfo); |
| 117 unittest.expect(o.longDynamicLink, unittest.equals('foo')); |
| 118 checkSuffix(o.suffix); |
| 119 } |
| 120 buildCounterCreateShortDynamicLinkRequest--; |
| 121 } |
| 122 |
| 123 buildUnnamed2171() { |
| 124 var o = new core.List<api.DynamicLinkWarning>(); |
| 125 o.add(buildDynamicLinkWarning()); |
| 126 o.add(buildDynamicLinkWarning()); |
| 127 return o; |
| 128 } |
| 129 |
| 130 checkUnnamed2171(core.List<api.DynamicLinkWarning> o) { |
| 131 unittest.expect(o, unittest.hasLength(2)); |
| 132 checkDynamicLinkWarning(o[0]); |
| 133 checkDynamicLinkWarning(o[1]); |
| 134 } |
| 135 |
| 136 core.int buildCounterCreateShortDynamicLinkResponse = 0; |
| 137 buildCreateShortDynamicLinkResponse() { |
| 138 var o = new api.CreateShortDynamicLinkResponse(); |
| 139 buildCounterCreateShortDynamicLinkResponse++; |
| 140 if (buildCounterCreateShortDynamicLinkResponse < 3) { |
| 141 o.previewLink = "foo"; |
| 142 o.shortLink = "foo"; |
| 143 o.warning = buildUnnamed2171(); |
| 144 } |
| 145 buildCounterCreateShortDynamicLinkResponse--; |
| 146 return o; |
| 147 } |
| 148 |
| 149 checkCreateShortDynamicLinkResponse(api.CreateShortDynamicLinkResponse o) { |
| 150 buildCounterCreateShortDynamicLinkResponse++; |
| 151 if (buildCounterCreateShortDynamicLinkResponse < 3) { |
| 152 unittest.expect(o.previewLink, unittest.equals('foo')); |
| 153 unittest.expect(o.shortLink, unittest.equals('foo')); |
| 154 checkUnnamed2171(o.warning); |
| 155 } |
| 156 buildCounterCreateShortDynamicLinkResponse--; |
| 157 } |
| 158 |
| 159 core.int buildCounterDynamicLinkInfo = 0; |
| 160 buildDynamicLinkInfo() { |
| 161 var o = new api.DynamicLinkInfo(); |
| 162 buildCounterDynamicLinkInfo++; |
| 163 if (buildCounterDynamicLinkInfo < 3) { |
| 164 o.analyticsInfo = buildAnalyticsInfo(); |
| 165 o.androidInfo = buildAndroidInfo(); |
| 166 o.dynamicLinkDomain = "foo"; |
| 167 o.iosInfo = buildIosInfo(); |
| 168 o.isAd = true; |
| 169 o.link = "foo"; |
| 170 o.socialMetaTagInfo = buildSocialMetaTagInfo(); |
| 171 } |
| 172 buildCounterDynamicLinkInfo--; |
| 173 return o; |
| 174 } |
| 175 |
| 176 checkDynamicLinkInfo(api.DynamicLinkInfo o) { |
| 177 buildCounterDynamicLinkInfo++; |
| 178 if (buildCounterDynamicLinkInfo < 3) { |
| 179 checkAnalyticsInfo(o.analyticsInfo); |
| 180 checkAndroidInfo(o.androidInfo); |
| 181 unittest.expect(o.dynamicLinkDomain, unittest.equals('foo')); |
| 182 checkIosInfo(o.iosInfo); |
| 183 unittest.expect(o.isAd, unittest.isTrue); |
| 184 unittest.expect(o.link, unittest.equals('foo')); |
| 185 checkSocialMetaTagInfo(o.socialMetaTagInfo); |
| 186 } |
| 187 buildCounterDynamicLinkInfo--; |
| 188 } |
| 189 |
| 190 core.int buildCounterDynamicLinkWarning = 0; |
| 191 buildDynamicLinkWarning() { |
| 192 var o = new api.DynamicLinkWarning(); |
| 193 buildCounterDynamicLinkWarning++; |
| 194 if (buildCounterDynamicLinkWarning < 3) { |
| 195 o.warningCode = "foo"; |
| 196 o.warningMessage = "foo"; |
| 197 } |
| 198 buildCounterDynamicLinkWarning--; |
| 199 return o; |
| 200 } |
| 201 |
| 202 checkDynamicLinkWarning(api.DynamicLinkWarning o) { |
| 203 buildCounterDynamicLinkWarning++; |
| 204 if (buildCounterDynamicLinkWarning < 3) { |
| 205 unittest.expect(o.warningCode, unittest.equals('foo')); |
| 206 unittest.expect(o.warningMessage, unittest.equals('foo')); |
| 207 } |
| 208 buildCounterDynamicLinkWarning--; |
| 209 } |
| 210 |
| 211 core.int buildCounterGooglePlayAnalytics = 0; |
| 212 buildGooglePlayAnalytics() { |
| 213 var o = new api.GooglePlayAnalytics(); |
| 214 buildCounterGooglePlayAnalytics++; |
| 215 if (buildCounterGooglePlayAnalytics < 3) { |
| 216 o.gclid = "foo"; |
| 217 o.utmCampaign = "foo"; |
| 218 o.utmContent = "foo"; |
| 219 o.utmMedium = "foo"; |
| 220 o.utmSource = "foo"; |
| 221 o.utmTerm = "foo"; |
| 222 } |
| 223 buildCounterGooglePlayAnalytics--; |
| 224 return o; |
| 225 } |
| 226 |
| 227 checkGooglePlayAnalytics(api.GooglePlayAnalytics o) { |
| 228 buildCounterGooglePlayAnalytics++; |
| 229 if (buildCounterGooglePlayAnalytics < 3) { |
| 230 unittest.expect(o.gclid, unittest.equals('foo')); |
| 231 unittest.expect(o.utmCampaign, unittest.equals('foo')); |
| 232 unittest.expect(o.utmContent, unittest.equals('foo')); |
| 233 unittest.expect(o.utmMedium, unittest.equals('foo')); |
| 234 unittest.expect(o.utmSource, unittest.equals('foo')); |
| 235 unittest.expect(o.utmTerm, unittest.equals('foo')); |
| 236 } |
| 237 buildCounterGooglePlayAnalytics--; |
| 238 } |
| 239 |
| 240 core.int buildCounterITunesConnectAnalytics = 0; |
| 241 buildITunesConnectAnalytics() { |
| 242 var o = new api.ITunesConnectAnalytics(); |
| 243 buildCounterITunesConnectAnalytics++; |
| 244 if (buildCounterITunesConnectAnalytics < 3) { |
| 245 o.at = "foo"; |
| 246 o.ct = "foo"; |
| 247 o.mt = "foo"; |
| 248 o.pt = "foo"; |
| 249 } |
| 250 buildCounterITunesConnectAnalytics--; |
| 251 return o; |
| 252 } |
| 253 |
| 254 checkITunesConnectAnalytics(api.ITunesConnectAnalytics o) { |
| 255 buildCounterITunesConnectAnalytics++; |
| 256 if (buildCounterITunesConnectAnalytics < 3) { |
| 257 unittest.expect(o.at, unittest.equals('foo')); |
| 258 unittest.expect(o.ct, unittest.equals('foo')); |
| 259 unittest.expect(o.mt, unittest.equals('foo')); |
| 260 unittest.expect(o.pt, unittest.equals('foo')); |
| 261 } |
| 262 buildCounterITunesConnectAnalytics--; |
| 263 } |
| 264 |
| 265 core.int buildCounterIosInfo = 0; |
| 266 buildIosInfo() { |
| 267 var o = new api.IosInfo(); |
| 268 buildCounterIosInfo++; |
| 269 if (buildCounterIosInfo < 3) { |
| 270 o.iosAppStoreId = "foo"; |
| 271 o.iosBundleId = "foo"; |
| 272 o.iosCustomScheme = "foo"; |
| 273 o.iosFallbackLink = "foo"; |
| 274 o.iosIpadBundleId = "foo"; |
| 275 o.iosIpadFallbackLink = "foo"; |
| 276 } |
| 277 buildCounterIosInfo--; |
| 278 return o; |
| 279 } |
| 280 |
| 281 checkIosInfo(api.IosInfo o) { |
| 282 buildCounterIosInfo++; |
| 283 if (buildCounterIosInfo < 3) { |
| 284 unittest.expect(o.iosAppStoreId, unittest.equals('foo')); |
| 285 unittest.expect(o.iosBundleId, unittest.equals('foo')); |
| 286 unittest.expect(o.iosCustomScheme, unittest.equals('foo')); |
| 287 unittest.expect(o.iosFallbackLink, unittest.equals('foo')); |
| 288 unittest.expect(o.iosIpadBundleId, unittest.equals('foo')); |
| 289 unittest.expect(o.iosIpadFallbackLink, unittest.equals('foo')); |
| 290 } |
| 291 buildCounterIosInfo--; |
| 292 } |
| 293 |
| 294 core.int buildCounterSocialMetaTagInfo = 0; |
| 295 buildSocialMetaTagInfo() { |
| 296 var o = new api.SocialMetaTagInfo(); |
| 297 buildCounterSocialMetaTagInfo++; |
| 298 if (buildCounterSocialMetaTagInfo < 3) { |
| 299 o.socialDescription = "foo"; |
| 300 o.socialImageLink = "foo"; |
| 301 o.socialTitle = "foo"; |
| 302 } |
| 303 buildCounterSocialMetaTagInfo--; |
| 304 return o; |
| 305 } |
| 306 |
| 307 checkSocialMetaTagInfo(api.SocialMetaTagInfo o) { |
| 308 buildCounterSocialMetaTagInfo++; |
| 309 if (buildCounterSocialMetaTagInfo < 3) { |
| 310 unittest.expect(o.socialDescription, unittest.equals('foo')); |
| 311 unittest.expect(o.socialImageLink, unittest.equals('foo')); |
| 312 unittest.expect(o.socialTitle, unittest.equals('foo')); |
| 313 } |
| 314 buildCounterSocialMetaTagInfo--; |
| 315 } |
| 316 |
| 317 core.int buildCounterSuffix = 0; |
| 318 buildSuffix() { |
| 319 var o = new api.Suffix(); |
| 320 buildCounterSuffix++; |
| 321 if (buildCounterSuffix < 3) { |
| 322 o.option = "foo"; |
| 323 } |
| 324 buildCounterSuffix--; |
| 325 return o; |
| 326 } |
| 327 |
| 328 checkSuffix(api.Suffix o) { |
| 329 buildCounterSuffix++; |
| 330 if (buildCounterSuffix < 3) { |
| 331 unittest.expect(o.option, unittest.equals('foo')); |
| 332 } |
| 333 buildCounterSuffix--; |
| 334 } |
| 335 |
| 336 |
| 337 main() { |
| 338 unittest.group("obj-schema-AnalyticsInfo", () { |
| 339 unittest.test("to-json--from-json", () { |
| 340 var o = buildAnalyticsInfo(); |
| 341 var od = new api.AnalyticsInfo.fromJson(o.toJson()); |
| 342 checkAnalyticsInfo(od); |
| 343 }); |
| 344 }); |
| 345 |
| 346 |
| 347 unittest.group("obj-schema-AndroidInfo", () { |
| 348 unittest.test("to-json--from-json", () { |
| 349 var o = buildAndroidInfo(); |
| 350 var od = new api.AndroidInfo.fromJson(o.toJson()); |
| 351 checkAndroidInfo(od); |
| 352 }); |
| 353 }); |
| 354 |
| 355 |
| 356 unittest.group("obj-schema-CreateShortDynamicLinkRequest", () { |
| 357 unittest.test("to-json--from-json", () { |
| 358 var o = buildCreateShortDynamicLinkRequest(); |
| 359 var od = new api.CreateShortDynamicLinkRequest.fromJson(o.toJson()); |
| 360 checkCreateShortDynamicLinkRequest(od); |
| 361 }); |
| 362 }); |
| 363 |
| 364 |
| 365 unittest.group("obj-schema-CreateShortDynamicLinkResponse", () { |
| 366 unittest.test("to-json--from-json", () { |
| 367 var o = buildCreateShortDynamicLinkResponse(); |
| 368 var od = new api.CreateShortDynamicLinkResponse.fromJson(o.toJson()); |
| 369 checkCreateShortDynamicLinkResponse(od); |
| 370 }); |
| 371 }); |
| 372 |
| 373 |
| 374 unittest.group("obj-schema-DynamicLinkInfo", () { |
| 375 unittest.test("to-json--from-json", () { |
| 376 var o = buildDynamicLinkInfo(); |
| 377 var od = new api.DynamicLinkInfo.fromJson(o.toJson()); |
| 378 checkDynamicLinkInfo(od); |
| 379 }); |
| 380 }); |
| 381 |
| 382 |
| 383 unittest.group("obj-schema-DynamicLinkWarning", () { |
| 384 unittest.test("to-json--from-json", () { |
| 385 var o = buildDynamicLinkWarning(); |
| 386 var od = new api.DynamicLinkWarning.fromJson(o.toJson()); |
| 387 checkDynamicLinkWarning(od); |
| 388 }); |
| 389 }); |
| 390 |
| 391 |
| 392 unittest.group("obj-schema-GooglePlayAnalytics", () { |
| 393 unittest.test("to-json--from-json", () { |
| 394 var o = buildGooglePlayAnalytics(); |
| 395 var od = new api.GooglePlayAnalytics.fromJson(o.toJson()); |
| 396 checkGooglePlayAnalytics(od); |
| 397 }); |
| 398 }); |
| 399 |
| 400 |
| 401 unittest.group("obj-schema-ITunesConnectAnalytics", () { |
| 402 unittest.test("to-json--from-json", () { |
| 403 var o = buildITunesConnectAnalytics(); |
| 404 var od = new api.ITunesConnectAnalytics.fromJson(o.toJson()); |
| 405 checkITunesConnectAnalytics(od); |
| 406 }); |
| 407 }); |
| 408 |
| 409 |
| 410 unittest.group("obj-schema-IosInfo", () { |
| 411 unittest.test("to-json--from-json", () { |
| 412 var o = buildIosInfo(); |
| 413 var od = new api.IosInfo.fromJson(o.toJson()); |
| 414 checkIosInfo(od); |
| 415 }); |
| 416 }); |
| 417 |
| 418 |
| 419 unittest.group("obj-schema-SocialMetaTagInfo", () { |
| 420 unittest.test("to-json--from-json", () { |
| 421 var o = buildSocialMetaTagInfo(); |
| 422 var od = new api.SocialMetaTagInfo.fromJson(o.toJson()); |
| 423 checkSocialMetaTagInfo(od); |
| 424 }); |
| 425 }); |
| 426 |
| 427 |
| 428 unittest.group("obj-schema-Suffix", () { |
| 429 unittest.test("to-json--from-json", () { |
| 430 var o = buildSuffix(); |
| 431 var od = new api.Suffix.fromJson(o.toJson()); |
| 432 checkSuffix(od); |
| 433 }); |
| 434 }); |
| 435 |
| 436 |
| 437 unittest.group("resource-ShortLinksResourceApi", () { |
| 438 unittest.test("method--create", () { |
| 439 |
| 440 var mock = new HttpServerMock(); |
| 441 api.ShortLinksResourceApi res = new api.FirebasedynamiclinksApi(mock).shor
tLinks; |
| 442 var arg_request = buildCreateShortDynamicLinkRequest(); |
| 443 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 444 var obj = new api.CreateShortDynamicLinkRequest.fromJson(json); |
| 445 checkCreateShortDynamicLinkRequest(obj); |
| 446 |
| 447 var path = (req.url).path; |
| 448 var pathOffset = 0; |
| 449 var index; |
| 450 var subPart; |
| 451 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 452 pathOffset += 1; |
| 453 unittest.expect(path.substring(pathOffset, pathOffset + 13), unittest.eq
uals("v1/shortLinks")); |
| 454 pathOffset += 13; |
| 455 |
| 456 var query = (req.url).query; |
| 457 var queryOffset = 0; |
| 458 var queryMap = {}; |
| 459 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 460 parseBool(n) { |
| 461 if (n == "true") return true; |
| 462 if (n == "false") return false; |
| 463 if (n == null) return null; |
| 464 throw new core.ArgumentError("Invalid boolean: $n"); |
| 465 } |
| 466 if (query.length > 0) { |
| 467 for (var part in query.split("&")) { |
| 468 var keyvalue = part.split("="); |
| 469 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 470 } |
| 471 } |
| 472 |
| 473 |
| 474 var h = { |
| 475 "content-type" : "application/json; charset=utf-8", |
| 476 }; |
| 477 var resp = convert.JSON.encode(buildCreateShortDynamicLinkResponse()); |
| 478 return new async.Future.value(stringResponse(200, h, resp)); |
| 479 }), true); |
| 480 res.create(arg_request).then(unittest.expectAsync(((api.CreateShortDynamic
LinkResponse response) { |
| 481 checkCreateShortDynamicLinkResponse(response); |
| 482 }))); |
| 483 }); |
| 484 |
| 485 }); |
| 486 |
| 487 |
| 488 } |
| 489 |
OLD | NEW |