OLD | NEW |
(Empty) | |
| 1 library googleapis.searchconsole.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/searchconsole/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 buildCounterBlockedResource = 0; |
| 55 buildBlockedResource() { |
| 56 var o = new api.BlockedResource(); |
| 57 buildCounterBlockedResource++; |
| 58 if (buildCounterBlockedResource < 3) { |
| 59 o.url = "foo"; |
| 60 } |
| 61 buildCounterBlockedResource--; |
| 62 return o; |
| 63 } |
| 64 |
| 65 checkBlockedResource(api.BlockedResource o) { |
| 66 buildCounterBlockedResource++; |
| 67 if (buildCounterBlockedResource < 3) { |
| 68 unittest.expect(o.url, unittest.equals('foo')); |
| 69 } |
| 70 buildCounterBlockedResource--; |
| 71 } |
| 72 |
| 73 core.int buildCounterImage = 0; |
| 74 buildImage() { |
| 75 var o = new api.Image(); |
| 76 buildCounterImage++; |
| 77 if (buildCounterImage < 3) { |
| 78 o.data = "foo"; |
| 79 o.mimeType = "foo"; |
| 80 } |
| 81 buildCounterImage--; |
| 82 return o; |
| 83 } |
| 84 |
| 85 checkImage(api.Image o) { |
| 86 buildCounterImage++; |
| 87 if (buildCounterImage < 3) { |
| 88 unittest.expect(o.data, unittest.equals('foo')); |
| 89 unittest.expect(o.mimeType, unittest.equals('foo')); |
| 90 } |
| 91 buildCounterImage--; |
| 92 } |
| 93 |
| 94 core.int buildCounterMobileFriendlyIssue = 0; |
| 95 buildMobileFriendlyIssue() { |
| 96 var o = new api.MobileFriendlyIssue(); |
| 97 buildCounterMobileFriendlyIssue++; |
| 98 if (buildCounterMobileFriendlyIssue < 3) { |
| 99 o.rule = "foo"; |
| 100 } |
| 101 buildCounterMobileFriendlyIssue--; |
| 102 return o; |
| 103 } |
| 104 |
| 105 checkMobileFriendlyIssue(api.MobileFriendlyIssue o) { |
| 106 buildCounterMobileFriendlyIssue++; |
| 107 if (buildCounterMobileFriendlyIssue < 3) { |
| 108 unittest.expect(o.rule, unittest.equals('foo')); |
| 109 } |
| 110 buildCounterMobileFriendlyIssue--; |
| 111 } |
| 112 |
| 113 core.int buildCounterResourceIssue = 0; |
| 114 buildResourceIssue() { |
| 115 var o = new api.ResourceIssue(); |
| 116 buildCounterResourceIssue++; |
| 117 if (buildCounterResourceIssue < 3) { |
| 118 o.blockedResource = buildBlockedResource(); |
| 119 } |
| 120 buildCounterResourceIssue--; |
| 121 return o; |
| 122 } |
| 123 |
| 124 checkResourceIssue(api.ResourceIssue o) { |
| 125 buildCounterResourceIssue++; |
| 126 if (buildCounterResourceIssue < 3) { |
| 127 checkBlockedResource(o.blockedResource); |
| 128 } |
| 129 buildCounterResourceIssue--; |
| 130 } |
| 131 |
| 132 core.int buildCounterRunMobileFriendlyTestRequest = 0; |
| 133 buildRunMobileFriendlyTestRequest() { |
| 134 var o = new api.RunMobileFriendlyTestRequest(); |
| 135 buildCounterRunMobileFriendlyTestRequest++; |
| 136 if (buildCounterRunMobileFriendlyTestRequest < 3) { |
| 137 o.requestScreenshot = true; |
| 138 o.url = "foo"; |
| 139 } |
| 140 buildCounterRunMobileFriendlyTestRequest--; |
| 141 return o; |
| 142 } |
| 143 |
| 144 checkRunMobileFriendlyTestRequest(api.RunMobileFriendlyTestRequest o) { |
| 145 buildCounterRunMobileFriendlyTestRequest++; |
| 146 if (buildCounterRunMobileFriendlyTestRequest < 3) { |
| 147 unittest.expect(o.requestScreenshot, unittest.isTrue); |
| 148 unittest.expect(o.url, unittest.equals('foo')); |
| 149 } |
| 150 buildCounterRunMobileFriendlyTestRequest--; |
| 151 } |
| 152 |
| 153 buildUnnamed1087() { |
| 154 var o = new core.List<api.MobileFriendlyIssue>(); |
| 155 o.add(buildMobileFriendlyIssue()); |
| 156 o.add(buildMobileFriendlyIssue()); |
| 157 return o; |
| 158 } |
| 159 |
| 160 checkUnnamed1087(core.List<api.MobileFriendlyIssue> o) { |
| 161 unittest.expect(o, unittest.hasLength(2)); |
| 162 checkMobileFriendlyIssue(o[0]); |
| 163 checkMobileFriendlyIssue(o[1]); |
| 164 } |
| 165 |
| 166 buildUnnamed1088() { |
| 167 var o = new core.List<api.ResourceIssue>(); |
| 168 o.add(buildResourceIssue()); |
| 169 o.add(buildResourceIssue()); |
| 170 return o; |
| 171 } |
| 172 |
| 173 checkUnnamed1088(core.List<api.ResourceIssue> o) { |
| 174 unittest.expect(o, unittest.hasLength(2)); |
| 175 checkResourceIssue(o[0]); |
| 176 checkResourceIssue(o[1]); |
| 177 } |
| 178 |
| 179 core.int buildCounterRunMobileFriendlyTestResponse = 0; |
| 180 buildRunMobileFriendlyTestResponse() { |
| 181 var o = new api.RunMobileFriendlyTestResponse(); |
| 182 buildCounterRunMobileFriendlyTestResponse++; |
| 183 if (buildCounterRunMobileFriendlyTestResponse < 3) { |
| 184 o.mobileFriendliness = "foo"; |
| 185 o.mobileFriendlyIssues = buildUnnamed1087(); |
| 186 o.resourceIssues = buildUnnamed1088(); |
| 187 o.screenshot = buildImage(); |
| 188 o.testStatus = buildTestStatus(); |
| 189 } |
| 190 buildCounterRunMobileFriendlyTestResponse--; |
| 191 return o; |
| 192 } |
| 193 |
| 194 checkRunMobileFriendlyTestResponse(api.RunMobileFriendlyTestResponse o) { |
| 195 buildCounterRunMobileFriendlyTestResponse++; |
| 196 if (buildCounterRunMobileFriendlyTestResponse < 3) { |
| 197 unittest.expect(o.mobileFriendliness, unittest.equals('foo')); |
| 198 checkUnnamed1087(o.mobileFriendlyIssues); |
| 199 checkUnnamed1088(o.resourceIssues); |
| 200 checkImage(o.screenshot); |
| 201 checkTestStatus(o.testStatus); |
| 202 } |
| 203 buildCounterRunMobileFriendlyTestResponse--; |
| 204 } |
| 205 |
| 206 core.int buildCounterTestStatus = 0; |
| 207 buildTestStatus() { |
| 208 var o = new api.TestStatus(); |
| 209 buildCounterTestStatus++; |
| 210 if (buildCounterTestStatus < 3) { |
| 211 o.details = "foo"; |
| 212 o.status = "foo"; |
| 213 } |
| 214 buildCounterTestStatus--; |
| 215 return o; |
| 216 } |
| 217 |
| 218 checkTestStatus(api.TestStatus o) { |
| 219 buildCounterTestStatus++; |
| 220 if (buildCounterTestStatus < 3) { |
| 221 unittest.expect(o.details, unittest.equals('foo')); |
| 222 unittest.expect(o.status, unittest.equals('foo')); |
| 223 } |
| 224 buildCounterTestStatus--; |
| 225 } |
| 226 |
| 227 |
| 228 main() { |
| 229 unittest.group("obj-schema-BlockedResource", () { |
| 230 unittest.test("to-json--from-json", () { |
| 231 var o = buildBlockedResource(); |
| 232 var od = new api.BlockedResource.fromJson(o.toJson()); |
| 233 checkBlockedResource(od); |
| 234 }); |
| 235 }); |
| 236 |
| 237 |
| 238 unittest.group("obj-schema-Image", () { |
| 239 unittest.test("to-json--from-json", () { |
| 240 var o = buildImage(); |
| 241 var od = new api.Image.fromJson(o.toJson()); |
| 242 checkImage(od); |
| 243 }); |
| 244 }); |
| 245 |
| 246 |
| 247 unittest.group("obj-schema-MobileFriendlyIssue", () { |
| 248 unittest.test("to-json--from-json", () { |
| 249 var o = buildMobileFriendlyIssue(); |
| 250 var od = new api.MobileFriendlyIssue.fromJson(o.toJson()); |
| 251 checkMobileFriendlyIssue(od); |
| 252 }); |
| 253 }); |
| 254 |
| 255 |
| 256 unittest.group("obj-schema-ResourceIssue", () { |
| 257 unittest.test("to-json--from-json", () { |
| 258 var o = buildResourceIssue(); |
| 259 var od = new api.ResourceIssue.fromJson(o.toJson()); |
| 260 checkResourceIssue(od); |
| 261 }); |
| 262 }); |
| 263 |
| 264 |
| 265 unittest.group("obj-schema-RunMobileFriendlyTestRequest", () { |
| 266 unittest.test("to-json--from-json", () { |
| 267 var o = buildRunMobileFriendlyTestRequest(); |
| 268 var od = new api.RunMobileFriendlyTestRequest.fromJson(o.toJson()); |
| 269 checkRunMobileFriendlyTestRequest(od); |
| 270 }); |
| 271 }); |
| 272 |
| 273 |
| 274 unittest.group("obj-schema-RunMobileFriendlyTestResponse", () { |
| 275 unittest.test("to-json--from-json", () { |
| 276 var o = buildRunMobileFriendlyTestResponse(); |
| 277 var od = new api.RunMobileFriendlyTestResponse.fromJson(o.toJson()); |
| 278 checkRunMobileFriendlyTestResponse(od); |
| 279 }); |
| 280 }); |
| 281 |
| 282 |
| 283 unittest.group("obj-schema-TestStatus", () { |
| 284 unittest.test("to-json--from-json", () { |
| 285 var o = buildTestStatus(); |
| 286 var od = new api.TestStatus.fromJson(o.toJson()); |
| 287 checkTestStatus(od); |
| 288 }); |
| 289 }); |
| 290 |
| 291 |
| 292 unittest.group("resource-UrlTestingToolsMobileFriendlyTestResourceApi", () { |
| 293 unittest.test("method--run", () { |
| 294 |
| 295 var mock = new HttpServerMock(); |
| 296 api.UrlTestingToolsMobileFriendlyTestResourceApi res = new api.Searchconso
leApi(mock).urlTestingTools.mobileFriendlyTest; |
| 297 var arg_request = buildRunMobileFriendlyTestRequest(); |
| 298 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 299 var obj = new api.RunMobileFriendlyTestRequest.fromJson(json); |
| 300 checkRunMobileFriendlyTestRequest(obj); |
| 301 |
| 302 var path = (req.url).path; |
| 303 var pathOffset = 0; |
| 304 var index; |
| 305 var subPart; |
| 306 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 307 pathOffset += 1; |
| 308 unittest.expect(path.substring(pathOffset, pathOffset + 41), unittest.eq
uals("v1/urlTestingTools/mobileFriendlyTest:run")); |
| 309 pathOffset += 41; |
| 310 |
| 311 var query = (req.url).query; |
| 312 var queryOffset = 0; |
| 313 var queryMap = {}; |
| 314 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 315 parseBool(n) { |
| 316 if (n == "true") return true; |
| 317 if (n == "false") return false; |
| 318 if (n == null) return null; |
| 319 throw new core.ArgumentError("Invalid boolean: $n"); |
| 320 } |
| 321 if (query.length > 0) { |
| 322 for (var part in query.split("&")) { |
| 323 var keyvalue = part.split("="); |
| 324 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 325 } |
| 326 } |
| 327 |
| 328 |
| 329 var h = { |
| 330 "content-type" : "application/json; charset=utf-8", |
| 331 }; |
| 332 var resp = convert.JSON.encode(buildRunMobileFriendlyTestResponse()); |
| 333 return new async.Future.value(stringResponse(200, h, resp)); |
| 334 }), true); |
| 335 res.run(arg_request).then(unittest.expectAsync(((api.RunMobileFriendlyTest
Response response) { |
| 336 checkRunMobileFriendlyTestResponse(response); |
| 337 }))); |
| 338 }); |
| 339 |
| 340 }); |
| 341 |
| 342 |
| 343 } |
| 344 |
OLD | NEW |