OLD | NEW |
(Empty) | |
| 1 library googleapis.manufacturers.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/manufacturers/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 buildUnnamed1811() { |
| 55 var o = new core.List<core.String>(); |
| 56 o.add("foo"); |
| 57 o.add("foo"); |
| 58 return o; |
| 59 } |
| 60 |
| 61 checkUnnamed1811(core.List<core.String> o) { |
| 62 unittest.expect(o, unittest.hasLength(2)); |
| 63 unittest.expect(o[0], unittest.equals('foo')); |
| 64 unittest.expect(o[1], unittest.equals('foo')); |
| 65 } |
| 66 |
| 67 buildUnnamed1812() { |
| 68 var o = new core.List<core.String>(); |
| 69 o.add("foo"); |
| 70 o.add("foo"); |
| 71 return o; |
| 72 } |
| 73 |
| 74 checkUnnamed1812(core.List<core.String> o) { |
| 75 unittest.expect(o, unittest.hasLength(2)); |
| 76 unittest.expect(o[0], unittest.equals('foo')); |
| 77 unittest.expect(o[1], unittest.equals('foo')); |
| 78 } |
| 79 |
| 80 core.int buildCounterAttributes = 0; |
| 81 buildAttributes() { |
| 82 var o = new api.Attributes(); |
| 83 buildCounterAttributes++; |
| 84 if (buildCounterAttributes < 3) { |
| 85 o.brand = "foo"; |
| 86 o.gtin = buildUnnamed1811(); |
| 87 o.mpn = "foo"; |
| 88 o.productLine = "foo"; |
| 89 o.productName = "foo"; |
| 90 o.productPageUrl = "foo"; |
| 91 o.productType = buildUnnamed1812(); |
| 92 o.title = "foo"; |
| 93 } |
| 94 buildCounterAttributes--; |
| 95 return o; |
| 96 } |
| 97 |
| 98 checkAttributes(api.Attributes o) { |
| 99 buildCounterAttributes++; |
| 100 if (buildCounterAttributes < 3) { |
| 101 unittest.expect(o.brand, unittest.equals('foo')); |
| 102 checkUnnamed1811(o.gtin); |
| 103 unittest.expect(o.mpn, unittest.equals('foo')); |
| 104 unittest.expect(o.productLine, unittest.equals('foo')); |
| 105 unittest.expect(o.productName, unittest.equals('foo')); |
| 106 unittest.expect(o.productPageUrl, unittest.equals('foo')); |
| 107 checkUnnamed1812(o.productType); |
| 108 unittest.expect(o.title, unittest.equals('foo')); |
| 109 } |
| 110 buildCounterAttributes--; |
| 111 } |
| 112 |
| 113 core.int buildCounterIssue = 0; |
| 114 buildIssue() { |
| 115 var o = new api.Issue(); |
| 116 buildCounterIssue++; |
| 117 if (buildCounterIssue < 3) { |
| 118 o.attribute = "foo"; |
| 119 o.description = "foo"; |
| 120 o.severity = "foo"; |
| 121 o.type = "foo"; |
| 122 } |
| 123 buildCounterIssue--; |
| 124 return o; |
| 125 } |
| 126 |
| 127 checkIssue(api.Issue o) { |
| 128 buildCounterIssue++; |
| 129 if (buildCounterIssue < 3) { |
| 130 unittest.expect(o.attribute, unittest.equals('foo')); |
| 131 unittest.expect(o.description, unittest.equals('foo')); |
| 132 unittest.expect(o.severity, unittest.equals('foo')); |
| 133 unittest.expect(o.type, unittest.equals('foo')); |
| 134 } |
| 135 buildCounterIssue--; |
| 136 } |
| 137 |
| 138 buildUnnamed1813() { |
| 139 var o = new core.List<api.Product>(); |
| 140 o.add(buildProduct()); |
| 141 o.add(buildProduct()); |
| 142 return o; |
| 143 } |
| 144 |
| 145 checkUnnamed1813(core.List<api.Product> o) { |
| 146 unittest.expect(o, unittest.hasLength(2)); |
| 147 checkProduct(o[0]); |
| 148 checkProduct(o[1]); |
| 149 } |
| 150 |
| 151 core.int buildCounterListProductsResponse = 0; |
| 152 buildListProductsResponse() { |
| 153 var o = new api.ListProductsResponse(); |
| 154 buildCounterListProductsResponse++; |
| 155 if (buildCounterListProductsResponse < 3) { |
| 156 o.nextPageToken = "foo"; |
| 157 o.products = buildUnnamed1813(); |
| 158 } |
| 159 buildCounterListProductsResponse--; |
| 160 return o; |
| 161 } |
| 162 |
| 163 checkListProductsResponse(api.ListProductsResponse o) { |
| 164 buildCounterListProductsResponse++; |
| 165 if (buildCounterListProductsResponse < 3) { |
| 166 unittest.expect(o.nextPageToken, unittest.equals('foo')); |
| 167 checkUnnamed1813(o.products); |
| 168 } |
| 169 buildCounterListProductsResponse--; |
| 170 } |
| 171 |
| 172 buildUnnamed1814() { |
| 173 var o = new core.List<api.Issue>(); |
| 174 o.add(buildIssue()); |
| 175 o.add(buildIssue()); |
| 176 return o; |
| 177 } |
| 178 |
| 179 checkUnnamed1814(core.List<api.Issue> o) { |
| 180 unittest.expect(o, unittest.hasLength(2)); |
| 181 checkIssue(o[0]); |
| 182 checkIssue(o[1]); |
| 183 } |
| 184 |
| 185 buildUnnamed1815() { |
| 186 var o = new core.List<core.String>(); |
| 187 o.add("foo"); |
| 188 o.add("foo"); |
| 189 return o; |
| 190 } |
| 191 |
| 192 checkUnnamed1815(core.List<core.String> o) { |
| 193 unittest.expect(o, unittest.hasLength(2)); |
| 194 unittest.expect(o[0], unittest.equals('foo')); |
| 195 unittest.expect(o[1], unittest.equals('foo')); |
| 196 } |
| 197 |
| 198 core.int buildCounterProduct = 0; |
| 199 buildProduct() { |
| 200 var o = new api.Product(); |
| 201 buildCounterProduct++; |
| 202 if (buildCounterProduct < 3) { |
| 203 o.contentLanguage = "foo"; |
| 204 o.finalAttributes = buildAttributes(); |
| 205 o.issues = buildUnnamed1814(); |
| 206 o.manuallyDeletedAttributes = buildUnnamed1815(); |
| 207 o.manuallyProvidedAttributes = buildAttributes(); |
| 208 o.name = "foo"; |
| 209 o.parent = "foo"; |
| 210 o.productId = "foo"; |
| 211 o.targetCountry = "foo"; |
| 212 o.uploadedAttributes = buildAttributes(); |
| 213 } |
| 214 buildCounterProduct--; |
| 215 return o; |
| 216 } |
| 217 |
| 218 checkProduct(api.Product o) { |
| 219 buildCounterProduct++; |
| 220 if (buildCounterProduct < 3) { |
| 221 unittest.expect(o.contentLanguage, unittest.equals('foo')); |
| 222 checkAttributes(o.finalAttributes); |
| 223 checkUnnamed1814(o.issues); |
| 224 checkUnnamed1815(o.manuallyDeletedAttributes); |
| 225 checkAttributes(o.manuallyProvidedAttributes); |
| 226 unittest.expect(o.name, unittest.equals('foo')); |
| 227 unittest.expect(o.parent, unittest.equals('foo')); |
| 228 unittest.expect(o.productId, unittest.equals('foo')); |
| 229 unittest.expect(o.targetCountry, unittest.equals('foo')); |
| 230 checkAttributes(o.uploadedAttributes); |
| 231 } |
| 232 buildCounterProduct--; |
| 233 } |
| 234 |
| 235 |
| 236 main() { |
| 237 unittest.group("obj-schema-Attributes", () { |
| 238 unittest.test("to-json--from-json", () { |
| 239 var o = buildAttributes(); |
| 240 var od = new api.Attributes.fromJson(o.toJson()); |
| 241 checkAttributes(od); |
| 242 }); |
| 243 }); |
| 244 |
| 245 |
| 246 unittest.group("obj-schema-Issue", () { |
| 247 unittest.test("to-json--from-json", () { |
| 248 var o = buildIssue(); |
| 249 var od = new api.Issue.fromJson(o.toJson()); |
| 250 checkIssue(od); |
| 251 }); |
| 252 }); |
| 253 |
| 254 |
| 255 unittest.group("obj-schema-ListProductsResponse", () { |
| 256 unittest.test("to-json--from-json", () { |
| 257 var o = buildListProductsResponse(); |
| 258 var od = new api.ListProductsResponse.fromJson(o.toJson()); |
| 259 checkListProductsResponse(od); |
| 260 }); |
| 261 }); |
| 262 |
| 263 |
| 264 unittest.group("obj-schema-Product", () { |
| 265 unittest.test("to-json--from-json", () { |
| 266 var o = buildProduct(); |
| 267 var od = new api.Product.fromJson(o.toJson()); |
| 268 checkProduct(od); |
| 269 }); |
| 270 }); |
| 271 |
| 272 |
| 273 unittest.group("resource-AccountsProductsResourceApi", () { |
| 274 unittest.test("method--get", () { |
| 275 |
| 276 var mock = new HttpServerMock(); |
| 277 api.AccountsProductsResourceApi res = new api.ManufacturersApi(mock).accou
nts.products; |
| 278 var arg_parent = "foo"; |
| 279 var arg_name = "foo"; |
| 280 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 281 var path = (req.url).path; |
| 282 var pathOffset = 0; |
| 283 var index; |
| 284 var subPart; |
| 285 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 286 pathOffset += 1; |
| 287 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); |
| 288 pathOffset += 3; |
| 289 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; |
| 290 |
| 291 var query = (req.url).query; |
| 292 var queryOffset = 0; |
| 293 var queryMap = {}; |
| 294 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 295 parseBool(n) { |
| 296 if (n == "true") return true; |
| 297 if (n == "false") return false; |
| 298 if (n == null) return null; |
| 299 throw new core.ArgumentError("Invalid boolean: $n"); |
| 300 } |
| 301 if (query.length > 0) { |
| 302 for (var part in query.split("&")) { |
| 303 var keyvalue = part.split("="); |
| 304 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 305 } |
| 306 } |
| 307 |
| 308 |
| 309 var h = { |
| 310 "content-type" : "application/json; charset=utf-8", |
| 311 }; |
| 312 var resp = convert.JSON.encode(buildProduct()); |
| 313 return new async.Future.value(stringResponse(200, h, resp)); |
| 314 }), true); |
| 315 res.get(arg_parent, arg_name).then(unittest.expectAsync(((api.Product resp
onse) { |
| 316 checkProduct(response); |
| 317 }))); |
| 318 }); |
| 319 |
| 320 unittest.test("method--list", () { |
| 321 |
| 322 var mock = new HttpServerMock(); |
| 323 api.AccountsProductsResourceApi res = new api.ManufacturersApi(mock).accou
nts.products; |
| 324 var arg_parent = "foo"; |
| 325 var arg_pageSize = 42; |
| 326 var arg_pageToken = "foo"; |
| 327 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 328 var path = (req.url).path; |
| 329 var pathOffset = 0; |
| 330 var index; |
| 331 var subPart; |
| 332 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 333 pathOffset += 1; |
| 334 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); |
| 335 pathOffset += 3; |
| 336 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; |
| 337 |
| 338 var query = (req.url).query; |
| 339 var queryOffset = 0; |
| 340 var queryMap = {}; |
| 341 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 342 parseBool(n) { |
| 343 if (n == "true") return true; |
| 344 if (n == "false") return false; |
| 345 if (n == null) return null; |
| 346 throw new core.ArgumentError("Invalid boolean: $n"); |
| 347 } |
| 348 if (query.length > 0) { |
| 349 for (var part in query.split("&")) { |
| 350 var keyvalue = part.split("="); |
| 351 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 352 } |
| 353 } |
| 354 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ
als(arg_pageSize)); |
| 355 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok
en)); |
| 356 |
| 357 |
| 358 var h = { |
| 359 "content-type" : "application/json; charset=utf-8", |
| 360 }; |
| 361 var resp = convert.JSON.encode(buildListProductsResponse()); |
| 362 return new async.Future.value(stringResponse(200, h, resp)); |
| 363 }), true); |
| 364 res.list(arg_parent, pageSize: arg_pageSize, pageToken: arg_pageToken).the
n(unittest.expectAsync(((api.ListProductsResponse response) { |
| 365 checkListProductsResponse(response); |
| 366 }))); |
| 367 }); |
| 368 |
| 369 }); |
| 370 |
| 371 |
| 372 } |
| 373 |
OLD | NEW |