| OLD | NEW |
| 1 library googleapis.adexperiencereport.v1.test; | 1 library googleapis.adexperiencereport.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/adexperiencereport/v1.dart' as api; | 10 import 'package:googleapis/adexperiencereport/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 buildUnnamed1774() { | 53 buildUnnamed1772() { |
| 55 var o = new core.List<core.String>(); | 54 var o = new core.List<core.String>(); |
| 56 o.add("foo"); | 55 o.add("foo"); |
| 57 o.add("foo"); | 56 o.add("foo"); |
| 58 return o; | 57 return o; |
| 59 } | 58 } |
| 60 | 59 |
| 61 checkUnnamed1774(core.List<core.String> o) { | 60 checkUnnamed1772(core.List<core.String> o) { |
| 62 unittest.expect(o, unittest.hasLength(2)); | 61 unittest.expect(o, unittest.hasLength(2)); |
| 63 unittest.expect(o[0], unittest.equals('foo')); | 62 unittest.expect(o[0], unittest.equals('foo')); |
| 64 unittest.expect(o[1], unittest.equals('foo')); | 63 unittest.expect(o[1], unittest.equals('foo')); |
| 65 } | 64 } |
| 66 | 65 |
| 67 core.int buildCounterPlatformSummary = 0; | 66 core.int buildCounterPlatformSummary = 0; |
| 68 buildPlatformSummary() { | 67 buildPlatformSummary() { |
| 69 var o = new api.PlatformSummary(); | 68 var o = new api.PlatformSummary(); |
| 70 buildCounterPlatformSummary++; | 69 buildCounterPlatformSummary++; |
| 71 if (buildCounterPlatformSummary < 3) { | 70 if (buildCounterPlatformSummary < 3) { |
| 72 o.abusiveStatus = "foo"; | 71 o.abusiveStatus = "foo"; |
| 73 o.betterAdsStatus = "foo"; | 72 o.betterAdsStatus = "foo"; |
| 74 o.enforcementTime = "foo"; | 73 o.enforcementTime = "foo"; |
| 75 o.filterStatus = "foo"; | 74 o.filterStatus = "foo"; |
| 76 o.lastChangeTime = "foo"; | 75 o.lastChangeTime = "foo"; |
| 77 o.region = buildUnnamed1774(); | 76 o.region = buildUnnamed1772(); |
| 78 o.reportUrl = "foo"; | 77 o.reportUrl = "foo"; |
| 79 o.underReview = true; | 78 o.underReview = true; |
| 80 } | 79 } |
| 81 buildCounterPlatformSummary--; | 80 buildCounterPlatformSummary--; |
| 82 return o; | 81 return o; |
| 83 } | 82 } |
| 84 | 83 |
| 85 checkPlatformSummary(api.PlatformSummary o) { | 84 checkPlatformSummary(api.PlatformSummary o) { |
| 86 buildCounterPlatformSummary++; | 85 buildCounterPlatformSummary++; |
| 87 if (buildCounterPlatformSummary < 3) { | 86 if (buildCounterPlatformSummary < 3) { |
| 88 unittest.expect(o.abusiveStatus, unittest.equals('foo')); | 87 unittest.expect(o.abusiveStatus, unittest.equals('foo')); |
| 89 unittest.expect(o.betterAdsStatus, unittest.equals('foo')); | 88 unittest.expect(o.betterAdsStatus, unittest.equals('foo')); |
| 90 unittest.expect(o.enforcementTime, unittest.equals('foo')); | 89 unittest.expect(o.enforcementTime, unittest.equals('foo')); |
| 91 unittest.expect(o.filterStatus, unittest.equals('foo')); | 90 unittest.expect(o.filterStatus, unittest.equals('foo')); |
| 92 unittest.expect(o.lastChangeTime, unittest.equals('foo')); | 91 unittest.expect(o.lastChangeTime, unittest.equals('foo')); |
| 93 checkUnnamed1774(o.region); | 92 checkUnnamed1772(o.region); |
| 94 unittest.expect(o.reportUrl, unittest.equals('foo')); | 93 unittest.expect(o.reportUrl, unittest.equals('foo')); |
| 95 unittest.expect(o.underReview, unittest.isTrue); | 94 unittest.expect(o.underReview, unittest.isTrue); |
| 96 } | 95 } |
| 97 buildCounterPlatformSummary--; | 96 buildCounterPlatformSummary--; |
| 98 } | 97 } |
| 99 | 98 |
| 100 core.int buildCounterSiteSummaryResponse = 0; | 99 core.int buildCounterSiteSummaryResponse = 0; |
| 101 buildSiteSummaryResponse() { | 100 buildSiteSummaryResponse() { |
| 102 var o = new api.SiteSummaryResponse(); | 101 var o = new api.SiteSummaryResponse(); |
| 103 buildCounterSiteSummaryResponse++; | 102 buildCounterSiteSummaryResponse++; |
| 104 if (buildCounterSiteSummaryResponse < 3) { | 103 if (buildCounterSiteSummaryResponse < 3) { |
| 105 o.desktopSummary = buildPlatformSummary(); | 104 o.desktopSummary = buildPlatformSummary(); |
| 106 o.mobileSummary = buildPlatformSummary(); | 105 o.mobileSummary = buildPlatformSummary(); |
| 107 o.reviewedSite = "foo"; | 106 o.reviewedSite = "foo"; |
| 108 } | 107 } |
| 109 buildCounterSiteSummaryResponse--; | 108 buildCounterSiteSummaryResponse--; |
| 110 return o; | 109 return o; |
| 111 } | 110 } |
| 112 | 111 |
| 113 checkSiteSummaryResponse(api.SiteSummaryResponse o) { | 112 checkSiteSummaryResponse(api.SiteSummaryResponse o) { |
| 114 buildCounterSiteSummaryResponse++; | 113 buildCounterSiteSummaryResponse++; |
| 115 if (buildCounterSiteSummaryResponse < 3) { | 114 if (buildCounterSiteSummaryResponse < 3) { |
| 116 checkPlatformSummary(o.desktopSummary); | 115 checkPlatformSummary(o.desktopSummary); |
| 117 checkPlatformSummary(o.mobileSummary); | 116 checkPlatformSummary(o.mobileSummary); |
| 118 unittest.expect(o.reviewedSite, unittest.equals('foo')); | 117 unittest.expect(o.reviewedSite, unittest.equals('foo')); |
| 119 } | 118 } |
| 120 buildCounterSiteSummaryResponse--; | 119 buildCounterSiteSummaryResponse--; |
| 121 } | 120 } |
| 122 | 121 |
| 123 buildUnnamed1775() { | 122 buildUnnamed1773() { |
| 124 var o = new core.List<api.SiteSummaryResponse>(); | 123 var o = new core.List<api.SiteSummaryResponse>(); |
| 125 o.add(buildSiteSummaryResponse()); | 124 o.add(buildSiteSummaryResponse()); |
| 126 o.add(buildSiteSummaryResponse()); | 125 o.add(buildSiteSummaryResponse()); |
| 127 return o; | 126 return o; |
| 128 } | 127 } |
| 129 | 128 |
| 130 checkUnnamed1775(core.List<api.SiteSummaryResponse> o) { | 129 checkUnnamed1773(core.List<api.SiteSummaryResponse> o) { |
| 131 unittest.expect(o, unittest.hasLength(2)); | 130 unittest.expect(o, unittest.hasLength(2)); |
| 132 checkSiteSummaryResponse(o[0]); | 131 checkSiteSummaryResponse(o[0]); |
| 133 checkSiteSummaryResponse(o[1]); | 132 checkSiteSummaryResponse(o[1]); |
| 134 } | 133 } |
| 135 | 134 |
| 136 core.int buildCounterViolatingSitesResponse = 0; | 135 core.int buildCounterViolatingSitesResponse = 0; |
| 137 buildViolatingSitesResponse() { | 136 buildViolatingSitesResponse() { |
| 138 var o = new api.ViolatingSitesResponse(); | 137 var o = new api.ViolatingSitesResponse(); |
| 139 buildCounterViolatingSitesResponse++; | 138 buildCounterViolatingSitesResponse++; |
| 140 if (buildCounterViolatingSitesResponse < 3) { | 139 if (buildCounterViolatingSitesResponse < 3) { |
| 141 o.violatingSites = buildUnnamed1775(); | 140 o.violatingSites = buildUnnamed1773(); |
| 142 } | 141 } |
| 143 buildCounterViolatingSitesResponse--; | 142 buildCounterViolatingSitesResponse--; |
| 144 return o; | 143 return o; |
| 145 } | 144 } |
| 146 | 145 |
| 147 checkViolatingSitesResponse(api.ViolatingSitesResponse o) { | 146 checkViolatingSitesResponse(api.ViolatingSitesResponse o) { |
| 148 buildCounterViolatingSitesResponse++; | 147 buildCounterViolatingSitesResponse++; |
| 149 if (buildCounterViolatingSitesResponse < 3) { | 148 if (buildCounterViolatingSitesResponse < 3) { |
| 150 checkUnnamed1775(o.violatingSites); | 149 checkUnnamed1773(o.violatingSites); |
| 151 } | 150 } |
| 152 buildCounterViolatingSitesResponse--; | 151 buildCounterViolatingSitesResponse--; |
| 153 } | 152 } |
| 154 | 153 |
| 155 | |
| 156 main() { | 154 main() { |
| 157 unittest.group("obj-schema-PlatformSummary", () { | 155 unittest.group("obj-schema-PlatformSummary", () { |
| 158 unittest.test("to-json--from-json", () { | 156 unittest.test("to-json--from-json", () { |
| 159 var o = buildPlatformSummary(); | 157 var o = buildPlatformSummary(); |
| 160 var od = new api.PlatformSummary.fromJson(o.toJson()); | 158 var od = new api.PlatformSummary.fromJson(o.toJson()); |
| 161 checkPlatformSummary(od); | 159 checkPlatformSummary(od); |
| 162 }); | 160 }); |
| 163 }); | 161 }); |
| 164 | 162 |
| 165 | |
| 166 unittest.group("obj-schema-SiteSummaryResponse", () { | 163 unittest.group("obj-schema-SiteSummaryResponse", () { |
| 167 unittest.test("to-json--from-json", () { | 164 unittest.test("to-json--from-json", () { |
| 168 var o = buildSiteSummaryResponse(); | 165 var o = buildSiteSummaryResponse(); |
| 169 var od = new api.SiteSummaryResponse.fromJson(o.toJson()); | 166 var od = new api.SiteSummaryResponse.fromJson(o.toJson()); |
| 170 checkSiteSummaryResponse(od); | 167 checkSiteSummaryResponse(od); |
| 171 }); | 168 }); |
| 172 }); | 169 }); |
| 173 | 170 |
| 174 | |
| 175 unittest.group("obj-schema-ViolatingSitesResponse", () { | 171 unittest.group("obj-schema-ViolatingSitesResponse", () { |
| 176 unittest.test("to-json--from-json", () { | 172 unittest.test("to-json--from-json", () { |
| 177 var o = buildViolatingSitesResponse(); | 173 var o = buildViolatingSitesResponse(); |
| 178 var od = new api.ViolatingSitesResponse.fromJson(o.toJson()); | 174 var od = new api.ViolatingSitesResponse.fromJson(o.toJson()); |
| 179 checkViolatingSitesResponse(od); | 175 checkViolatingSitesResponse(od); |
| 180 }); | 176 }); |
| 181 }); | 177 }); |
| 182 | 178 |
| 183 | |
| 184 unittest.group("resource-SitesResourceApi", () { | 179 unittest.group("resource-SitesResourceApi", () { |
| 185 unittest.test("method--get", () { | 180 unittest.test("method--get", () { |
| 186 | |
| 187 var mock = new HttpServerMock(); | 181 var mock = new HttpServerMock(); |
| 188 api.SitesResourceApi res = new api.AdexperiencereportApi(mock).sites; | 182 api.SitesResourceApi res = new api.AdexperiencereportApi(mock).sites; |
| 189 var arg_name = "foo"; | 183 var arg_name = "foo"; |
| 190 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { | 184 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 191 var path = (req.url).path; | 185 var path = (req.url).path; |
| 192 var pathOffset = 0; | 186 var pathOffset = 0; |
| 193 var index; | 187 var index; |
| 194 var subPart; | 188 var subPart; |
| 195 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 189 unittest.expect( |
| 190 path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| 196 pathOffset += 1; | 191 pathOffset += 1; |
| 197 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); | 192 unittest.expect( |
| 193 path.substring(pathOffset, pathOffset + 3), unittest.equals("v1/")); |
| 198 pathOffset += 3; | 194 pathOffset += 3; |
| 199 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; | 195 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; |
| 200 | 196 |
| 201 var query = (req.url).query; | 197 var query = (req.url).query; |
| 202 var queryOffset = 0; | 198 var queryOffset = 0; |
| 203 var queryMap = {}; | 199 var queryMap = {}; |
| 204 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | 200 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 205 parseBool(n) { | 201 parseBool(n) { |
| 206 if (n == "true") return true; | 202 if (n == "true") return true; |
| 207 if (n == "false") return false; | 203 if (n == "false") return false; |
| 208 if (n == null) return null; | 204 if (n == null) return null; |
| 209 throw new core.ArgumentError("Invalid boolean: $n"); | 205 throw new core.ArgumentError("Invalid boolean: $n"); |
| 210 } | 206 } |
| 207 |
| 211 if (query.length > 0) { | 208 if (query.length > 0) { |
| 212 for (var part in query.split("&")) { | 209 for (var part in query.split("&")) { |
| 213 var keyvalue = part.split("="); | 210 var keyvalue = part.split("="); |
| 214 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 211 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), |
| 212 core.Uri.decodeQueryComponent(keyvalue[1])); |
| 215 } | 213 } |
| 216 } | 214 } |
| 217 | 215 |
| 218 | |
| 219 var h = { | 216 var h = { |
| 220 "content-type" : "application/json; charset=utf-8", | 217 "content-type": "application/json; charset=utf-8", |
| 221 }; | 218 }; |
| 222 var resp = convert.JSON.encode(buildSiteSummaryResponse()); | 219 var resp = convert.JSON.encode(buildSiteSummaryResponse()); |
| 223 return new async.Future.value(stringResponse(200, h, resp)); | 220 return new async.Future.value(stringResponse(200, h, resp)); |
| 224 }), true); | 221 }), true); |
| 225 res.get(arg_name).then(unittest.expectAsync1(((api.SiteSummaryResponse res
ponse) { | 222 res |
| 223 .get(arg_name) |
| 224 .then(unittest.expectAsync1(((api.SiteSummaryResponse response) { |
| 226 checkSiteSummaryResponse(response); | 225 checkSiteSummaryResponse(response); |
| 227 }))); | 226 }))); |
| 228 }); | 227 }); |
| 229 | |
| 230 }); | 228 }); |
| 231 | 229 |
| 232 | |
| 233 unittest.group("resource-ViolatingSitesResourceApi", () { | 230 unittest.group("resource-ViolatingSitesResourceApi", () { |
| 234 unittest.test("method--list", () { | 231 unittest.test("method--list", () { |
| 235 | |
| 236 var mock = new HttpServerMock(); | 232 var mock = new HttpServerMock(); |
| 237 api.ViolatingSitesResourceApi res = new api.AdexperiencereportApi(mock).vi
olatingSites; | 233 api.ViolatingSitesResourceApi res = |
| 234 new api.AdexperiencereportApi(mock).violatingSites; |
| 238 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { | 235 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 239 var path = (req.url).path; | 236 var path = (req.url).path; |
| 240 var pathOffset = 0; | 237 var pathOffset = 0; |
| 241 var index; | 238 var index; |
| 242 var subPart; | 239 var subPart; |
| 243 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 240 unittest.expect( |
| 241 path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| 244 pathOffset += 1; | 242 pathOffset += 1; |
| 245 unittest.expect(path.substring(pathOffset, pathOffset + 17), unittest.eq
uals("v1/violatingSites")); | 243 unittest.expect(path.substring(pathOffset, pathOffset + 17), |
| 244 unittest.equals("v1/violatingSites")); |
| 246 pathOffset += 17; | 245 pathOffset += 17; |
| 247 | 246 |
| 248 var query = (req.url).query; | 247 var query = (req.url).query; |
| 249 var queryOffset = 0; | 248 var queryOffset = 0; |
| 250 var queryMap = {}; | 249 var queryMap = {}; |
| 251 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | 250 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 252 parseBool(n) { | 251 parseBool(n) { |
| 253 if (n == "true") return true; | 252 if (n == "true") return true; |
| 254 if (n == "false") return false; | 253 if (n == "false") return false; |
| 255 if (n == null) return null; | 254 if (n == null) return null; |
| 256 throw new core.ArgumentError("Invalid boolean: $n"); | 255 throw new core.ArgumentError("Invalid boolean: $n"); |
| 257 } | 256 } |
| 257 |
| 258 if (query.length > 0) { | 258 if (query.length > 0) { |
| 259 for (var part in query.split("&")) { | 259 for (var part in query.split("&")) { |
| 260 var keyvalue = part.split("="); | 260 var keyvalue = part.split("="); |
| 261 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 261 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), |
| 262 core.Uri.decodeQueryComponent(keyvalue[1])); |
| 262 } | 263 } |
| 263 } | 264 } |
| 264 | 265 |
| 265 | |
| 266 var h = { | 266 var h = { |
| 267 "content-type" : "application/json; charset=utf-8", | 267 "content-type": "application/json; charset=utf-8", |
| 268 }; | 268 }; |
| 269 var resp = convert.JSON.encode(buildViolatingSitesResponse()); | 269 var resp = convert.JSON.encode(buildViolatingSitesResponse()); |
| 270 return new async.Future.value(stringResponse(200, h, resp)); | 270 return new async.Future.value(stringResponse(200, h, resp)); |
| 271 }), true); | 271 }), true); |
| 272 res.list().then(unittest.expectAsync1(((api.ViolatingSitesResponse respons
e) { | 272 res |
| 273 .list() |
| 274 .then(unittest.expectAsync1(((api.ViolatingSitesResponse response) { |
| 273 checkViolatingSitesResponse(response); | 275 checkViolatingSitesResponse(response); |
| 274 }))); | 276 }))); |
| 275 }); | 277 }); |
| 276 | |
| 277 }); | 278 }); |
| 278 | |
| 279 | |
| 280 } | 279 } |
| 281 | |
| OLD | NEW |