OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 | 7 |
| 8 import 'package:stream_channel/stream_channel.dart'; |
8 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
| 10 |
9 import 'package:json_rpc_2/error_code.dart' as error_code; | 11 import 'package:json_rpc_2/error_code.dart' as error_code; |
10 import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc; | 12 import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc; |
11 | 13 |
12 void main() { | 14 void main() { |
13 var incoming; | 15 var incoming; |
14 var outgoing; | 16 var outgoing; |
15 var peer; | 17 var peer; |
16 setUp(() { | 18 setUp(() { |
17 var incomingController = new StreamController(); | 19 var incomingController = new StreamController(); |
18 incoming = incomingController.sink; | 20 incoming = incomingController.sink; |
19 var outgoingController = new StreamController(); | 21 var outgoingController = new StreamController(); |
20 outgoing = outgoingController.stream; | 22 outgoing = outgoingController.stream; |
21 peer = new json_rpc.Peer.withoutJson( | 23 peer = new json_rpc.Peer.withoutJson( |
22 incomingController.stream, outgoingController); | 24 new StreamChannel(incomingController.stream, outgoingController)); |
23 }); | 25 }); |
24 | 26 |
25 group("like a client,", () { | 27 group("like a client,", () { |
26 test("can send a message and receive a response", () { | 28 test("can send a message and receive a response", () { |
27 expect(outgoing.first.then((request) { | 29 expect(outgoing.first.then((request) { |
28 expect(request, equals({ | 30 expect(request, equals({ |
29 "jsonrpc": "2.0", | 31 "jsonrpc": "2.0", |
30 "method": "foo", | 32 "method": "foo", |
31 "params": {"bar": "baz"}, | 33 "params": {"bar": "baz"}, |
32 "id": 0 | 34 "id": 0 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 "params": {"x": "y"}, | 160 "params": {"x": "y"}, |
159 "id": 2 | 161 "id": 2 |
160 } | 162 } |
161 ]); | 163 ]); |
162 }); | 164 }); |
163 | 165 |
164 test("returns a response for malformed JSON", () { | 166 test("returns a response for malformed JSON", () { |
165 var incomingController = new StreamController(); | 167 var incomingController = new StreamController(); |
166 var outgoingController = new StreamController(); | 168 var outgoingController = new StreamController(); |
167 var jsonPeer = new json_rpc.Peer( | 169 var jsonPeer = new json_rpc.Peer( |
168 incomingController.stream, outgoingController); | 170 new StreamChannel(incomingController.stream, outgoingController)); |
169 | 171 |
170 expect(outgoingController.stream.first.then(JSON.decode), completion({ | 172 expect(outgoingController.stream.first.then(JSON.decode), completion({ |
171 "jsonrpc": "2.0", | 173 "jsonrpc": "2.0", |
172 "error": { | 174 "error": { |
173 'code': error_code.PARSE_ERROR, | 175 'code': error_code.PARSE_ERROR, |
174 "message": startsWith("Invalid JSON: "), | 176 "message": startsWith("Invalid JSON: "), |
175 "data": {'request': '{invalid'} | 177 "data": {'request': '{invalid'} |
176 }, | 178 }, |
177 "id": null | 179 "id": null |
178 })); | 180 })); |
(...skipping 15 matching lines...) Expand all Loading... |
194 })); | 196 })); |
195 | 197 |
196 peer.listen(); | 198 peer.listen(); |
197 | 199 |
198 incoming.add({ | 200 incoming.add({ |
199 "completely": "wrong" | 201 "completely": "wrong" |
200 }); | 202 }); |
201 }); | 203 }); |
202 }); | 204 }); |
203 } | 205 } |
OLD | NEW |