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

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

Issue 812253002: Delete a bunch of packages that are now on GitHub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Un-delete http Created 6 years 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library json_rpc_2.test.server.batch_test;
6
7 import 'dart:convert';
8
9 import 'package:unittest/unittest.dart';
10 import 'package:json_rpc_2/error_code.dart' as error_code;
11 import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
12
13 import 'utils.dart';
14
15 void main() {
16 var controller;
17 setUp(() {
18 controller = new ServerController();
19 controller.server
20 ..registerMethod('foo', () => 'foo')
21 ..registerMethod('id', (params) => params.value)
22 ..registerMethod('arg', (params) => params['arg'].value);
23 });
24
25 test('handles a batch of requests', () {
26 expect(controller.handleRequest([
27 {'jsonrpc': '2.0', 'method': 'foo', 'id': 1},
28 {'jsonrpc': '2.0', 'method': 'id', 'params': ['value'], 'id': 2},
29 {'jsonrpc': '2.0', 'method': 'arg', 'params': {'arg': 'value'}, 'id': 3}
30 ]), completion(equals([
31 {'jsonrpc': '2.0', 'result': 'foo', 'id': 1},
32 {'jsonrpc': '2.0', 'result': ['value'], 'id': 2},
33 {'jsonrpc': '2.0', 'result': 'value', 'id': 3}
34 ])));
35 });
36
37 test('handles errors individually', () {
38 expect(controller.handleRequest([
39 {'jsonrpc': '2.0', 'method': 'foo', 'id': 1},
40 {'jsonrpc': '2.0', 'method': 'zap', 'id': 2},
41 {'jsonrpc': '2.0', 'method': 'arg', 'params': {'arg': 'value'}, 'id': 3}
42 ]), completion(equals([
43 {'jsonrpc': '2.0', 'result': 'foo', 'id': 1},
44 {
45 'jsonrpc': '2.0',
46 'id': 2,
47 'error': {
48 'code': error_code.METHOD_NOT_FOUND,
49 'message': 'Unknown method "zap".',
50 'data': {'request': {'jsonrpc': '2.0', 'method': 'zap', 'id': 2}},
51 }
52 },
53 {'jsonrpc': '2.0', 'result': 'value', 'id': 3}
54 ])));
55 });
56
57 test('handles notifications individually', () {
58 expect(controller.handleRequest([
59 {'jsonrpc': '2.0', 'method': 'foo', 'id': 1},
60 {'jsonrpc': '2.0', 'method': 'id', 'params': ['value']},
61 {'jsonrpc': '2.0', 'method': 'arg', 'params': {'arg': 'value'}, 'id': 3}
62 ]), completion(equals([
63 {'jsonrpc': '2.0', 'result': 'foo', 'id': 1},
64 {'jsonrpc': '2.0', 'result': 'value', 'id': 3}
65 ])));
66 });
67
68 test('returns nothing if every request is a notification', () {
69 expect(controller.handleRequest([
70 {'jsonrpc': '2.0', 'method': 'foo'},
71 {'jsonrpc': '2.0', 'method': 'id', 'params': ['value']},
72 {'jsonrpc': '2.0', 'method': 'arg', 'params': {'arg': 'value'}}
73 ]), completion(isNull));
74 });
75
76 test('returns an error if the batch is empty', () {
77 expectErrorResponse(controller, [], error_code.INVALID_REQUEST,
78 'A batch must contain at least one request.');
79 });
80
81 test('disallows nested batches', () {
82 expect(controller.handleRequest([
83 [{'jsonrpc': '2.0', 'method': 'foo', 'id': 1}]
84 ]), completion(equals([{
85 'jsonrpc': '2.0',
86 'id': null,
87 'error': {
88 'code': error_code.INVALID_REQUEST,
89 'message': 'Request must be an Array or an Object.',
90 'data': {'request': [{'jsonrpc': '2.0', 'method': 'foo', 'id': 1}]}
91 }
92 }])));
93 });
94 }
OLDNEW
« no previous file with comments | « pkg/json_rpc_2/test/peer_test.dart ('k') | pkg/json_rpc_2/test/server/invalid_request_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698