| library googleapis.oauth2.v2.test; |
| |
| import "dart:core" as core; |
| import "dart:collection" as collection; |
| import "dart:async" as async; |
| import "dart:convert" as convert; |
| |
| import 'package:http/http.dart' as http; |
| import 'package:http/testing.dart' as http_testing; |
| import 'package:unittest/unittest.dart' as unittest; |
| import 'package:googleapis/common/common.dart' as common; |
| import 'package:googleapis/src/common_internal.dart' as common_internal; |
| import '../common/common_internal_test.dart' as common_test; |
| |
| import 'package:googleapis/oauth2/v2.dart' as api; |
| |
| |
| |
| core.int buildCounterTokeninfo = 0; |
| buildTokeninfo() { |
| var o = new api.Tokeninfo(); |
| buildCounterTokeninfo++; |
| if (buildCounterTokeninfo < 3) { |
| o.accessType = "foo"; |
| o.audience = "foo"; |
| o.email = "foo"; |
| o.expiresIn = 42; |
| o.issuedTo = "foo"; |
| o.scope = "foo"; |
| o.userId = "foo"; |
| o.verifiedEmail = true; |
| } |
| buildCounterTokeninfo--; |
| return o; |
| } |
| |
| checkTokeninfo(api.Tokeninfo o) { |
| buildCounterTokeninfo++; |
| if (buildCounterTokeninfo < 3) { |
| unittest.expect(o.accessType, unittest.equals('foo')); |
| unittest.expect(o.audience, unittest.equals('foo')); |
| unittest.expect(o.email, unittest.equals('foo')); |
| unittest.expect(o.expiresIn, unittest.equals(42)); |
| unittest.expect(o.issuedTo, unittest.equals('foo')); |
| unittest.expect(o.scope, unittest.equals('foo')); |
| unittest.expect(o.userId, unittest.equals('foo')); |
| unittest.expect(o.verifiedEmail, unittest.isTrue); |
| } |
| buildCounterTokeninfo--; |
| } |
| |
| core.int buildCounterUserinfoplus = 0; |
| buildUserinfoplus() { |
| var o = new api.Userinfoplus(); |
| buildCounterUserinfoplus++; |
| if (buildCounterUserinfoplus < 3) { |
| o.email = "foo"; |
| o.familyName = "foo"; |
| o.gender = "foo"; |
| o.givenName = "foo"; |
| o.hd = "foo"; |
| o.id = "foo"; |
| o.link = "foo"; |
| o.locale = "foo"; |
| o.name = "foo"; |
| o.picture = "foo"; |
| o.verifiedEmail = true; |
| } |
| buildCounterUserinfoplus--; |
| return o; |
| } |
| |
| checkUserinfoplus(api.Userinfoplus o) { |
| buildCounterUserinfoplus++; |
| if (buildCounterUserinfoplus < 3) { |
| unittest.expect(o.email, unittest.equals('foo')); |
| unittest.expect(o.familyName, unittest.equals('foo')); |
| unittest.expect(o.gender, unittest.equals('foo')); |
| unittest.expect(o.givenName, unittest.equals('foo')); |
| unittest.expect(o.hd, unittest.equals('foo')); |
| unittest.expect(o.id, unittest.equals('foo')); |
| unittest.expect(o.link, unittest.equals('foo')); |
| unittest.expect(o.locale, unittest.equals('foo')); |
| unittest.expect(o.name, unittest.equals('foo')); |
| unittest.expect(o.picture, unittest.equals('foo')); |
| unittest.expect(o.verifiedEmail, unittest.isTrue); |
| } |
| buildCounterUserinfoplus--; |
| } |
| |
| |
| main() { |
| unittest.group("obj-schema-Tokeninfo", () { |
| unittest.test("to-json--from-json", () { |
| var o = buildTokeninfo(); |
| var od = new api.Tokeninfo.fromJson(o.toJson()); |
| checkTokeninfo(od); |
| }); |
| }); |
| |
| |
| unittest.group("obj-schema-Userinfoplus", () { |
| unittest.test("to-json--from-json", () { |
| var o = buildUserinfoplus(); |
| var od = new api.Userinfoplus.fromJson(o.toJson()); |
| checkUserinfoplus(od); |
| }); |
| }); |
| |
| |
| unittest.group("resource-Oauth2Api", () { |
| unittest.test("method--tokeninfo", () { |
| |
| var mock = new common_test.HttpServerMock(); |
| api.Oauth2Api res = new api.Oauth2Api(mock); |
| var arg_accessToken = "foo"; |
| var arg_idToken = "foo"; |
| mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| var path = (req.url).path; |
| var pathOffset = 0; |
| var index; |
| var subPart; |
| unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| pathOffset += 1; |
| unittest.expect(path.substring(pathOffset, pathOffset + 19), unittest.equals("oauth2/v2/tokeninfo")); |
| pathOffset += 19; |
| |
| var query = (req.url).query; |
| var queryOffset = 0; |
| var queryMap = {}; |
| addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| parseBool(n) { |
| if (n == "true") return true; |
| if (n == "false") return false; |
| if (n == null) return null; |
| throw new core.ArgumentError("Invalid boolean: $n"); |
| } |
| if (query.length > 0) { |
| for (var part in query.split("&")) { |
| var keyvalue = part.split("="); |
| addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.decodeQueryComponent(keyvalue[1])); |
| } |
| } |
| unittest.expect(queryMap["access_token"].first, unittest.equals(arg_accessToken)); |
| unittest.expect(queryMap["id_token"].first, unittest.equals(arg_idToken)); |
| |
| |
| var h = { |
| "content-type" : "application/json; charset=utf-8", |
| }; |
| var resp = convert.JSON.encode(buildTokeninfo()); |
| return new async.Future.value(common_test.stringResponse(200, h, resp)); |
| }), true); |
| res.tokeninfo(accessToken: arg_accessToken, idToken: arg_idToken).then(unittest.expectAsync(((api.Tokeninfo response) { |
| checkTokeninfo(response); |
| }))); |
| }); |
| |
| }); |
| |
| |
| unittest.group("resource-UserinfoResourceApi", () { |
| unittest.test("method--get", () { |
| |
| var mock = new common_test.HttpServerMock(); |
| api.UserinfoResourceApi res = new api.Oauth2Api(mock).userinfo; |
| mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| var path = (req.url).path; |
| var pathOffset = 0; |
| var index; |
| var subPart; |
| unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| pathOffset += 1; |
| unittest.expect(path.substring(pathOffset, pathOffset + 18), unittest.equals("oauth2/v2/userinfo")); |
| pathOffset += 18; |
| |
| var query = (req.url).query; |
| var queryOffset = 0; |
| var queryMap = {}; |
| addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| parseBool(n) { |
| if (n == "true") return true; |
| if (n == "false") return false; |
| if (n == null) return null; |
| throw new core.ArgumentError("Invalid boolean: $n"); |
| } |
| if (query.length > 0) { |
| for (var part in query.split("&")) { |
| var keyvalue = part.split("="); |
| addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.decodeQueryComponent(keyvalue[1])); |
| } |
| } |
| |
| |
| var h = { |
| "content-type" : "application/json; charset=utf-8", |
| }; |
| var resp = convert.JSON.encode(buildUserinfoplus()); |
| return new async.Future.value(common_test.stringResponse(200, h, resp)); |
| }), true); |
| res.get().then(unittest.expectAsync(((api.Userinfoplus response) { |
| checkUserinfoplus(response); |
| }))); |
| }); |
| |
| }); |
| |
| |
| unittest.group("resource-UserinfoV2MeResourceApi", () { |
| unittest.test("method--get", () { |
| |
| var mock = new common_test.HttpServerMock(); |
| api.UserinfoV2MeResourceApi res = new api.Oauth2Api(mock).userinfo.v2.me; |
| mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| var path = (req.url).path; |
| var pathOffset = 0; |
| var index; |
| var subPart; |
| unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| pathOffset += 1; |
| unittest.expect(path.substring(pathOffset, pathOffset + 14), unittest.equals("userinfo/v2/me")); |
| pathOffset += 14; |
| |
| var query = (req.url).query; |
| var queryOffset = 0; |
| var queryMap = {}; |
| addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| parseBool(n) { |
| if (n == "true") return true; |
| if (n == "false") return false; |
| if (n == null) return null; |
| throw new core.ArgumentError("Invalid boolean: $n"); |
| } |
| if (query.length > 0) { |
| for (var part in query.split("&")) { |
| var keyvalue = part.split("="); |
| addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.decodeQueryComponent(keyvalue[1])); |
| } |
| } |
| |
| |
| var h = { |
| "content-type" : "application/json; charset=utf-8", |
| }; |
| var resp = convert.JSON.encode(buildUserinfoplus()); |
| return new async.Future.value(common_test.stringResponse(200, h, resp)); |
| }), true); |
| res.get().then(unittest.expectAsync(((api.Userinfoplus response) { |
| checkUserinfoplus(response); |
| }))); |
| }); |
| |
| }); |
| |
| |
| } |
| |