OLD | NEW |
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; | 4 import "dart:collection" as collection; |
5 import "dart:async" as async; | 5 import "dart:async" as async; |
6 import "dart:convert" as convert; | 6 import "dart:convert" as convert; |
7 | 7 |
8 import 'package:http/http.dart' as http; | 8 import 'package:http/http.dart' as http; |
9 import 'package:http/testing.dart' as http_testing; | 9 import 'package:http/testing.dart' as http_testing; |
10 import 'package:unittest/unittest.dart' as unittest; | 10 import 'package:test/test.dart' as unittest; |
11 | 11 |
12 import 'package:googleapis/acceleratedmobilepageurl/v1.dart' as api; | 12 import 'package:googleapis/acceleratedmobilepageurl/v1.dart' as api; |
13 | 13 |
14 class HttpServerMock extends http.BaseClient { | 14 class HttpServerMock extends http.BaseClient { |
15 core.Function _callback; | 15 core.Function _callback; |
16 core.bool _expectJson; | 16 core.bool _expectJson; |
17 | 17 |
18 void register(core.Function callback, core.bool expectJson) { | 18 void register(core.Function callback, core.bool expectJson) { |
19 _callback = callback; | 19 _callback = callback; |
20 _expectJson = expectJson; | 20 _expectJson = expectJson; |
(...skipping 18 matching lines...) Expand all Loading... |
39 } else { | 39 } else { |
40 return stream.toBytes().then((data) { | 40 return stream.toBytes().then((data) { |
41 return _callback(request, data); | 41 return _callback(request, data); |
42 }); | 42 }); |
43 } | 43 } |
44 } | 44 } |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 http.StreamedResponse stringResponse( | 48 http.StreamedResponse stringResponse( |
49 core.int status, core.Map headers, core.String body) { | 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)]); | 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
51 return new http.StreamedResponse(stream, status, headers: headers); | 51 return new http.StreamedResponse(stream, status, headers: headers); |
52 } | 52 } |
53 | 53 |
54 core.int buildCounterAmpUrl = 0; | 54 core.int buildCounterAmpUrl = 0; |
55 buildAmpUrl() { | 55 buildAmpUrl() { |
56 var o = new api.AmpUrl(); | 56 var o = new api.AmpUrl(); |
57 buildCounterAmpUrl++; | 57 buildCounterAmpUrl++; |
58 if (buildCounterAmpUrl < 3) { | 58 if (buildCounterAmpUrl < 3) { |
59 o.ampUrl = "foo"; | 59 o.ampUrl = "foo"; |
(...skipping 30 matching lines...) Expand all Loading... |
90 checkAmpUrlError(api.AmpUrlError o) { | 90 checkAmpUrlError(api.AmpUrlError o) { |
91 buildCounterAmpUrlError++; | 91 buildCounterAmpUrlError++; |
92 if (buildCounterAmpUrlError < 3) { | 92 if (buildCounterAmpUrlError < 3) { |
93 unittest.expect(o.errorCode, unittest.equals('foo')); | 93 unittest.expect(o.errorCode, unittest.equals('foo')); |
94 unittest.expect(o.errorMessage, unittest.equals('foo')); | 94 unittest.expect(o.errorMessage, unittest.equals('foo')); |
95 unittest.expect(o.originalUrl, unittest.equals('foo')); | 95 unittest.expect(o.originalUrl, unittest.equals('foo')); |
96 } | 96 } |
97 buildCounterAmpUrlError--; | 97 buildCounterAmpUrlError--; |
98 } | 98 } |
99 | 99 |
100 buildUnnamed1172() { | 100 buildUnnamed1179() { |
101 var o = new core.List<core.String>(); | 101 var o = new core.List<core.String>(); |
102 o.add("foo"); | 102 o.add("foo"); |
103 o.add("foo"); | 103 o.add("foo"); |
104 return o; | 104 return o; |
105 } | 105 } |
106 | 106 |
107 checkUnnamed1172(core.List<core.String> o) { | 107 checkUnnamed1179(core.List<core.String> o) { |
108 unittest.expect(o, unittest.hasLength(2)); | 108 unittest.expect(o, unittest.hasLength(2)); |
109 unittest.expect(o[0], unittest.equals('foo')); | 109 unittest.expect(o[0], unittest.equals('foo')); |
110 unittest.expect(o[1], unittest.equals('foo')); | 110 unittest.expect(o[1], unittest.equals('foo')); |
111 } | 111 } |
112 | 112 |
113 core.int buildCounterBatchGetAmpUrlsRequest = 0; | 113 core.int buildCounterBatchGetAmpUrlsRequest = 0; |
114 buildBatchGetAmpUrlsRequest() { | 114 buildBatchGetAmpUrlsRequest() { |
115 var o = new api.BatchGetAmpUrlsRequest(); | 115 var o = new api.BatchGetAmpUrlsRequest(); |
116 buildCounterBatchGetAmpUrlsRequest++; | 116 buildCounterBatchGetAmpUrlsRequest++; |
117 if (buildCounterBatchGetAmpUrlsRequest < 3) { | 117 if (buildCounterBatchGetAmpUrlsRequest < 3) { |
118 o.lookupStrategy = "foo"; | 118 o.lookupStrategy = "foo"; |
119 o.urls = buildUnnamed1172(); | 119 o.urls = buildUnnamed1179(); |
120 } | 120 } |
121 buildCounterBatchGetAmpUrlsRequest--; | 121 buildCounterBatchGetAmpUrlsRequest--; |
122 return o; | 122 return o; |
123 } | 123 } |
124 | 124 |
125 checkBatchGetAmpUrlsRequest(api.BatchGetAmpUrlsRequest o) { | 125 checkBatchGetAmpUrlsRequest(api.BatchGetAmpUrlsRequest o) { |
126 buildCounterBatchGetAmpUrlsRequest++; | 126 buildCounterBatchGetAmpUrlsRequest++; |
127 if (buildCounterBatchGetAmpUrlsRequest < 3) { | 127 if (buildCounterBatchGetAmpUrlsRequest < 3) { |
128 unittest.expect(o.lookupStrategy, unittest.equals('foo')); | 128 unittest.expect(o.lookupStrategy, unittest.equals('foo')); |
129 checkUnnamed1172(o.urls); | 129 checkUnnamed1179(o.urls); |
130 } | 130 } |
131 buildCounterBatchGetAmpUrlsRequest--; | 131 buildCounterBatchGetAmpUrlsRequest--; |
132 } | 132 } |
133 | 133 |
134 buildUnnamed1173() { | 134 buildUnnamed1180() { |
135 var o = new core.List<api.AmpUrl>(); | 135 var o = new core.List<api.AmpUrl>(); |
136 o.add(buildAmpUrl()); | 136 o.add(buildAmpUrl()); |
137 o.add(buildAmpUrl()); | 137 o.add(buildAmpUrl()); |
138 return o; | 138 return o; |
139 } | 139 } |
140 | 140 |
141 checkUnnamed1173(core.List<api.AmpUrl> o) { | 141 checkUnnamed1180(core.List<api.AmpUrl> o) { |
142 unittest.expect(o, unittest.hasLength(2)); | 142 unittest.expect(o, unittest.hasLength(2)); |
143 checkAmpUrl(o[0]); | 143 checkAmpUrl(o[0]); |
144 checkAmpUrl(o[1]); | 144 checkAmpUrl(o[1]); |
145 } | 145 } |
146 | 146 |
147 buildUnnamed1174() { | 147 buildUnnamed1181() { |
148 var o = new core.List<api.AmpUrlError>(); | 148 var o = new core.List<api.AmpUrlError>(); |
149 o.add(buildAmpUrlError()); | 149 o.add(buildAmpUrlError()); |
150 o.add(buildAmpUrlError()); | 150 o.add(buildAmpUrlError()); |
151 return o; | 151 return o; |
152 } | 152 } |
153 | 153 |
154 checkUnnamed1174(core.List<api.AmpUrlError> o) { | 154 checkUnnamed1181(core.List<api.AmpUrlError> o) { |
155 unittest.expect(o, unittest.hasLength(2)); | 155 unittest.expect(o, unittest.hasLength(2)); |
156 checkAmpUrlError(o[0]); | 156 checkAmpUrlError(o[0]); |
157 checkAmpUrlError(o[1]); | 157 checkAmpUrlError(o[1]); |
158 } | 158 } |
159 | 159 |
160 core.int buildCounterBatchGetAmpUrlsResponse = 0; | 160 core.int buildCounterBatchGetAmpUrlsResponse = 0; |
161 buildBatchGetAmpUrlsResponse() { | 161 buildBatchGetAmpUrlsResponse() { |
162 var o = new api.BatchGetAmpUrlsResponse(); | 162 var o = new api.BatchGetAmpUrlsResponse(); |
163 buildCounterBatchGetAmpUrlsResponse++; | 163 buildCounterBatchGetAmpUrlsResponse++; |
164 if (buildCounterBatchGetAmpUrlsResponse < 3) { | 164 if (buildCounterBatchGetAmpUrlsResponse < 3) { |
165 o.ampUrls = buildUnnamed1173(); | 165 o.ampUrls = buildUnnamed1180(); |
166 o.urlErrors = buildUnnamed1174(); | 166 o.urlErrors = buildUnnamed1181(); |
167 } | 167 } |
168 buildCounterBatchGetAmpUrlsResponse--; | 168 buildCounterBatchGetAmpUrlsResponse--; |
169 return o; | 169 return o; |
170 } | 170 } |
171 | 171 |
172 checkBatchGetAmpUrlsResponse(api.BatchGetAmpUrlsResponse o) { | 172 checkBatchGetAmpUrlsResponse(api.BatchGetAmpUrlsResponse o) { |
173 buildCounterBatchGetAmpUrlsResponse++; | 173 buildCounterBatchGetAmpUrlsResponse++; |
174 if (buildCounterBatchGetAmpUrlsResponse < 3) { | 174 if (buildCounterBatchGetAmpUrlsResponse < 3) { |
175 checkUnnamed1173(o.ampUrls); | 175 checkUnnamed1180(o.ampUrls); |
176 checkUnnamed1174(o.urlErrors); | 176 checkUnnamed1181(o.urlErrors); |
177 } | 177 } |
178 buildCounterBatchGetAmpUrlsResponse--; | 178 buildCounterBatchGetAmpUrlsResponse--; |
179 } | 179 } |
180 | 180 |
181 | 181 |
182 main() { | 182 main() { |
183 unittest.group("obj-schema-AmpUrl", () { | 183 unittest.group("obj-schema-AmpUrl", () { |
184 unittest.test("to-json--from-json", () { | 184 unittest.test("to-json--from-json", () { |
185 var o = buildAmpUrl(); | 185 var o = buildAmpUrl(); |
186 var od = new api.AmpUrl.fromJson(o.toJson()); | 186 var od = new api.AmpUrl.fromJson(o.toJson()); |
(...skipping 28 matching lines...) Expand all Loading... |
215 }); | 215 }); |
216 }); | 216 }); |
217 | 217 |
218 | 218 |
219 unittest.group("resource-AmpUrlsResourceApi", () { | 219 unittest.group("resource-AmpUrlsResourceApi", () { |
220 unittest.test("method--batchGet", () { | 220 unittest.test("method--batchGet", () { |
221 | 221 |
222 var mock = new HttpServerMock(); | 222 var mock = new HttpServerMock(); |
223 api.AmpUrlsResourceApi res = new api.AcceleratedmobilepageurlApi(mock).amp
Urls; | 223 api.AmpUrlsResourceApi res = new api.AcceleratedmobilepageurlApi(mock).amp
Urls; |
224 var arg_request = buildBatchGetAmpUrlsRequest(); | 224 var arg_request = buildBatchGetAmpUrlsRequest(); |
225 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 225 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
226 var obj = new api.BatchGetAmpUrlsRequest.fromJson(json); | 226 var obj = new api.BatchGetAmpUrlsRequest.fromJson(json); |
227 checkBatchGetAmpUrlsRequest(obj); | 227 checkBatchGetAmpUrlsRequest(obj); |
228 | 228 |
229 var path = (req.url).path; | 229 var path = (req.url).path; |
230 var pathOffset = 0; | 230 var pathOffset = 0; |
231 var index; | 231 var index; |
232 var subPart; | 232 var subPart; |
233 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 233 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
234 pathOffset += 1; | 234 pathOffset += 1; |
235 unittest.expect(path.substring(pathOffset, pathOffset + 19), unittest.eq
uals("v1/ampUrls:batchGet")); | 235 unittest.expect(path.substring(pathOffset, pathOffset + 19), unittest.eq
uals("v1/ampUrls:batchGet")); |
(...skipping 16 matching lines...) Expand all Loading... |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 | 255 |
256 var h = { | 256 var h = { |
257 "content-type" : "application/json; charset=utf-8", | 257 "content-type" : "application/json; charset=utf-8", |
258 }; | 258 }; |
259 var resp = convert.JSON.encode(buildBatchGetAmpUrlsResponse()); | 259 var resp = convert.JSON.encode(buildBatchGetAmpUrlsResponse()); |
260 return new async.Future.value(stringResponse(200, h, resp)); | 260 return new async.Future.value(stringResponse(200, h, resp)); |
261 }), true); | 261 }), true); |
262 res.batchGet(arg_request).then(unittest.expectAsync(((api.BatchGetAmpUrlsR
esponse response) { | 262 res.batchGet(arg_request).then(unittest.expectAsync1(((api.BatchGetAmpUrls
Response response) { |
263 checkBatchGetAmpUrlsResponse(response); | 263 checkBatchGetAmpUrlsResponse(response); |
264 }))); | 264 }))); |
265 }); | 265 }); |
266 | 266 |
267 }); | 267 }); |
268 | 268 |
269 | 269 |
270 } | 270 } |
271 | 271 |
OLD | NEW |