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 library json_rpc_2.test.server.server_test; | 5 library json_rpc_2.test.server.server_test; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 import 'package:json_rpc_2/error_code.dart' as error_code; | 10 import 'package:json_rpc_2/error_code.dart' as error_code; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 test("doesn't return a result for a notification", () { | 85 test("doesn't return a result for a notification", () { |
86 server.registerMethod('foo', (args) => 'result'); | 86 server.registerMethod('foo', (args) => 'result'); |
87 | 87 |
88 expect(server.handleRequest({ | 88 expect(server.handleRequest({ |
89 'jsonrpc': '2.0', | 89 'jsonrpc': '2.0', |
90 'method': 'foo', | 90 'method': 'foo', |
91 'params': {} | 91 'params': {} |
92 }), completion(isNull)); | 92 }), completion(isNull)); |
93 }); | 93 }); |
94 | 94 |
| 95 test("includes the error data in the response", () { |
| 96 server.registerMethod('foo', (params) { |
| 97 throw new json_rpc.RpcException(5, 'Error message.', data: 'data value'); |
| 98 }); |
| 99 |
| 100 expectErrorResponse(server, { |
| 101 'jsonrpc': '2.0', |
| 102 'method': 'foo', |
| 103 'params': {}, |
| 104 'id': 1234 |
| 105 }, |
| 106 5, |
| 107 'Error message.', |
| 108 data: 'data value'); |
| 109 }); |
| 110 |
95 group("JSON", () { | 111 group("JSON", () { |
96 test("handles a request parsed from JSON", () { | 112 test("handles a request parsed from JSON", () { |
97 server.registerMethod('foo', (params) { | 113 server.registerMethod('foo', (params) { |
98 return {'params': params.value}; | 114 return {'params': params.value}; |
99 }); | 115 }); |
100 | 116 |
101 expect(server.parseRequest(JSON.encode({ | 117 expect(server.parseRequest(JSON.encode({ |
102 'jsonrpc': '2.0', | 118 'jsonrpc': '2.0', |
103 'method': 'foo', | 119 'method': 'foo', |
104 'params': {'param': 'value'}, | 120 'params': {'param': 'value'}, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 210 } |
195 })); | 211 })); |
196 }); | 212 }); |
197 }); | 213 }); |
198 | 214 |
199 test("disallows multiple methods with the same name", () { | 215 test("disallows multiple methods with the same name", () { |
200 server.registerMethod('foo', () => null); | 216 server.registerMethod('foo', () => null); |
201 expect(() => server.registerMethod('foo', () => null), throwsArgumentError); | 217 expect(() => server.registerMethod('foo', () => null), throwsArgumentError); |
202 }); | 218 }); |
203 } | 219 } |
OLD | NEW |