Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1369)

Side by Side Diff: pkg/json_rpc_2/test/server/server_test.dart

Issue 224903010: Pass RpcException error data through if it's not a map. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/json_rpc_2/test/server/parameters_test.dart ('k') | pkg/json_rpc_2/test/server/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « pkg/json_rpc_2/test/server/parameters_test.dart ('k') | pkg/json_rpc_2/test/server/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698