OLD | NEW |
1 library googleapis.admin.email_migration_v2.test; | 1 library googleapis.admin.email_migration_v2.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/admin/email_migration_v2.dart' as api; | 12 import 'package:googleapis/admin/email_migration_v2.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 buildUnnamed0() { | 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 buildUnnamed120() { |
20 var o = new core.List<core.String>(); | 55 var o = new core.List<core.String>(); |
21 o.add("foo"); | 56 o.add("foo"); |
22 o.add("foo"); | 57 o.add("foo"); |
23 return o; | 58 return o; |
24 } | 59 } |
25 | 60 |
26 checkUnnamed0(core.List<core.String> o) { | 61 checkUnnamed120(core.List<core.String> o) { |
27 unittest.expect(o, unittest.hasLength(2)); | 62 unittest.expect(o, unittest.hasLength(2)); |
28 unittest.expect(o[0], unittest.equals('foo')); | 63 unittest.expect(o[0], unittest.equals('foo')); |
29 unittest.expect(o[1], unittest.equals('foo')); | 64 unittest.expect(o[1], unittest.equals('foo')); |
30 } | 65 } |
31 | 66 |
32 core.int buildCounterMailItem = 0; | 67 core.int buildCounterMailItem = 0; |
33 buildMailItem() { | 68 buildMailItem() { |
34 var o = new api.MailItem(); | 69 var o = new api.MailItem(); |
35 buildCounterMailItem++; | 70 buildCounterMailItem++; |
36 if (buildCounterMailItem < 3) { | 71 if (buildCounterMailItem < 3) { |
37 o.isDeleted = true; | 72 o.isDeleted = true; |
38 o.isDraft = true; | 73 o.isDraft = true; |
39 o.isInbox = true; | 74 o.isInbox = true; |
40 o.isSent = true; | 75 o.isSent = true; |
41 o.isStarred = true; | 76 o.isStarred = true; |
42 o.isTrash = true; | 77 o.isTrash = true; |
43 o.isUnread = true; | 78 o.isUnread = true; |
44 o.kind = "foo"; | 79 o.kind = "foo"; |
45 o.labels = buildUnnamed0(); | 80 o.labels = buildUnnamed120(); |
46 } | 81 } |
47 buildCounterMailItem--; | 82 buildCounterMailItem--; |
48 return o; | 83 return o; |
49 } | 84 } |
50 | 85 |
51 checkMailItem(api.MailItem o) { | 86 checkMailItem(api.MailItem o) { |
52 buildCounterMailItem++; | 87 buildCounterMailItem++; |
53 if (buildCounterMailItem < 3) { | 88 if (buildCounterMailItem < 3) { |
54 unittest.expect(o.isDeleted, unittest.isTrue); | 89 unittest.expect(o.isDeleted, unittest.isTrue); |
55 unittest.expect(o.isDraft, unittest.isTrue); | 90 unittest.expect(o.isDraft, unittest.isTrue); |
56 unittest.expect(o.isInbox, unittest.isTrue); | 91 unittest.expect(o.isInbox, unittest.isTrue); |
57 unittest.expect(o.isSent, unittest.isTrue); | 92 unittest.expect(o.isSent, unittest.isTrue); |
58 unittest.expect(o.isStarred, unittest.isTrue); | 93 unittest.expect(o.isStarred, unittest.isTrue); |
59 unittest.expect(o.isTrash, unittest.isTrue); | 94 unittest.expect(o.isTrash, unittest.isTrue); |
60 unittest.expect(o.isUnread, unittest.isTrue); | 95 unittest.expect(o.isUnread, unittest.isTrue); |
61 unittest.expect(o.kind, unittest.equals('foo')); | 96 unittest.expect(o.kind, unittest.equals('foo')); |
62 checkUnnamed0(o.labels); | 97 checkUnnamed120(o.labels); |
63 } | 98 } |
64 buildCounterMailItem--; | 99 buildCounterMailItem--; |
65 } | 100 } |
66 | 101 |
67 | 102 |
68 main() { | 103 main() { |
69 unittest.group("obj-schema-MailItem", () { | 104 unittest.group("obj-schema-MailItem", () { |
70 unittest.test("to-json--from-json", () { | 105 unittest.test("to-json--from-json", () { |
71 var o = buildMailItem(); | 106 var o = buildMailItem(); |
72 var od = new api.MailItem.fromJson(o.toJson()); | 107 var od = new api.MailItem.fromJson(o.toJson()); |
73 checkMailItem(od); | 108 checkMailItem(od); |
74 }); | 109 }); |
75 }); | 110 }); |
76 | 111 |
77 | 112 |
78 unittest.group("resource-MailResourceApi", () { | 113 unittest.group("resource-MailResourceApi", () { |
79 unittest.test("method--insert", () { | 114 unittest.test("method--insert", () { |
80 // TODO: Implement tests for media upload; | 115 // TODO: Implement tests for media upload; |
81 // TODO: Implement tests for media download; | 116 // TODO: Implement tests for media download; |
82 | 117 |
83 var mock = new common_test.HttpServerMock(); | 118 var mock = new HttpServerMock(); |
84 api.MailResourceApi res = new api.AdminApi(mock).mail; | 119 api.MailResourceApi res = new api.AdminApi(mock).mail; |
85 var arg_request = buildMailItem(); | 120 var arg_request = buildMailItem(); |
86 var arg_userKey = "foo"; | 121 var arg_userKey = "foo"; |
87 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 122 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
88 var obj = new api.MailItem.fromJson(json); | 123 var obj = new api.MailItem.fromJson(json); |
89 checkMailItem(obj); | 124 checkMailItem(obj); |
90 | 125 |
91 var path = (req.url).path; | 126 var path = (req.url).path; |
92 var pathOffset = 0; | 127 var pathOffset = 0; |
93 var index; | 128 var index; |
(...skipping 16 matching lines...) Expand all Loading... |
110 var keyvalue = part.split("="); | 145 var keyvalue = part.split("="); |
111 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 146 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
112 } | 147 } |
113 } | 148 } |
114 | 149 |
115 | 150 |
116 var h = { | 151 var h = { |
117 "content-type" : "application/json; charset=utf-8", | 152 "content-type" : "application/json; charset=utf-8", |
118 }; | 153 }; |
119 var resp = ""; | 154 var resp = ""; |
120 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 155 return new async.Future.value(stringResponse(200, h, resp)); |
121 }), true); | 156 }), true); |
122 res.insert(arg_request, arg_userKey).then(unittest.expectAsync((_) {})); | 157 res.insert(arg_request, arg_userKey).then(unittest.expectAsync((_) {})); |
123 }); | 158 }); |
124 | 159 |
125 }); | 160 }); |
126 | 161 |
127 | 162 |
128 } | 163 } |
129 | 164 |
OLD | NEW |