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

Side by Side Diff: generated/googleapis/test/acceleratedmobilepageurl/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.acceleratedmobilepageurl.v1.test; 1 library googleapis.acceleratedmobilepageurl.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/acceleratedmobilepageurl/v1.dart' as api; 10 import 'package:googleapis/acceleratedmobilepageurl/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 buildCounterAmpUrl = 0; 53 core.int buildCounterAmpUrl = 0;
55 buildAmpUrl() { 54 buildAmpUrl() {
56 var o = new api.AmpUrl(); 55 var o = new api.AmpUrl();
57 buildCounterAmpUrl++; 56 buildCounterAmpUrl++;
58 if (buildCounterAmpUrl < 3) { 57 if (buildCounterAmpUrl < 3) {
59 o.ampUrl = "foo"; 58 o.ampUrl = "foo";
(...skipping 30 matching lines...) Expand all
90 checkAmpUrlError(api.AmpUrlError o) { 89 checkAmpUrlError(api.AmpUrlError o) {
91 buildCounterAmpUrlError++; 90 buildCounterAmpUrlError++;
92 if (buildCounterAmpUrlError < 3) { 91 if (buildCounterAmpUrlError < 3) {
93 unittest.expect(o.errorCode, unittest.equals('foo')); 92 unittest.expect(o.errorCode, unittest.equals('foo'));
94 unittest.expect(o.errorMessage, unittest.equals('foo')); 93 unittest.expect(o.errorMessage, unittest.equals('foo'));
95 unittest.expect(o.originalUrl, unittest.equals('foo')); 94 unittest.expect(o.originalUrl, unittest.equals('foo'));
96 } 95 }
97 buildCounterAmpUrlError--; 96 buildCounterAmpUrlError--;
98 } 97 }
99 98
100 buildUnnamed1258() { 99 buildUnnamed1254() {
101 var o = new core.List<core.String>(); 100 var o = new core.List<core.String>();
102 o.add("foo"); 101 o.add("foo");
103 o.add("foo"); 102 o.add("foo");
104 return o; 103 return o;
105 } 104 }
106 105
107 checkUnnamed1258(core.List<core.String> o) { 106 checkUnnamed1254(core.List<core.String> o) {
108 unittest.expect(o, unittest.hasLength(2)); 107 unittest.expect(o, unittest.hasLength(2));
109 unittest.expect(o[0], unittest.equals('foo')); 108 unittest.expect(o[0], unittest.equals('foo'));
110 unittest.expect(o[1], unittest.equals('foo')); 109 unittest.expect(o[1], unittest.equals('foo'));
111 } 110 }
112 111
113 core.int buildCounterBatchGetAmpUrlsRequest = 0; 112 core.int buildCounterBatchGetAmpUrlsRequest = 0;
114 buildBatchGetAmpUrlsRequest() { 113 buildBatchGetAmpUrlsRequest() {
115 var o = new api.BatchGetAmpUrlsRequest(); 114 var o = new api.BatchGetAmpUrlsRequest();
116 buildCounterBatchGetAmpUrlsRequest++; 115 buildCounterBatchGetAmpUrlsRequest++;
117 if (buildCounterBatchGetAmpUrlsRequest < 3) { 116 if (buildCounterBatchGetAmpUrlsRequest < 3) {
118 o.lookupStrategy = "foo"; 117 o.lookupStrategy = "foo";
119 o.urls = buildUnnamed1258(); 118 o.urls = buildUnnamed1254();
120 } 119 }
121 buildCounterBatchGetAmpUrlsRequest--; 120 buildCounterBatchGetAmpUrlsRequest--;
122 return o; 121 return o;
123 } 122 }
124 123
125 checkBatchGetAmpUrlsRequest(api.BatchGetAmpUrlsRequest o) { 124 checkBatchGetAmpUrlsRequest(api.BatchGetAmpUrlsRequest o) {
126 buildCounterBatchGetAmpUrlsRequest++; 125 buildCounterBatchGetAmpUrlsRequest++;
127 if (buildCounterBatchGetAmpUrlsRequest < 3) { 126 if (buildCounterBatchGetAmpUrlsRequest < 3) {
128 unittest.expect(o.lookupStrategy, unittest.equals('foo')); 127 unittest.expect(o.lookupStrategy, unittest.equals('foo'));
129 checkUnnamed1258(o.urls); 128 checkUnnamed1254(o.urls);
130 } 129 }
131 buildCounterBatchGetAmpUrlsRequest--; 130 buildCounterBatchGetAmpUrlsRequest--;
132 } 131 }
133 132
134 buildUnnamed1259() { 133 buildUnnamed1255() {
135 var o = new core.List<api.AmpUrl>(); 134 var o = new core.List<api.AmpUrl>();
136 o.add(buildAmpUrl()); 135 o.add(buildAmpUrl());
137 o.add(buildAmpUrl()); 136 o.add(buildAmpUrl());
138 return o; 137 return o;
139 } 138 }
140 139
141 checkUnnamed1259(core.List<api.AmpUrl> o) { 140 checkUnnamed1255(core.List<api.AmpUrl> o) {
142 unittest.expect(o, unittest.hasLength(2)); 141 unittest.expect(o, unittest.hasLength(2));
143 checkAmpUrl(o[0]); 142 checkAmpUrl(o[0]);
144 checkAmpUrl(o[1]); 143 checkAmpUrl(o[1]);
145 } 144 }
146 145
147 buildUnnamed1260() { 146 buildUnnamed1256() {
148 var o = new core.List<api.AmpUrlError>(); 147 var o = new core.List<api.AmpUrlError>();
149 o.add(buildAmpUrlError()); 148 o.add(buildAmpUrlError());
150 o.add(buildAmpUrlError()); 149 o.add(buildAmpUrlError());
151 return o; 150 return o;
152 } 151 }
153 152
154 checkUnnamed1260(core.List<api.AmpUrlError> o) { 153 checkUnnamed1256(core.List<api.AmpUrlError> o) {
155 unittest.expect(o, unittest.hasLength(2)); 154 unittest.expect(o, unittest.hasLength(2));
156 checkAmpUrlError(o[0]); 155 checkAmpUrlError(o[0]);
157 checkAmpUrlError(o[1]); 156 checkAmpUrlError(o[1]);
158 } 157 }
159 158
160 core.int buildCounterBatchGetAmpUrlsResponse = 0; 159 core.int buildCounterBatchGetAmpUrlsResponse = 0;
161 buildBatchGetAmpUrlsResponse() { 160 buildBatchGetAmpUrlsResponse() {
162 var o = new api.BatchGetAmpUrlsResponse(); 161 var o = new api.BatchGetAmpUrlsResponse();
163 buildCounterBatchGetAmpUrlsResponse++; 162 buildCounterBatchGetAmpUrlsResponse++;
164 if (buildCounterBatchGetAmpUrlsResponse < 3) { 163 if (buildCounterBatchGetAmpUrlsResponse < 3) {
165 o.ampUrls = buildUnnamed1259(); 164 o.ampUrls = buildUnnamed1255();
166 o.urlErrors = buildUnnamed1260(); 165 o.urlErrors = buildUnnamed1256();
167 } 166 }
168 buildCounterBatchGetAmpUrlsResponse--; 167 buildCounterBatchGetAmpUrlsResponse--;
169 return o; 168 return o;
170 } 169 }
171 170
172 checkBatchGetAmpUrlsResponse(api.BatchGetAmpUrlsResponse o) { 171 checkBatchGetAmpUrlsResponse(api.BatchGetAmpUrlsResponse o) {
173 buildCounterBatchGetAmpUrlsResponse++; 172 buildCounterBatchGetAmpUrlsResponse++;
174 if (buildCounterBatchGetAmpUrlsResponse < 3) { 173 if (buildCounterBatchGetAmpUrlsResponse < 3) {
175 checkUnnamed1259(o.ampUrls); 174 checkUnnamed1255(o.ampUrls);
176 checkUnnamed1260(o.urlErrors); 175 checkUnnamed1256(o.urlErrors);
177 } 176 }
178 buildCounterBatchGetAmpUrlsResponse--; 177 buildCounterBatchGetAmpUrlsResponse--;
179 } 178 }
180 179
181
182 main() { 180 main() {
183 unittest.group("obj-schema-AmpUrl", () { 181 unittest.group("obj-schema-AmpUrl", () {
184 unittest.test("to-json--from-json", () { 182 unittest.test("to-json--from-json", () {
185 var o = buildAmpUrl(); 183 var o = buildAmpUrl();
186 var od = new api.AmpUrl.fromJson(o.toJson()); 184 var od = new api.AmpUrl.fromJson(o.toJson());
187 checkAmpUrl(od); 185 checkAmpUrl(od);
188 }); 186 });
189 }); 187 });
190 188
191
192 unittest.group("obj-schema-AmpUrlError", () { 189 unittest.group("obj-schema-AmpUrlError", () {
193 unittest.test("to-json--from-json", () { 190 unittest.test("to-json--from-json", () {
194 var o = buildAmpUrlError(); 191 var o = buildAmpUrlError();
195 var od = new api.AmpUrlError.fromJson(o.toJson()); 192 var od = new api.AmpUrlError.fromJson(o.toJson());
196 checkAmpUrlError(od); 193 checkAmpUrlError(od);
197 }); 194 });
198 }); 195 });
199 196
200
201 unittest.group("obj-schema-BatchGetAmpUrlsRequest", () { 197 unittest.group("obj-schema-BatchGetAmpUrlsRequest", () {
202 unittest.test("to-json--from-json", () { 198 unittest.test("to-json--from-json", () {
203 var o = buildBatchGetAmpUrlsRequest(); 199 var o = buildBatchGetAmpUrlsRequest();
204 var od = new api.BatchGetAmpUrlsRequest.fromJson(o.toJson()); 200 var od = new api.BatchGetAmpUrlsRequest.fromJson(o.toJson());
205 checkBatchGetAmpUrlsRequest(od); 201 checkBatchGetAmpUrlsRequest(od);
206 }); 202 });
207 }); 203 });
208 204
209
210 unittest.group("obj-schema-BatchGetAmpUrlsResponse", () { 205 unittest.group("obj-schema-BatchGetAmpUrlsResponse", () {
211 unittest.test("to-json--from-json", () { 206 unittest.test("to-json--from-json", () {
212 var o = buildBatchGetAmpUrlsResponse(); 207 var o = buildBatchGetAmpUrlsResponse();
213 var od = new api.BatchGetAmpUrlsResponse.fromJson(o.toJson()); 208 var od = new api.BatchGetAmpUrlsResponse.fromJson(o.toJson());
214 checkBatchGetAmpUrlsResponse(od); 209 checkBatchGetAmpUrlsResponse(od);
215 }); 210 });
216 }); 211 });
217 212
218
219 unittest.group("resource-AmpUrlsResourceApi", () { 213 unittest.group("resource-AmpUrlsResourceApi", () {
220 unittest.test("method--batchGet", () { 214 unittest.test("method--batchGet", () {
221
222 var mock = new HttpServerMock(); 215 var mock = new HttpServerMock();
223 api.AmpUrlsResourceApi res = new api.AcceleratedmobilepageurlApi(mock).amp Urls; 216 api.AmpUrlsResourceApi res =
217 new api.AcceleratedmobilepageurlApi(mock).ampUrls;
224 var arg_request = buildBatchGetAmpUrlsRequest(); 218 var arg_request = buildBatchGetAmpUrlsRequest();
225 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { 219 mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
226 var obj = new api.BatchGetAmpUrlsRequest.fromJson(json); 220 var obj = new api.BatchGetAmpUrlsRequest.fromJson(json);
227 checkBatchGetAmpUrlsRequest(obj); 221 checkBatchGetAmpUrlsRequest(obj);
228 222
229 var path = (req.url).path; 223 var path = (req.url).path;
230 var pathOffset = 0; 224 var pathOffset = 0;
231 var index; 225 var index;
232 var subPart; 226 var subPart;
233 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/")); 227 unittest.expect(
228 path.substring(pathOffset, pathOffset + 1), unittest.equals("/"));
234 pathOffset += 1; 229 pathOffset += 1;
235 unittest.expect(path.substring(pathOffset, pathOffset + 19), unittest.eq uals("v1/ampUrls:batchGet")); 230 unittest.expect(path.substring(pathOffset, pathOffset + 19),
231 unittest.equals("v1/ampUrls:batchGet"));
236 pathOffset += 19; 232 pathOffset += 19;
237 233
238 var query = (req.url).query; 234 var query = (req.url).query;
239 var queryOffset = 0; 235 var queryOffset = 0;
240 var queryMap = {}; 236 var queryMap = {};
241 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); 237 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
242 parseBool(n) { 238 parseBool(n) {
243 if (n == "true") return true; 239 if (n == "true") return true;
244 if (n == "false") return false; 240 if (n == "false") return false;
245 if (n == null) return null; 241 if (n == null) return null;
246 throw new core.ArgumentError("Invalid boolean: $n"); 242 throw new core.ArgumentError("Invalid boolean: $n");
247 } 243 }
244
248 if (query.length > 0) { 245 if (query.length > 0) {
249 for (var part in query.split("&")) { 246 for (var part in query.split("&")) {
250 var keyvalue = part.split("="); 247 var keyvalue = part.split("=");
251 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1])); 248 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]),
249 core.Uri.decodeQueryComponent(keyvalue[1]));
252 } 250 }
253 } 251 }
254 252
255
256 var h = { 253 var h = {
257 "content-type" : "application/json; charset=utf-8", 254 "content-type": "application/json; charset=utf-8",
258 }; 255 };
259 var resp = convert.JSON.encode(buildBatchGetAmpUrlsResponse()); 256 var resp = convert.JSON.encode(buildBatchGetAmpUrlsResponse());
260 return new async.Future.value(stringResponse(200, h, resp)); 257 return new async.Future.value(stringResponse(200, h, resp));
261 }), true); 258 }), true);
262 res.batchGet(arg_request).then(unittest.expectAsync1(((api.BatchGetAmpUrls Response response) { 259 res
260 .batchGet(arg_request)
261 .then(unittest.expectAsync1(((api.BatchGetAmpUrlsResponse response) {
263 checkBatchGetAmpUrlsResponse(response); 262 checkBatchGetAmpUrlsResponse(response);
264 }))); 263 })));
265 }); 264 });
266
267 }); 265 });
268
269
270 } 266 }
271
OLDNEW
« no previous file with comments | « generated/googleapis/pubspec.yaml ('k') | generated/googleapis/test/adexperiencereport/v1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698