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

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

Issue 1296863002: Api-roll 22: 2015-08-17 (Closed) Base URL: git@github.com:dart-lang/googleapis.git@master
Patch Set: Created 5 years, 4 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.cloudbilling.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/cloudbilling/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 buildCounterBillingAccount = 0;
55 buildBillingAccount() {
56 var o = new api.BillingAccount();
57 buildCounterBillingAccount++;
58 if (buildCounterBillingAccount < 3) {
59 o.displayName = "foo";
60 o.name = "foo";
61 o.open = true;
62 }
63 buildCounterBillingAccount--;
64 return o;
65 }
66
67 checkBillingAccount(api.BillingAccount o) {
68 buildCounterBillingAccount++;
69 if (buildCounterBillingAccount < 3) {
70 unittest.expect(o.displayName, unittest.equals('foo'));
71 unittest.expect(o.name, unittest.equals('foo'));
72 unittest.expect(o.open, unittest.isTrue);
73 }
74 buildCounterBillingAccount--;
75 }
76
77 buildUnnamed20() {
78 var o = new core.List<api.BillingAccount>();
79 o.add(buildBillingAccount());
80 o.add(buildBillingAccount());
81 return o;
82 }
83
84 checkUnnamed20(core.List<api.BillingAccount> o) {
85 unittest.expect(o, unittest.hasLength(2));
86 checkBillingAccount(o[0]);
87 checkBillingAccount(o[1]);
88 }
89
90 core.int buildCounterListBillingAccountsResponse = 0;
91 buildListBillingAccountsResponse() {
92 var o = new api.ListBillingAccountsResponse();
93 buildCounterListBillingAccountsResponse++;
94 if (buildCounterListBillingAccountsResponse < 3) {
95 o.billingAccounts = buildUnnamed20();
96 o.nextPageToken = "foo";
97 }
98 buildCounterListBillingAccountsResponse--;
99 return o;
100 }
101
102 checkListBillingAccountsResponse(api.ListBillingAccountsResponse o) {
103 buildCounterListBillingAccountsResponse++;
104 if (buildCounterListBillingAccountsResponse < 3) {
105 checkUnnamed20(o.billingAccounts);
106 unittest.expect(o.nextPageToken, unittest.equals('foo'));
107 }
108 buildCounterListBillingAccountsResponse--;
109 }
110
111 buildUnnamed21() {
112 var o = new core.List<api.ProjectBillingInfo>();
113 o.add(buildProjectBillingInfo());
114 o.add(buildProjectBillingInfo());
115 return o;
116 }
117
118 checkUnnamed21(core.List<api.ProjectBillingInfo> o) {
119 unittest.expect(o, unittest.hasLength(2));
120 checkProjectBillingInfo(o[0]);
121 checkProjectBillingInfo(o[1]);
122 }
123
124 core.int buildCounterListProjectBillingInfoResponse = 0;
125 buildListProjectBillingInfoResponse() {
126 var o = new api.ListProjectBillingInfoResponse();
127 buildCounterListProjectBillingInfoResponse++;
128 if (buildCounterListProjectBillingInfoResponse < 3) {
129 o.nextPageToken = "foo";
130 o.projectBillingInfo = buildUnnamed21();
131 }
132 buildCounterListProjectBillingInfoResponse--;
133 return o;
134 }
135
136 checkListProjectBillingInfoResponse(api.ListProjectBillingInfoResponse o) {
137 buildCounterListProjectBillingInfoResponse++;
138 if (buildCounterListProjectBillingInfoResponse < 3) {
139 unittest.expect(o.nextPageToken, unittest.equals('foo'));
140 checkUnnamed21(o.projectBillingInfo);
141 }
142 buildCounterListProjectBillingInfoResponse--;
143 }
144
145 core.int buildCounterProjectBillingInfo = 0;
146 buildProjectBillingInfo() {
147 var o = new api.ProjectBillingInfo();
148 buildCounterProjectBillingInfo++;
149 if (buildCounterProjectBillingInfo < 3) {
150 o.billingAccountName = "foo";
151 o.billingEnabled = true;
152 o.name = "foo";
153 o.projectId = "foo";
154 }
155 buildCounterProjectBillingInfo--;
156 return o;
157 }
158
159 checkProjectBillingInfo(api.ProjectBillingInfo o) {
160 buildCounterProjectBillingInfo++;
161 if (buildCounterProjectBillingInfo < 3) {
162 unittest.expect(o.billingAccountName, unittest.equals('foo'));
163 unittest.expect(o.billingEnabled, unittest.isTrue);
164 unittest.expect(o.name, unittest.equals('foo'));
165 unittest.expect(o.projectId, unittest.equals('foo'));
166 }
167 buildCounterProjectBillingInfo--;
168 }
169
170
171 main() {
172 unittest.group("obj-schema-BillingAccount", () {
173 unittest.test("to-json--from-json", () {
174 var o = buildBillingAccount();
175 var od = new api.BillingAccount.fromJson(o.toJson());
176 checkBillingAccount(od);
177 });
178 });
179
180
181 unittest.group("obj-schema-ListBillingAccountsResponse", () {
182 unittest.test("to-json--from-json", () {
183 var o = buildListBillingAccountsResponse();
184 var od = new api.ListBillingAccountsResponse.fromJson(o.toJson());
185 checkListBillingAccountsResponse(od);
186 });
187 });
188
189
190 unittest.group("obj-schema-ListProjectBillingInfoResponse", () {
191 unittest.test("to-json--from-json", () {
192 var o = buildListProjectBillingInfoResponse();
193 var od = new api.ListProjectBillingInfoResponse.fromJson(o.toJson());
194 checkListProjectBillingInfoResponse(od);
195 });
196 });
197
198
199 unittest.group("obj-schema-ProjectBillingInfo", () {
200 unittest.test("to-json--from-json", () {
201 var o = buildProjectBillingInfo();
202 var od = new api.ProjectBillingInfo.fromJson(o.toJson());
203 checkProjectBillingInfo(od);
204 });
205 });
206
207
208 unittest.group("resource-BillingAccountsResourceApi", () {
209 unittest.test("method--get", () {
210
211 var mock = new HttpServerMock();
212 api.BillingAccountsResourceApi res = new api.CloudbillingApi(mock).billing Accounts;
213 var arg_name = "foo";
214 mock.register(unittest.expectAsync((http.BaseRequest req, json) {
215 var path = (req.url).path;
216 var pathOffset = 0;
217 var index;
218 var subPart;
219 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
220 pathOffset += 1;
221 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ als("v1/"));
222 pathOffset += 3;
223 // NOTE: We cannot test reserved expansions due to the inability to reve rse the operation;
224
225 var query = (req.url).query;
226 var queryOffset = 0;
227 var queryMap = {};
228 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
229 parseBool(n) {
230 if (n == "true") return true;
231 if (n == "false") return false;
232 if (n == null) return null;
233 throw new core.ArgumentError("Invalid boolean: $n");
234 }
235 if (query.length > 0) {
236 for (var part in query.split("&")) {
237 var keyvalue = part.split("=");
238 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
239 }
240 }
241
242
243 var h = {
244 "content-type" : "application/json; charset=utf-8",
245 };
246 var resp = convert.JSON.encode(buildBillingAccount());
247 return new async.Future.value(stringResponse(200, h, resp));
248 }), true);
249 res.get(arg_name).then(unittest.expectAsync(((api.BillingAccount response) {
250 checkBillingAccount(response);
251 })));
252 });
253
254 unittest.test("method--list", () {
255
256 var mock = new HttpServerMock();
257 api.BillingAccountsResourceApi res = new api.CloudbillingApi(mock).billing Accounts;
258 var arg_pageSize = 42;
259 var arg_pageToken = "foo";
260 mock.register(unittest.expectAsync((http.BaseRequest req, json) {
261 var path = (req.url).path;
262 var pathOffset = 0;
263 var index;
264 var subPart;
265 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
266 pathOffset += 1;
267 unittest.expect(path.substring(pathOffset, pathOffset + 18), unittest.eq uals("v1/billingAccounts"));
268 pathOffset += 18;
269
270 var query = (req.url).query;
271 var queryOffset = 0;
272 var queryMap = {};
273 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
274 parseBool(n) {
275 if (n == "true") return true;
276 if (n == "false") return false;
277 if (n == null) return null;
278 throw new core.ArgumentError("Invalid boolean: $n");
279 }
280 if (query.length > 0) {
281 for (var part in query.split("&")) {
282 var keyvalue = part.split("=");
283 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
284 }
285 }
286 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ als(arg_pageSize));
287 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok en));
288
289
290 var h = {
291 "content-type" : "application/json; charset=utf-8",
292 };
293 var resp = convert.JSON.encode(buildListBillingAccountsResponse());
294 return new async.Future.value(stringResponse(200, h, resp));
295 }), true);
296 res.list(pageSize: arg_pageSize, pageToken: arg_pageToken).then(unittest.e xpectAsync(((api.ListBillingAccountsResponse response) {
297 checkListBillingAccountsResponse(response);
298 })));
299 });
300
301 });
302
303
304 unittest.group("resource-BillingAccountsProjectsResourceApi", () {
305 unittest.test("method--list", () {
306
307 var mock = new HttpServerMock();
308 api.BillingAccountsProjectsResourceApi res = new api.CloudbillingApi(mock) .billingAccounts.projects;
309 var arg_name = "foo";
310 var arg_pageSize = 42;
311 var arg_pageToken = "foo";
312 mock.register(unittest.expectAsync((http.BaseRequest req, json) {
313 var path = (req.url).path;
314 var pathOffset = 0;
315 var index;
316 var subPart;
317 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
318 pathOffset += 1;
319 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ als("v1/"));
320 pathOffset += 3;
321 // NOTE: We cannot test reserved expansions due to the inability to reve rse the operation;
322
323 var query = (req.url).query;
324 var queryOffset = 0;
325 var queryMap = {};
326 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
327 parseBool(n) {
328 if (n == "true") return true;
329 if (n == "false") return false;
330 if (n == null) return null;
331 throw new core.ArgumentError("Invalid boolean: $n");
332 }
333 if (query.length > 0) {
334 for (var part in query.split("&")) {
335 var keyvalue = part.split("=");
336 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
337 }
338 }
339 unittest.expect(core.int.parse(queryMap["pageSize"].first), unittest.equ als(arg_pageSize));
340 unittest.expect(queryMap["pageToken"].first, unittest.equals(arg_pageTok en));
341
342
343 var h = {
344 "content-type" : "application/json; charset=utf-8",
345 };
346 var resp = convert.JSON.encode(buildListProjectBillingInfoResponse());
347 return new async.Future.value(stringResponse(200, h, resp));
348 }), true);
349 res.list(arg_name, pageSize: arg_pageSize, pageToken: arg_pageToken).then( unittest.expectAsync(((api.ListProjectBillingInfoResponse response) {
350 checkListProjectBillingInfoResponse(response);
351 })));
352 });
353
354 });
355
356
357 unittest.group("resource-ProjectsResourceApi", () {
358 unittest.test("method--getBillingInfo", () {
359
360 var mock = new HttpServerMock();
361 api.ProjectsResourceApi res = new api.CloudbillingApi(mock).projects;
362 var arg_name = "foo";
363 mock.register(unittest.expectAsync((http.BaseRequest req, json) {
364 var path = (req.url).path;
365 var pathOffset = 0;
366 var index;
367 var subPart;
368 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
369 pathOffset += 1;
370 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ als("v1/"));
371 pathOffset += 3;
372 // NOTE: We cannot test reserved expansions due to the inability to reve rse the operation;
373
374 var query = (req.url).query;
375 var queryOffset = 0;
376 var queryMap = {};
377 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
378 parseBool(n) {
379 if (n == "true") return true;
380 if (n == "false") return false;
381 if (n == null) return null;
382 throw new core.ArgumentError("Invalid boolean: $n");
383 }
384 if (query.length > 0) {
385 for (var part in query.split("&")) {
386 var keyvalue = part.split("=");
387 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
388 }
389 }
390
391
392 var h = {
393 "content-type" : "application/json; charset=utf-8",
394 };
395 var resp = convert.JSON.encode(buildProjectBillingInfo());
396 return new async.Future.value(stringResponse(200, h, resp));
397 }), true);
398 res.getBillingInfo(arg_name).then(unittest.expectAsync(((api.ProjectBillin gInfo response) {
399 checkProjectBillingInfo(response);
400 })));
401 });
402
403 unittest.test("method--updateBillingInfo", () {
404
405 var mock = new HttpServerMock();
406 api.ProjectsResourceApi res = new api.CloudbillingApi(mock).projects;
407 var arg_request = buildProjectBillingInfo();
408 var arg_name = "foo";
409 mock.register(unittest.expectAsync((http.BaseRequest req, json) {
410 var obj = new api.ProjectBillingInfo.fromJson(json);
411 checkProjectBillingInfo(obj);
412
413 var path = (req.url).path;
414 var pathOffset = 0;
415 var index;
416 var subPart;
417 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
418 pathOffset += 1;
419 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ als("v1/"));
420 pathOffset += 3;
421 // NOTE: We cannot test reserved expansions due to the inability to reve rse the operation;
422
423 var query = (req.url).query;
424 var queryOffset = 0;
425 var queryMap = {};
426 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
427 parseBool(n) {
428 if (n == "true") return true;
429 if (n == "false") return false;
430 if (n == null) return null;
431 throw new core.ArgumentError("Invalid boolean: $n");
432 }
433 if (query.length > 0) {
434 for (var part in query.split("&")) {
435 var keyvalue = part.split("=");
436 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
437 }
438 }
439
440
441 var h = {
442 "content-type" : "application/json; charset=utf-8",
443 };
444 var resp = convert.JSON.encode(buildProjectBillingInfo());
445 return new async.Future.value(stringResponse(200, h, resp));
446 }), true);
447 res.updateBillingInfo(arg_request, arg_name).then(unittest.expectAsync(((a pi.ProjectBillingInfo response) {
448 checkProjectBillingInfo(response);
449 })));
450 });
451
452 });
453
454
455 }
456
OLDNEW
« no previous file with comments | « generated/googleapis/test/classroom/v1_test.dart ('k') | generated/googleapis/test/clouddebugger/v2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698