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

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

Issue 205533005: Create a package that implements a JSON-RPC 2.0 server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 9 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
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.invalid_request_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 server;
17 setUp(() => server = new json_rpc.Server());
18
19 test("a non-Array/Object request is invalid", () {
20 expectErrorResponse(server, 'foo', error_code.INVALID_REQUEST,
21 'Request must be an Array or an Object.');
22 });
23
24 test("requests must have a jsonrpc key", () {
25 expectErrorResponse(server, {
26 'method': 'foo',
27 'id': 1234
28 }, error_code.INVALID_REQUEST, 'Request must contain a "jsonrpc" key.');
29 });
30
31 test("the jsonrpc version must be 2.0", () {
32 expectErrorResponse(server, {
33 'jsonrpc': '1.0',
34 'method': 'foo',
35 'id': 1234
36 }, error_code.INVALID_REQUEST,
37 'Invalid JSON-RPC version "1.0", expected "2.0".');
38 });
39
40 test("requests must have a method key", () {
41 expectErrorResponse(server, {
42 'jsonrpc': '2.0',
43 'id': 1234
44 }, error_code.INVALID_REQUEST, 'Request must contain a "method" key.');
45 });
46
47 test("request method must be a string", () {
48 expectErrorResponse(server, {
49 'jsonrpc': '2.0',
50 'method': 1234,
51 'id': 1234
52 }, error_code.INVALID_REQUEST,
53 'Request method must be a string, but was 1234.');
54 });
55
56 test("request params must be an Array or Object", () {
57 expectErrorResponse(server, {
58 'jsonrpc': '2.0',
59 'method': 'foo',
60 'params': 1234,
61 'id': 1234
62 }, error_code.INVALID_REQUEST,
63 'Request params must be an Array or an Object, but was 1234.');
64 });
65
66 test("request id may not be an Array or Object", () {
67 expect(server.handleRequest({
68 'jsonrpc': '2.0',
69 'method': 'foo',
70 'id': {'bad': 'id'}
71 }), completion(equals({
72 'jsonrpc': '2.0',
73 'id': null,
74 'error': {
75 'code': error_code.INVALID_REQUEST,
76 'message': 'Request id must be a string, number, or null, but was '
77 '{"bad":"id"}.',
78 'data': {'request': {
79 'jsonrpc': '2.0',
80 'method': 'foo',
81 'id': {'bad': 'id'}
82 }}
83 }
84 })));
85 });
86 }
OLDNEW
« no previous file with comments | « pkg/json_rpc_2/test/server/batch_test.dart ('k') | pkg/json_rpc_2/test/server/parameters_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698