| OLD | NEW |
| 1 library googleapis.webfonts.v1.test; | 1 library googleapis.webfonts.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:unittest/unittest.dart' as unittest; |
| 11 import 'package:googleapis/common/common.dart' as common; | |
| 12 import 'package:googleapis/src/common_internal.dart' as common_internal; | |
| 13 import '../common/common_internal_test.dart' as common_test; | |
| 14 | 11 |
| 15 import 'package:googleapis/webfonts/v1.dart' as api; | 12 import 'package:googleapis/webfonts/v1.dart' as api; |
| 16 | 13 |
| 14 class HttpServerMock extends http.BaseClient { |
| 15 core.Function _callback; |
| 16 core.bool _expectJson; |
| 17 | 17 |
| 18 void register(core.Function callback, core.bool expectJson) { |
| 19 _callback = callback; |
| 20 _expectJson = expectJson; |
| 21 } |
| 18 | 22 |
| 19 buildUnnamed1126() { | 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 buildUnnamed1398() { |
| 20 var o = new core.Map<core.String, core.String>(); | 55 var o = new core.Map<core.String, core.String>(); |
| 21 o["x"] = "foo"; | 56 o["x"] = "foo"; |
| 22 o["y"] = "foo"; | 57 o["y"] = "foo"; |
| 23 return o; | 58 return o; |
| 24 } | 59 } |
| 25 | 60 |
| 26 checkUnnamed1126(core.Map<core.String, core.String> o) { | 61 checkUnnamed1398(core.Map<core.String, core.String> o) { |
| 27 unittest.expect(o, unittest.hasLength(2)); | 62 unittest.expect(o, unittest.hasLength(2)); |
| 28 unittest.expect(o["x"], unittest.equals('foo')); | 63 unittest.expect(o["x"], unittest.equals('foo')); |
| 29 unittest.expect(o["y"], unittest.equals('foo')); | 64 unittest.expect(o["y"], unittest.equals('foo')); |
| 30 } | 65 } |
| 31 | 66 |
| 32 buildUnnamed1127() { | 67 buildUnnamed1399() { |
| 33 var o = new core.List<core.String>(); | 68 var o = new core.List<core.String>(); |
| 34 o.add("foo"); | 69 o.add("foo"); |
| 35 o.add("foo"); | 70 o.add("foo"); |
| 36 return o; | 71 return o; |
| 37 } | 72 } |
| 38 | 73 |
| 39 checkUnnamed1127(core.List<core.String> o) { | 74 checkUnnamed1399(core.List<core.String> o) { |
| 40 unittest.expect(o, unittest.hasLength(2)); | 75 unittest.expect(o, unittest.hasLength(2)); |
| 41 unittest.expect(o[0], unittest.equals('foo')); | 76 unittest.expect(o[0], unittest.equals('foo')); |
| 42 unittest.expect(o[1], unittest.equals('foo')); | 77 unittest.expect(o[1], unittest.equals('foo')); |
| 43 } | 78 } |
| 44 | 79 |
| 45 buildUnnamed1128() { | 80 buildUnnamed1400() { |
| 46 var o = new core.List<core.String>(); | 81 var o = new core.List<core.String>(); |
| 47 o.add("foo"); | 82 o.add("foo"); |
| 48 o.add("foo"); | 83 o.add("foo"); |
| 49 return o; | 84 return o; |
| 50 } | 85 } |
| 51 | 86 |
| 52 checkUnnamed1128(core.List<core.String> o) { | 87 checkUnnamed1400(core.List<core.String> o) { |
| 53 unittest.expect(o, unittest.hasLength(2)); | 88 unittest.expect(o, unittest.hasLength(2)); |
| 54 unittest.expect(o[0], unittest.equals('foo')); | 89 unittest.expect(o[0], unittest.equals('foo')); |
| 55 unittest.expect(o[1], unittest.equals('foo')); | 90 unittest.expect(o[1], unittest.equals('foo')); |
| 56 } | 91 } |
| 57 | 92 |
| 58 core.int buildCounterWebfont = 0; | 93 core.int buildCounterWebfont = 0; |
| 59 buildWebfont() { | 94 buildWebfont() { |
| 60 var o = new api.Webfont(); | 95 var o = new api.Webfont(); |
| 61 buildCounterWebfont++; | 96 buildCounterWebfont++; |
| 62 if (buildCounterWebfont < 3) { | 97 if (buildCounterWebfont < 3) { |
| 63 o.category = "foo"; | 98 o.category = "foo"; |
| 64 o.family = "foo"; | 99 o.family = "foo"; |
| 65 o.files = buildUnnamed1126(); | 100 o.files = buildUnnamed1398(); |
| 66 o.kind = "foo"; | 101 o.kind = "foo"; |
| 67 o.lastModified = core.DateTime.parse("2002-02-27T14:01:02Z"); | 102 o.lastModified = core.DateTime.parse("2002-02-27T14:01:02Z"); |
| 68 o.subsets = buildUnnamed1127(); | 103 o.subsets = buildUnnamed1399(); |
| 69 o.variants = buildUnnamed1128(); | 104 o.variants = buildUnnamed1400(); |
| 70 o.version = "foo"; | 105 o.version = "foo"; |
| 71 } | 106 } |
| 72 buildCounterWebfont--; | 107 buildCounterWebfont--; |
| 73 return o; | 108 return o; |
| 74 } | 109 } |
| 75 | 110 |
| 76 checkWebfont(api.Webfont o) { | 111 checkWebfont(api.Webfont o) { |
| 77 buildCounterWebfont++; | 112 buildCounterWebfont++; |
| 78 if (buildCounterWebfont < 3) { | 113 if (buildCounterWebfont < 3) { |
| 79 unittest.expect(o.category, unittest.equals('foo')); | 114 unittest.expect(o.category, unittest.equals('foo')); |
| 80 unittest.expect(o.family, unittest.equals('foo')); | 115 unittest.expect(o.family, unittest.equals('foo')); |
| 81 checkUnnamed1126(o.files); | 116 checkUnnamed1398(o.files); |
| 82 unittest.expect(o.kind, unittest.equals('foo')); | 117 unittest.expect(o.kind, unittest.equals('foo')); |
| 83 unittest.expect(o.lastModified, unittest.equals(core.DateTime.parse("2002-02
-27T00:00:00"))); | 118 unittest.expect(o.lastModified, unittest.equals(core.DateTime.parse("2002-02
-27T00:00:00"))); |
| 84 checkUnnamed1127(o.subsets); | 119 checkUnnamed1399(o.subsets); |
| 85 checkUnnamed1128(o.variants); | 120 checkUnnamed1400(o.variants); |
| 86 unittest.expect(o.version, unittest.equals('foo')); | 121 unittest.expect(o.version, unittest.equals('foo')); |
| 87 } | 122 } |
| 88 buildCounterWebfont--; | 123 buildCounterWebfont--; |
| 89 } | 124 } |
| 90 | 125 |
| 91 buildUnnamed1129() { | 126 buildUnnamed1401() { |
| 92 var o = new core.List<api.Webfont>(); | 127 var o = new core.List<api.Webfont>(); |
| 93 o.add(buildWebfont()); | 128 o.add(buildWebfont()); |
| 94 o.add(buildWebfont()); | 129 o.add(buildWebfont()); |
| 95 return o; | 130 return o; |
| 96 } | 131 } |
| 97 | 132 |
| 98 checkUnnamed1129(core.List<api.Webfont> o) { | 133 checkUnnamed1401(core.List<api.Webfont> o) { |
| 99 unittest.expect(o, unittest.hasLength(2)); | 134 unittest.expect(o, unittest.hasLength(2)); |
| 100 checkWebfont(o[0]); | 135 checkWebfont(o[0]); |
| 101 checkWebfont(o[1]); | 136 checkWebfont(o[1]); |
| 102 } | 137 } |
| 103 | 138 |
| 104 core.int buildCounterWebfontList = 0; | 139 core.int buildCounterWebfontList = 0; |
| 105 buildWebfontList() { | 140 buildWebfontList() { |
| 106 var o = new api.WebfontList(); | 141 var o = new api.WebfontList(); |
| 107 buildCounterWebfontList++; | 142 buildCounterWebfontList++; |
| 108 if (buildCounterWebfontList < 3) { | 143 if (buildCounterWebfontList < 3) { |
| 109 o.items = buildUnnamed1129(); | 144 o.items = buildUnnamed1401(); |
| 110 o.kind = "foo"; | 145 o.kind = "foo"; |
| 111 } | 146 } |
| 112 buildCounterWebfontList--; | 147 buildCounterWebfontList--; |
| 113 return o; | 148 return o; |
| 114 } | 149 } |
| 115 | 150 |
| 116 checkWebfontList(api.WebfontList o) { | 151 checkWebfontList(api.WebfontList o) { |
| 117 buildCounterWebfontList++; | 152 buildCounterWebfontList++; |
| 118 if (buildCounterWebfontList < 3) { | 153 if (buildCounterWebfontList < 3) { |
| 119 checkUnnamed1129(o.items); | 154 checkUnnamed1401(o.items); |
| 120 unittest.expect(o.kind, unittest.equals('foo')); | 155 unittest.expect(o.kind, unittest.equals('foo')); |
| 121 } | 156 } |
| 122 buildCounterWebfontList--; | 157 buildCounterWebfontList--; |
| 123 } | 158 } |
| 124 | 159 |
| 125 | 160 |
| 126 main() { | 161 main() { |
| 127 unittest.group("obj-schema-Webfont", () { | 162 unittest.group("obj-schema-Webfont", () { |
| 128 unittest.test("to-json--from-json", () { | 163 unittest.test("to-json--from-json", () { |
| 129 var o = buildWebfont(); | 164 var o = buildWebfont(); |
| 130 var od = new api.Webfont.fromJson(o.toJson()); | 165 var od = new api.Webfont.fromJson(o.toJson()); |
| 131 checkWebfont(od); | 166 checkWebfont(od); |
| 132 }); | 167 }); |
| 133 }); | 168 }); |
| 134 | 169 |
| 135 | 170 |
| 136 unittest.group("obj-schema-WebfontList", () { | 171 unittest.group("obj-schema-WebfontList", () { |
| 137 unittest.test("to-json--from-json", () { | 172 unittest.test("to-json--from-json", () { |
| 138 var o = buildWebfontList(); | 173 var o = buildWebfontList(); |
| 139 var od = new api.WebfontList.fromJson(o.toJson()); | 174 var od = new api.WebfontList.fromJson(o.toJson()); |
| 140 checkWebfontList(od); | 175 checkWebfontList(od); |
| 141 }); | 176 }); |
| 142 }); | 177 }); |
| 143 | 178 |
| 144 | 179 |
| 145 unittest.group("resource-WebfontsResourceApi", () { | 180 unittest.group("resource-WebfontsResourceApi", () { |
| 146 unittest.test("method--list", () { | 181 unittest.test("method--list", () { |
| 147 | 182 |
| 148 var mock = new common_test.HttpServerMock(); | 183 var mock = new HttpServerMock(); |
| 149 api.WebfontsResourceApi res = new api.WebfontsApi(mock).webfonts; | 184 api.WebfontsResourceApi res = new api.WebfontsApi(mock).webfonts; |
| 150 var arg_sort = "foo"; | 185 var arg_sort = "foo"; |
| 151 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 186 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 152 var path = (req.url).path; | 187 var path = (req.url).path; |
| 153 var pathOffset = 0; | 188 var pathOffset = 0; |
| 154 var index; | 189 var index; |
| 155 var subPart; | 190 var subPart; |
| 156 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 191 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 157 pathOffset += 1; | 192 pathOffset += 1; |
| 158 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("webfonts/v1/")); | 193 unittest.expect(path.substring(pathOffset, pathOffset + 12), unittest.eq
uals("webfonts/v1/")); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 176 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 211 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 177 } | 212 } |
| 178 } | 213 } |
| 179 unittest.expect(queryMap["sort"].first, unittest.equals(arg_sort)); | 214 unittest.expect(queryMap["sort"].first, unittest.equals(arg_sort)); |
| 180 | 215 |
| 181 | 216 |
| 182 var h = { | 217 var h = { |
| 183 "content-type" : "application/json; charset=utf-8", | 218 "content-type" : "application/json; charset=utf-8", |
| 184 }; | 219 }; |
| 185 var resp = convert.JSON.encode(buildWebfontList()); | 220 var resp = convert.JSON.encode(buildWebfontList()); |
| 186 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 221 return new async.Future.value(stringResponse(200, h, resp)); |
| 187 }), true); | 222 }), true); |
| 188 res.list(sort: arg_sort).then(unittest.expectAsync(((api.WebfontList respo
nse) { | 223 res.list(sort: arg_sort).then(unittest.expectAsync(((api.WebfontList respo
nse) { |
| 189 checkWebfontList(response); | 224 checkWebfontList(response); |
| 190 }))); | 225 }))); |
| 191 }); | 226 }); |
| 192 | 227 |
| 193 }); | 228 }); |
| 194 | 229 |
| 195 | 230 |
| 196 } | 231 } |
| 197 | 232 |
| OLD | NEW |