OLD | NEW |
1 library googleapis.searchconsole.v1.test; | 1 library googleapis.searchconsole.v1.test; |
2 | 2 |
3 import "dart:core" as core; | 3 import "dart:core" as core; |
4 import "dart:collection" as collection; | |
5 import "dart:async" as async; | 4 import "dart:async" as async; |
6 import "dart:convert" as convert; | 5 import "dart:convert" as convert; |
7 | 6 |
8 import 'package:http/http.dart' as http; | 7 import 'package:http/http.dart' as http; |
9 import 'package:http/testing.dart' as http_testing; | |
10 import 'package:test/test.dart' as unittest; | 8 import 'package:test/test.dart' as unittest; |
11 | 9 |
12 import 'package:googleapis/searchconsole/v1.dart' as api; | 10 import 'package:googleapis/searchconsole/v1.dart' as api; |
13 | 11 |
14 class HttpServerMock extends http.BaseClient { | 12 class HttpServerMock extends http.BaseClient { |
15 core.Function _callback; | 13 core.Function _callback; |
16 core.bool _expectJson; | 14 core.bool _expectJson; |
17 | 15 |
18 void register(core.Function callback, core.bool expectJson) { | 16 void register(core.Function callback, core.bool expectJson) { |
19 _callback = callback; | 17 _callback = callback; |
20 _expectJson = expectJson; | 18 _expectJson = expectJson; |
21 } | 19 } |
22 | 20 |
23 async.Future<http.StreamedResponse> send(http.BaseRequest request) { | 21 async.Future<http.StreamedResponse> send(http.BaseRequest request) { |
24 if (_expectJson) { | 22 if (_expectJson) { |
25 return request.finalize() | 23 return request |
| 24 .finalize() |
26 .transform(convert.UTF8.decoder) | 25 .transform(convert.UTF8.decoder) |
27 .join('') | 26 .join('') |
28 .then((core.String jsonString) { | 27 .then((core.String jsonString) { |
29 if (jsonString.isEmpty) { | 28 if (jsonString.isEmpty) { |
30 return _callback(request, null); | 29 return _callback(request, null); |
31 } else { | 30 } else { |
32 return _callback(request, convert.JSON.decode(jsonString)); | 31 return _callback(request, convert.JSON.decode(jsonString)); |
33 } | 32 } |
34 }); | 33 }); |
35 } else { | 34 } else { |
36 var stream = request.finalize(); | 35 var stream = request.finalize(); |
37 if (stream == null) { | 36 if (stream == null) { |
38 return _callback(request, []); | 37 return _callback(request, []); |
39 } else { | 38 } else { |
40 return stream.toBytes().then((data) { | 39 return stream.toBytes().then((data) { |
41 return _callback(request, data); | 40 return _callback(request, data); |
42 }); | 41 }); |
43 } | 42 } |
44 } | 43 } |
45 } | 44 } |
46 } | 45 } |
47 | 46 |
48 http.StreamedResponse stringResponse( | 47 http.StreamedResponse stringResponse(core.int status, |
49 core.int status, core.Map<core.String, core.String> headers, core.String bod
y) { | 48 core.Map<core.String, core.String> headers, core.String body) { |
50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | 49 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
51 return new http.StreamedResponse(stream, status, headers: headers); | 50 return new http.StreamedResponse(stream, status, headers: headers); |
52 } | 51 } |
53 | 52 |
54 core.int buildCounterBlockedResource = 0; | 53 core.int buildCounterBlockedResource = 0; |
55 buildBlockedResource() { | 54 buildBlockedResource() { |
56 var o = new api.BlockedResource(); | 55 var o = new api.BlockedResource(); |
57 buildCounterBlockedResource++; | 56 buildCounterBlockedResource++; |
58 if (buildCounterBlockedResource < 3) { | 57 if (buildCounterBlockedResource < 3) { |
59 o.url = "foo"; | 58 o.url = "foo"; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 142 |
144 checkRunMobileFriendlyTestRequest(api.RunMobileFriendlyTestRequest o) { | 143 checkRunMobileFriendlyTestRequest(api.RunMobileFriendlyTestRequest o) { |
145 buildCounterRunMobileFriendlyTestRequest++; | 144 buildCounterRunMobileFriendlyTestRequest++; |
146 if (buildCounterRunMobileFriendlyTestRequest < 3) { | 145 if (buildCounterRunMobileFriendlyTestRequest < 3) { |
147 unittest.expect(o.requestScreenshot, unittest.isTrue); | 146 unittest.expect(o.requestScreenshot, unittest.isTrue); |
148 unittest.expect(o.url, unittest.equals('foo')); | 147 unittest.expect(o.url, unittest.equals('foo')); |
149 } | 148 } |
150 buildCounterRunMobileFriendlyTestRequest--; | 149 buildCounterRunMobileFriendlyTestRequest--; |
151 } | 150 } |
152 | 151 |
153 buildUnnamed1233() { | 152 buildUnnamed1229() { |
154 var o = new core.List<api.MobileFriendlyIssue>(); | 153 var o = new core.List<api.MobileFriendlyIssue>(); |
155 o.add(buildMobileFriendlyIssue()); | 154 o.add(buildMobileFriendlyIssue()); |
156 o.add(buildMobileFriendlyIssue()); | 155 o.add(buildMobileFriendlyIssue()); |
157 return o; | 156 return o; |
158 } | 157 } |
159 | 158 |
160 checkUnnamed1233(core.List<api.MobileFriendlyIssue> o) { | 159 checkUnnamed1229(core.List<api.MobileFriendlyIssue> o) { |
161 unittest.expect(o, unittest.hasLength(2)); | 160 unittest.expect(o, unittest.hasLength(2)); |
162 checkMobileFriendlyIssue(o[0]); | 161 checkMobileFriendlyIssue(o[0]); |
163 checkMobileFriendlyIssue(o[1]); | 162 checkMobileFriendlyIssue(o[1]); |
164 } | 163 } |
165 | 164 |
166 buildUnnamed1234() { | 165 buildUnnamed1230() { |
167 var o = new core.List<api.ResourceIssue>(); | 166 var o = new core.List<api.ResourceIssue>(); |
168 o.add(buildResourceIssue()); | 167 o.add(buildResourceIssue()); |
169 o.add(buildResourceIssue()); | 168 o.add(buildResourceIssue()); |
170 return o; | 169 return o; |
171 } | 170 } |
172 | 171 |
173 checkUnnamed1234(core.List<api.ResourceIssue> o) { | 172 checkUnnamed1230(core.List<api.ResourceIssue> o) { |
174 unittest.expect(o, unittest.hasLength(2)); | 173 unittest.expect(o, unittest.hasLength(2)); |
175 checkResourceIssue(o[0]); | 174 checkResourceIssue(o[0]); |
176 checkResourceIssue(o[1]); | 175 checkResourceIssue(o[1]); |
177 } | 176 } |
178 | 177 |
179 core.int buildCounterRunMobileFriendlyTestResponse = 0; | 178 core.int buildCounterRunMobileFriendlyTestResponse = 0; |
180 buildRunMobileFriendlyTestResponse() { | 179 buildRunMobileFriendlyTestResponse() { |
181 var o = new api.RunMobileFriendlyTestResponse(); | 180 var o = new api.RunMobileFriendlyTestResponse(); |
182 buildCounterRunMobileFriendlyTestResponse++; | 181 buildCounterRunMobileFriendlyTestResponse++; |
183 if (buildCounterRunMobileFriendlyTestResponse < 3) { | 182 if (buildCounterRunMobileFriendlyTestResponse < 3) { |
184 o.mobileFriendliness = "foo"; | 183 o.mobileFriendliness = "foo"; |
185 o.mobileFriendlyIssues = buildUnnamed1233(); | 184 o.mobileFriendlyIssues = buildUnnamed1229(); |
186 o.resourceIssues = buildUnnamed1234(); | 185 o.resourceIssues = buildUnnamed1230(); |
187 o.screenshot = buildImage(); | 186 o.screenshot = buildImage(); |
188 o.testStatus = buildTestStatus(); | 187 o.testStatus = buildTestStatus(); |
189 } | 188 } |
190 buildCounterRunMobileFriendlyTestResponse--; | 189 buildCounterRunMobileFriendlyTestResponse--; |
191 return o; | 190 return o; |
192 } | 191 } |
193 | 192 |
194 checkRunMobileFriendlyTestResponse(api.RunMobileFriendlyTestResponse o) { | 193 checkRunMobileFriendlyTestResponse(api.RunMobileFriendlyTestResponse o) { |
195 buildCounterRunMobileFriendlyTestResponse++; | 194 buildCounterRunMobileFriendlyTestResponse++; |
196 if (buildCounterRunMobileFriendlyTestResponse < 3) { | 195 if (buildCounterRunMobileFriendlyTestResponse < 3) { |
197 unittest.expect(o.mobileFriendliness, unittest.equals('foo')); | 196 unittest.expect(o.mobileFriendliness, unittest.equals('foo')); |
198 checkUnnamed1233(o.mobileFriendlyIssues); | 197 checkUnnamed1229(o.mobileFriendlyIssues); |
199 checkUnnamed1234(o.resourceIssues); | 198 checkUnnamed1230(o.resourceIssues); |
200 checkImage(o.screenshot); | 199 checkImage(o.screenshot); |
201 checkTestStatus(o.testStatus); | 200 checkTestStatus(o.testStatus); |
202 } | 201 } |
203 buildCounterRunMobileFriendlyTestResponse--; | 202 buildCounterRunMobileFriendlyTestResponse--; |
204 } | 203 } |
205 | 204 |
206 core.int buildCounterTestStatus = 0; | 205 core.int buildCounterTestStatus = 0; |
207 buildTestStatus() { | 206 buildTestStatus() { |
208 var o = new api.TestStatus(); | 207 var o = new api.TestStatus(); |
209 buildCounterTestStatus++; | 208 buildCounterTestStatus++; |
210 if (buildCounterTestStatus < 3) { | 209 if (buildCounterTestStatus < 3) { |
211 o.details = "foo"; | 210 o.details = "foo"; |
212 o.status = "foo"; | 211 o.status = "foo"; |
213 } | 212 } |
214 buildCounterTestStatus--; | 213 buildCounterTestStatus--; |
215 return o; | 214 return o; |
216 } | 215 } |
217 | 216 |
218 checkTestStatus(api.TestStatus o) { | 217 checkTestStatus(api.TestStatus o) { |
219 buildCounterTestStatus++; | 218 buildCounterTestStatus++; |
220 if (buildCounterTestStatus < 3) { | 219 if (buildCounterTestStatus < 3) { |
221 unittest.expect(o.details, unittest.equals('foo')); | 220 unittest.expect(o.details, unittest.equals('foo')); |
222 unittest.expect(o.status, unittest.equals('foo')); | 221 unittest.expect(o.status, unittest.equals('foo')); |
223 } | 222 } |
224 buildCounterTestStatus--; | 223 buildCounterTestStatus--; |
225 } | 224 } |
226 | 225 |
227 | |
228 main() { | 226 main() { |
229 unittest.group("obj-schema-BlockedResource", () { | 227 unittest.group("obj-schema-BlockedResource", () { |
230 unittest.test("to-json--from-json", () { | 228 unittest.test("to-json--from-json", () { |
231 var o = buildBlockedResource(); | 229 var o = buildBlockedResource(); |
232 var od = new api.BlockedResource.fromJson(o.toJson()); | 230 var od = new api.BlockedResource.fromJson(o.toJson()); |
233 checkBlockedResource(od); | 231 checkBlockedResource(od); |
234 }); | 232 }); |
235 }); | 233 }); |
236 | 234 |
237 | |
238 unittest.group("obj-schema-Image", () { | 235 unittest.group("obj-schema-Image", () { |
239 unittest.test("to-json--from-json", () { | 236 unittest.test("to-json--from-json", () { |
240 var o = buildImage(); | 237 var o = buildImage(); |
241 var od = new api.Image.fromJson(o.toJson()); | 238 var od = new api.Image.fromJson(o.toJson()); |
242 checkImage(od); | 239 checkImage(od); |
243 }); | 240 }); |
244 }); | 241 }); |
245 | 242 |
246 | |
247 unittest.group("obj-schema-MobileFriendlyIssue", () { | 243 unittest.group("obj-schema-MobileFriendlyIssue", () { |
248 unittest.test("to-json--from-json", () { | 244 unittest.test("to-json--from-json", () { |
249 var o = buildMobileFriendlyIssue(); | 245 var o = buildMobileFriendlyIssue(); |
250 var od = new api.MobileFriendlyIssue.fromJson(o.toJson()); | 246 var od = new api.MobileFriendlyIssue.fromJson(o.toJson()); |
251 checkMobileFriendlyIssue(od); | 247 checkMobileFriendlyIssue(od); |
252 }); | 248 }); |
253 }); | 249 }); |
254 | 250 |
255 | |
256 unittest.group("obj-schema-ResourceIssue", () { | 251 unittest.group("obj-schema-ResourceIssue", () { |
257 unittest.test("to-json--from-json", () { | 252 unittest.test("to-json--from-json", () { |
258 var o = buildResourceIssue(); | 253 var o = buildResourceIssue(); |
259 var od = new api.ResourceIssue.fromJson(o.toJson()); | 254 var od = new api.ResourceIssue.fromJson(o.toJson()); |
260 checkResourceIssue(od); | 255 checkResourceIssue(od); |
261 }); | 256 }); |
262 }); | 257 }); |
263 | 258 |
264 | |
265 unittest.group("obj-schema-RunMobileFriendlyTestRequest", () { | 259 unittest.group("obj-schema-RunMobileFriendlyTestRequest", () { |
266 unittest.test("to-json--from-json", () { | 260 unittest.test("to-json--from-json", () { |
267 var o = buildRunMobileFriendlyTestRequest(); | 261 var o = buildRunMobileFriendlyTestRequest(); |
268 var od = new api.RunMobileFriendlyTestRequest.fromJson(o.toJson()); | 262 var od = new api.RunMobileFriendlyTestRequest.fromJson(o.toJson()); |
269 checkRunMobileFriendlyTestRequest(od); | 263 checkRunMobileFriendlyTestRequest(od); |
270 }); | 264 }); |
271 }); | 265 }); |
272 | 266 |
273 | |
274 unittest.group("obj-schema-RunMobileFriendlyTestResponse", () { | 267 unittest.group("obj-schema-RunMobileFriendlyTestResponse", () { |
275 unittest.test("to-json--from-json", () { | 268 unittest.test("to-json--from-json", () { |
276 var o = buildRunMobileFriendlyTestResponse(); | 269 var o = buildRunMobileFriendlyTestResponse(); |
277 var od = new api.RunMobileFriendlyTestResponse.fromJson(o.toJson()); | 270 var od = new api.RunMobileFriendlyTestResponse.fromJson(o.toJson()); |
278 checkRunMobileFriendlyTestResponse(od); | 271 checkRunMobileFriendlyTestResponse(od); |
279 }); | 272 }); |
280 }); | 273 }); |
281 | 274 |
282 | |
283 unittest.group("obj-schema-TestStatus", () { | 275 unittest.group("obj-schema-TestStatus", () { |
284 unittest.test("to-json--from-json", () { | 276 unittest.test("to-json--from-json", () { |
285 var o = buildTestStatus(); | 277 var o = buildTestStatus(); |
286 var od = new api.TestStatus.fromJson(o.toJson()); | 278 var od = new api.TestStatus.fromJson(o.toJson()); |
287 checkTestStatus(od); | 279 checkTestStatus(od); |
288 }); | 280 }); |
289 }); | 281 }); |
290 | 282 |
291 | |
292 unittest.group("resource-UrlTestingToolsMobileFriendlyTestResourceApi", () { | 283 unittest.group("resource-UrlTestingToolsMobileFriendlyTestResourceApi", () { |
293 unittest.test("method--run", () { | 284 unittest.test("method--run", () { |
294 | |
295 var mock = new HttpServerMock(); | 285 var mock = new HttpServerMock(); |
296 api.UrlTestingToolsMobileFriendlyTestResourceApi res = new api.Searchconso
leApi(mock).urlTestingTools.mobileFriendlyTest; | 286 api.UrlTestingToolsMobileFriendlyTestResourceApi res = |
| 287 new api.SearchconsoleApi(mock).urlTestingTools.mobileFriendlyTest; |
297 var arg_request = buildRunMobileFriendlyTestRequest(); | 288 var arg_request = buildRunMobileFriendlyTestRequest(); |
298 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { | 289 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
299 var obj = new api.RunMobileFriendlyTestRequest.fromJson(json); | 290 var obj = new api.RunMobileFriendlyTestRequest.fromJson(json); |
300 checkRunMobileFriendlyTestRequest(obj); | 291 checkRunMobileFriendlyTestRequest(obj); |
301 | 292 |
302 var path = (req.url).path; | 293 var path = (req.url).path; |
303 var pathOffset = 0; | 294 var pathOffset = 0; |
304 var index; | 295 var index; |
305 var subPart; | 296 var subPart; |
306 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 297 unittest.expect( |
| 298 path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
307 pathOffset += 1; | 299 pathOffset += 1; |
308 unittest.expect(path.substring(pathOffset, pathOffset + 41), unittest.eq
uals("v1/urlTestingTools/mobileFriendlyTest:run")); | 300 unittest.expect(path.substring(pathOffset, pathOffset + 41), |
| 301 unittest.equals("v1/urlTestingTools/mobileFriendlyTest:run")); |
309 pathOffset += 41; | 302 pathOffset += 41; |
310 | 303 |
311 var query = (req.url).query; | 304 var query = (req.url).query; |
312 var queryOffset = 0; | 305 var queryOffset = 0; |
313 var queryMap = {}; | 306 var queryMap = {}; |
314 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | 307 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
315 parseBool(n) { | 308 parseBool(n) { |
316 if (n == "true") return true; | 309 if (n == "true") return true; |
317 if (n == "false") return false; | 310 if (n == "false") return false; |
318 if (n == null) return null; | 311 if (n == null) return null; |
319 throw new core.ArgumentError("Invalid boolean: $n"); | 312 throw new core.ArgumentError("Invalid boolean: $n"); |
320 } | 313 } |
| 314 |
321 if (query.length > 0) { | 315 if (query.length > 0) { |
322 for (var part in query.split("&")) { | 316 for (var part in query.split("&")) { |
323 var keyvalue = part.split("="); | 317 var keyvalue = part.split("="); |
324 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 318 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), |
| 319 core.Uri.decodeQueryComponent(keyvalue[1])); |
325 } | 320 } |
326 } | 321 } |
327 | 322 |
328 | |
329 var h = { | 323 var h = { |
330 "content-type" : "application/json; charset=utf-8", | 324 "content-type": "application/json; charset=utf-8", |
331 }; | 325 }; |
332 var resp = convert.JSON.encode(buildRunMobileFriendlyTestResponse()); | 326 var resp = convert.JSON.encode(buildRunMobileFriendlyTestResponse()); |
333 return new async.Future.value(stringResponse(200, h, resp)); | 327 return new async.Future.value(stringResponse(200, h, resp)); |
334 }), true); | 328 }), true); |
335 res.run(arg_request).then(unittest.expectAsync1(((api.RunMobileFriendlyTes
tResponse response) { | 329 res.run(arg_request).then( |
| 330 unittest.expectAsync1(((api.RunMobileFriendlyTestResponse response) { |
336 checkRunMobileFriendlyTestResponse(response); | 331 checkRunMobileFriendlyTestResponse(response); |
337 }))); | 332 }))); |
338 }); | 333 }); |
339 | |
340 }); | 334 }); |
341 | |
342 | |
343 } | 335 } |
344 | |
OLD | NEW |