OLD | NEW |
| (Empty) |
1 library googleapis.oauth2.v2.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/oauth2/v2.dart' as api; | |
16 | |
17 | |
18 | |
19 core.int buildCounterTokeninfo = 0; | |
20 buildTokeninfo() { | |
21 var o = new api.Tokeninfo(); | |
22 buildCounterTokeninfo++; | |
23 if (buildCounterTokeninfo < 3) { | |
24 o.accessType = "foo"; | |
25 o.audience = "foo"; | |
26 o.email = "foo"; | |
27 o.expiresIn = 42; | |
28 o.issuedTo = "foo"; | |
29 o.scope = "foo"; | |
30 o.userId = "foo"; | |
31 o.verifiedEmail = true; | |
32 } | |
33 buildCounterTokeninfo--; | |
34 return o; | |
35 } | |
36 | |
37 checkTokeninfo(api.Tokeninfo o) { | |
38 buildCounterTokeninfo++; | |
39 if (buildCounterTokeninfo < 3) { | |
40 unittest.expect(o.accessType, unittest.equals('foo')); | |
41 unittest.expect(o.audience, unittest.equals('foo')); | |
42 unittest.expect(o.email, unittest.equals('foo')); | |
43 unittest.expect(o.expiresIn, unittest.equals(42)); | |
44 unittest.expect(o.issuedTo, unittest.equals('foo')); | |
45 unittest.expect(o.scope, unittest.equals('foo')); | |
46 unittest.expect(o.userId, unittest.equals('foo')); | |
47 unittest.expect(o.verifiedEmail, unittest.isTrue); | |
48 } | |
49 buildCounterTokeninfo--; | |
50 } | |
51 | |
52 core.int buildCounterUserinfoplus = 0; | |
53 buildUserinfoplus() { | |
54 var o = new api.Userinfoplus(); | |
55 buildCounterUserinfoplus++; | |
56 if (buildCounterUserinfoplus < 3) { | |
57 o.email = "foo"; | |
58 o.familyName = "foo"; | |
59 o.gender = "foo"; | |
60 o.givenName = "foo"; | |
61 o.hd = "foo"; | |
62 o.id = "foo"; | |
63 o.link = "foo"; | |
64 o.locale = "foo"; | |
65 o.name = "foo"; | |
66 o.picture = "foo"; | |
67 o.verifiedEmail = true; | |
68 } | |
69 buildCounterUserinfoplus--; | |
70 return o; | |
71 } | |
72 | |
73 checkUserinfoplus(api.Userinfoplus o) { | |
74 buildCounterUserinfoplus++; | |
75 if (buildCounterUserinfoplus < 3) { | |
76 unittest.expect(o.email, unittest.equals('foo')); | |
77 unittest.expect(o.familyName, unittest.equals('foo')); | |
78 unittest.expect(o.gender, unittest.equals('foo')); | |
79 unittest.expect(o.givenName, unittest.equals('foo')); | |
80 unittest.expect(o.hd, unittest.equals('foo')); | |
81 unittest.expect(o.id, unittest.equals('foo')); | |
82 unittest.expect(o.link, unittest.equals('foo')); | |
83 unittest.expect(o.locale, unittest.equals('foo')); | |
84 unittest.expect(o.name, unittest.equals('foo')); | |
85 unittest.expect(o.picture, unittest.equals('foo')); | |
86 unittest.expect(o.verifiedEmail, unittest.isTrue); | |
87 } | |
88 buildCounterUserinfoplus--; | |
89 } | |
90 | |
91 | |
92 main() { | |
93 unittest.group("obj-schema-Tokeninfo", () { | |
94 unittest.test("to-json--from-json", () { | |
95 var o = buildTokeninfo(); | |
96 var od = new api.Tokeninfo.fromJson(o.toJson()); | |
97 checkTokeninfo(od); | |
98 }); | |
99 }); | |
100 | |
101 | |
102 unittest.group("obj-schema-Userinfoplus", () { | |
103 unittest.test("to-json--from-json", () { | |
104 var o = buildUserinfoplus(); | |
105 var od = new api.Userinfoplus.fromJson(o.toJson()); | |
106 checkUserinfoplus(od); | |
107 }); | |
108 }); | |
109 | |
110 | |
111 unittest.group("resource-Oauth2Api", () { | |
112 unittest.test("method--tokeninfo", () { | |
113 | |
114 var mock = new common_test.HttpServerMock(); | |
115 api.Oauth2Api res = new api.Oauth2Api(mock); | |
116 var arg_accessToken = "foo"; | |
117 var arg_idToken = "foo"; | |
118 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
119 var path = (req.url).path; | |
120 var pathOffset = 0; | |
121 var index; | |
122 var subPart; | |
123 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
124 pathOffset += 1; | |
125 unittest.expect(path.substring(pathOffset, pathOffset + 19), unittest.eq
uals("oauth2/v2/tokeninfo")); | |
126 pathOffset += 19; | |
127 | |
128 var query = (req.url).query; | |
129 var queryOffset = 0; | |
130 var queryMap = {}; | |
131 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
132 parseBool(n) { | |
133 if (n == "true") return true; | |
134 if (n == "false") return false; | |
135 if (n == null) return null; | |
136 throw new core.ArgumentError("Invalid boolean: $n"); | |
137 } | |
138 if (query.length > 0) { | |
139 for (var part in query.split("&")) { | |
140 var keyvalue = part.split("="); | |
141 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
142 } | |
143 } | |
144 unittest.expect(queryMap["access_token"].first, unittest.equals(arg_acce
ssToken)); | |
145 unittest.expect(queryMap["id_token"].first, unittest.equals(arg_idToken)
); | |
146 | |
147 | |
148 var h = { | |
149 "content-type" : "application/json; charset=utf-8", | |
150 }; | |
151 var resp = convert.JSON.encode(buildTokeninfo()); | |
152 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
153 }), true); | |
154 res.tokeninfo(accessToken: arg_accessToken, idToken: arg_idToken).then(uni
ttest.expectAsync(((api.Tokeninfo response) { | |
155 checkTokeninfo(response); | |
156 }))); | |
157 }); | |
158 | |
159 }); | |
160 | |
161 | |
162 unittest.group("resource-UserinfoResourceApi", () { | |
163 unittest.test("method--get", () { | |
164 | |
165 var mock = new common_test.HttpServerMock(); | |
166 api.UserinfoResourceApi res = new api.Oauth2Api(mock).userinfo; | |
167 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
168 var path = (req.url).path; | |
169 var pathOffset = 0; | |
170 var index; | |
171 var subPart; | |
172 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
173 pathOffset += 1; | |
174 unittest.expect(path.substring(pathOffset, pathOffset + 18), unittest.eq
uals("oauth2/v2/userinfo")); | |
175 pathOffset += 18; | |
176 | |
177 var query = (req.url).query; | |
178 var queryOffset = 0; | |
179 var queryMap = {}; | |
180 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
181 parseBool(n) { | |
182 if (n == "true") return true; | |
183 if (n == "false") return false; | |
184 if (n == null) return null; | |
185 throw new core.ArgumentError("Invalid boolean: $n"); | |
186 } | |
187 if (query.length > 0) { | |
188 for (var part in query.split("&")) { | |
189 var keyvalue = part.split("="); | |
190 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
191 } | |
192 } | |
193 | |
194 | |
195 var h = { | |
196 "content-type" : "application/json; charset=utf-8", | |
197 }; | |
198 var resp = convert.JSON.encode(buildUserinfoplus()); | |
199 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
200 }), true); | |
201 res.get().then(unittest.expectAsync(((api.Userinfoplus response) { | |
202 checkUserinfoplus(response); | |
203 }))); | |
204 }); | |
205 | |
206 }); | |
207 | |
208 | |
209 unittest.group("resource-UserinfoV2MeResourceApi", () { | |
210 unittest.test("method--get", () { | |
211 | |
212 var mock = new common_test.HttpServerMock(); | |
213 api.UserinfoV2MeResourceApi res = new api.Oauth2Api(mock).userinfo.v2.me; | |
214 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | |
215 var path = (req.url).path; | |
216 var pathOffset = 0; | |
217 var index; | |
218 var subPart; | |
219 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | |
220 pathOffset += 1; | |
221 unittest.expect(path.substring(pathOffset, pathOffset + 14), unittest.eq
uals("userinfo/v2/me")); | |
222 pathOffset += 14; | |
223 | |
224 var query = (req.url).query; | |
225 var queryOffset = 0; | |
226 var queryMap = {}; | |
227 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | |
228 parseBool(n) { | |
229 if (n == "true") return true; | |
230 if (n == "false") return false; | |
231 if (n == null) return null; | |
232 throw new core.ArgumentError("Invalid boolean: $n"); | |
233 } | |
234 if (query.length > 0) { | |
235 for (var part in query.split("&")) { | |
236 var keyvalue = part.split("="); | |
237 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | |
238 } | |
239 } | |
240 | |
241 | |
242 var h = { | |
243 "content-type" : "application/json; charset=utf-8", | |
244 }; | |
245 var resp = convert.JSON.encode(buildUserinfoplus()); | |
246 return new async.Future.value(common_test.stringResponse(200, h, resp)); | |
247 }), true); | |
248 res.get().then(unittest.expectAsync(((api.Userinfoplus response) { | |
249 checkUserinfoplus(response); | |
250 }))); | |
251 }); | |
252 | |
253 }); | |
254 | |
255 | |
256 } | |
257 | |
OLD | NEW |