Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: generated/googleapis/test/adexperiencereport/v1_test.dart

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

Powered by Google App Engine
This is Rietveld 408576698