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

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

Issue 3006323002: Api-Roll 54: 2017-09-11 (Closed)
Patch Set: use 2.0.0-dev.infinity sdk constraint in pubspecs Created 3 years, 3 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
1 library googleapis.groupsmigration.v1.test; 1 library googleapis.groupsmigration.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/groupsmigration/v1.dart' as api; 10 import 'package:googleapis/groupsmigration/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 core.int buildCounterGroups = 0; 53 core.int buildCounterGroups = 0;
55 buildGroups() { 54 buildGroups() {
56 var o = new api.Groups(); 55 var o = new api.Groups();
57 buildCounterGroups++; 56 buildCounterGroups++;
58 if (buildCounterGroups < 3) { 57 if (buildCounterGroups < 3) {
59 o.kind = "foo"; 58 o.kind = "foo";
60 o.responseCode = "foo"; 59 o.responseCode = "foo";
61 } 60 }
62 buildCounterGroups--; 61 buildCounterGroups--;
63 return o; 62 return o;
64 } 63 }
65 64
66 checkGroups(api.Groups o) { 65 checkGroups(api.Groups o) {
67 buildCounterGroups++; 66 buildCounterGroups++;
68 if (buildCounterGroups < 3) { 67 if (buildCounterGroups < 3) {
69 unittest.expect(o.kind, unittest.equals('foo')); 68 unittest.expect(o.kind, unittest.equals('foo'));
70 unittest.expect(o.responseCode, unittest.equals('foo')); 69 unittest.expect(o.responseCode, unittest.equals('foo'));
71 } 70 }
72 buildCounterGroups--; 71 buildCounterGroups--;
73 } 72 }
74 73
75
76 main() { 74 main() {
77 unittest.group("obj-schema-Groups", () { 75 unittest.group("obj-schema-Groups", () {
78 unittest.test("to-json--from-json", () { 76 unittest.test("to-json--from-json", () {
79 var o = buildGroups(); 77 var o = buildGroups();
80 var od = new api.Groups.fromJson(o.toJson()); 78 var od = new api.Groups.fromJson(o.toJson());
81 checkGroups(od); 79 checkGroups(od);
82 }); 80 });
83 }); 81 });
84 82
85
86 unittest.group("resource-ArchiveResourceApi", () { 83 unittest.group("resource-ArchiveResourceApi", () {
87 unittest.test("method--insert", () { 84 unittest.test("method--insert", () {
88 // TODO: Implement tests for media upload; 85 // TODO: Implement tests for media upload;
89 // TODO: Implement tests for media download; 86 // TODO: Implement tests for media download;
90 87
91 var mock = new HttpServerMock(); 88 var mock = new HttpServerMock();
92 api.ArchiveResourceApi res = new api.GroupsmigrationApi(mock).archive; 89 api.ArchiveResourceApi res = new api.GroupsmigrationApi(mock).archive;
93 var arg_groupId = "foo"; 90 var arg_groupId = "foo";
94 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { 91 mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
95 var path = (req.url).path; 92 var path = (req.url).path;
96 var pathOffset = 0; 93 var pathOffset = 0;
97 var index; 94 var index;
98 var subPart; 95 var subPart;
99 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/")); 96 unittest.expect(
97 path.substring(pathOffset, pathOffset + 1), unittest.equals("/"));
100 pathOffset += 1; 98 pathOffset += 1;
101 99
102 var query = (req.url).query; 100 var query = (req.url).query;
103 var queryOffset = 0; 101 var queryOffset = 0;
104 var queryMap = {}; 102 var queryMap = {};
105 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); 103 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
106 parseBool(n) { 104 parseBool(n) {
107 if (n == "true") return true; 105 if (n == "true") return true;
108 if (n == "false") return false; 106 if (n == "false") return false;
109 if (n == null) return null; 107 if (n == null) return null;
110 throw new core.ArgumentError("Invalid boolean: $n"); 108 throw new core.ArgumentError("Invalid boolean: $n");
111 } 109 }
110
112 if (query.length > 0) { 111 if (query.length > 0) {
113 for (var part in query.split("&")) { 112 for (var part in query.split("&")) {
114 var keyvalue = part.split("="); 113 var keyvalue = part.split("=");
115 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1])); 114 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]),
115 core.Uri.decodeQueryComponent(keyvalue[1]));
116 } 116 }
117 } 117 }
118 118
119
120 var h = { 119 var h = {
121 "content-type" : "application/json; charset=utf-8", 120 "content-type": "application/json; charset=utf-8",
122 }; 121 };
123 var resp = convert.JSON.encode(buildGroups()); 122 var resp = convert.JSON.encode(buildGroups());
124 return new async.Future.value(stringResponse(200, h, resp)); 123 return new async.Future.value(stringResponse(200, h, resp));
125 }), true); 124 }), true);
126 res.insert(arg_groupId).then(unittest.expectAsync1(((api.Groups response) { 125 res
126 .insert(arg_groupId)
127 .then(unittest.expectAsync1(((api.Groups response) {
127 checkGroups(response); 128 checkGroups(response);
128 }))); 129 })));
129 }); 130 });
130
131 }); 131 });
132
133
134 } 132 }
135
OLDNEW
« no previous file with comments | « generated/googleapis/test/genomics/v1_test.dart ('k') | generated/googleapis/test/groupssettings/v1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698