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

Side by Side Diff: pkg/analysis_server/test/protocol_test.dart

Issue 182903005: split client and server channels (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments 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
« no previous file with comments | « pkg/analysis_server/test/mocks.dart ('k') | no next file » | 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 test.protocol; 5 library test.protocol;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:unittest/matcher.dart'; 8 import 'package:unittest/matcher.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 import 'dart:convert';
10 11
11 main() { 12 main() {
13 group('Notification', () {
14 test('getParameter_defined', NotificationTest.getParameter_defined);
15 test('getParameter_undefined', NotificationTest.getParameter_undefined);
16 test('fromJson', NotificationTest.fromJson);
17 test('fromJson_withParams', NotificationTest.fromJson_withParams);
18 });
12 group('Request', () { 19 group('Request', () {
13 test('getParameter_defined', RequestTest.getParameter_defined); 20 test('getParameter_defined', RequestTest.getParameter_defined);
14 test('getParameter_undefined', RequestTest.getParameter_undefined); 21 test('getParameter_undefined', RequestTest.getParameter_undefined);
15 test('getRequiredParameter_defined', RequestTest.getRequiredParameter_define d); 22 test('getRequiredParameter_defined', RequestTest.getRequiredParameter_define d);
16 test('getRequiredParameter_undefined', RequestTest.getRequiredParameter_unde fined); 23 test('getRequiredParameter_undefined', RequestTest.getRequiredParameter_unde fined);
24 test('fromJson', RequestTest.fromJson);
25 test('fromJson_withParams', RequestTest.fromJson_withParams);
17 test('toJson', RequestTest.toJson); 26 test('toJson', RequestTest.toJson);
27 test('toJson_withParams', RequestTest.toJson_withParams);
18 }); 28 });
19 group('Response', () { 29 group('Response', () {
20 test('create_contextDoesNotExist', ResponseTest.create_contextDoesNotExist); 30 test('create_contextDoesNotExist', ResponseTest.create_contextDoesNotExist);
21 test('create_invalidRequestFormat', ResponseTest.create_invalidRequestFormat ); 31 test('create_invalidRequestFormat', ResponseTest.create_invalidRequestFormat );
22 test('create_missingRequiredParameter', ResponseTest.create_missingRequiredP arameter); 32 test('create_missingRequiredParameter', ResponseTest.create_missingRequiredP arameter);
23 test('create_unknownRequest', ResponseTest.create_unknownRequest); 33 test('create_unknownRequest', ResponseTest.create_unknownRequest);
24 test('setResult', ResponseTest.setResult); 34 test('setResult', ResponseTest.setResult);
35 test('fromJson', ResponseTest.fromJson);
36 test('fromJson_withError', ResponseTest.fromJson_withError);
37 test('fromJson_withResult', ResponseTest.fromJson_withResult);
25 }); 38 });
26 } 39 }
27 40
41 class NotificationTest {
42 static void getParameter_defined() {
43 Notification notification = new Notification('foo');
44 notification.setParameter('x', 'y');
45 expect(notification.event, equals('foo'));
46 expect(notification.params.length, equals(1));
47 expect(notification.getParameter('x'), equals('y'));
48 expect(notification.toJson(), equals({
49 'event' : 'foo',
50 'params' : {'x' : 'y'}
51 }));
52 }
53
54 static void getParameter_undefined() {
55 Notification notification = new Notification('foo');
56 expect(notification.event, equals('foo'));
57 expect(notification.params.length, equals(0));
58 expect(notification.getParameter('x'), isNull);
59 expect(notification.toJson(), equals({
60 'event' : 'foo'
61 }));
62 }
63
64 static void fromJson() {
65 Notification original = new Notification('foo');
66 Notification notification = new Notification.fromJson(original.toJson());
67 expect(notification.event, equals('foo'));
68 expect(notification.params.length, equals(0));
69 expect(notification.getParameter('x'), isNull);
70 }
71
72 static void fromJson_withParams() {
73 Notification original = new Notification('foo');
74 original.setParameter('x', 'y');
75 Notification notification = new Notification.fromJson(original.toJson());
76 expect(notification.event, equals('foo'));
77 expect(notification.params.length, equals(1));
78 expect(notification.getParameter('x'), equals('y'));
79 }
80 }
81
28 class RequestTest { 82 class RequestTest {
29 static void getParameter_defined() { 83 static void getParameter_defined() {
30 String name = 'name'; 84 String name = 'name';
31 String value = 'value'; 85 String value = 'value';
32 Request request = new Request('0', ''); 86 Request request = new Request('0', '');
33 request.setParameter(name, value); 87 request.setParameter(name, value);
34 expect(request.getParameter(name), equals(value)); 88 expect(request.getParameter(name), equals(value));
35 } 89 }
36 90
37 static void getParameter_undefined() { 91 static void getParameter_undefined() {
38 String name = 'name'; 92 String name = 'name';
39 Request request = new Request('0', ''); 93 Request request = new Request('0', '');
40 expect(request.getParameter(name), isNull); 94 expect(request.getParameter(name), isNull);
41 } 95 }
42 96
43 static void getRequiredParameter_defined() { 97 static void getRequiredParameter_defined() {
44 String name = 'name'; 98 String name = 'name';
45 String value = 'value'; 99 String value = 'value';
46 Request request = new Request('0', ''); 100 Request request = new Request('0', '');
47 request.setParameter(name, value); 101 request.setParameter(name, value);
48 expect(request.getRequiredParameter(name), equals(value)); 102 expect(request.getRequiredParameter(name), equals(value));
49 } 103 }
50 104
51 static void getRequiredParameter_undefined() { 105 static void getRequiredParameter_undefined() {
52 String name = 'name'; 106 String name = 'name';
53 Request request = new Request('0', ''); 107 Request request = new Request('0', '');
54 expect(() => request.getRequiredParameter(name), throwsA(new isInstanceOf<Re questFailure>())); 108 expect(() => request.getRequiredParameter(name), throwsA(new isInstanceOf<Re questFailure>()));
55 } 109 }
56 110
111 static void fromJson() {
112 Request original = new Request('one', 'aMethod');
113 String json = new JsonEncoder(null).convert(original.toJson());
114 Request request = new Request.fromString(json);
115 expect(request.id, equals('one'));
116 expect(request.method, equals('aMethod'));
117 }
118
119 static void fromJson_withParams() {
120 Request original = new Request('one', 'aMethod');
121 original.setParameter('foo', 'bar');
122 String json = new JsonEncoder(null).convert(original.toJson());
123 Request request = new Request.fromString(json);
124 expect(request.id, equals('one'));
125 expect(request.method, equals('aMethod'));
126 expect(request.getParameter('foo'), equals('bar'));
127 }
128
57 static void toJson() { 129 static void toJson() {
58 Request original = new Request('one', 'aMethod'); 130 Request request = new Request('one', 'aMethod');
59 expect(original.toJson(), equals({ 131 expect(request.toJson(), equals({
60 Request.ID: 'one', 132 Request.ID : 'one',
61 Request.METHOD : 'aMethod' 133 Request.METHOD : 'aMethod'
62 })); 134 }));
63 } 135 }
136
137 static void toJson_withParams() {
138 Request request = new Request('one', 'aMethod');
139 request.setParameter('foo', 'bar');
140 expect(request.toJson(), equals({
141 Request.ID : 'one',
142 Request.METHOD : 'aMethod',
143 Request.PARAMS : {'foo' : 'bar'}
144 }));
145 }
64 } 146 }
65 147
66 class ResponseTest { 148 class ResponseTest {
67 static void create_contextDoesNotExist() { 149 static void create_contextDoesNotExist() {
68 Response response = new Response.contextDoesNotExist(new Request('0', '')); 150 Response response = new Response.contextDoesNotExist(new Request('0', ''));
69 expect(response.id, equals('0')); 151 expect(response.id, equals('0'));
70 expect(response.error, isNotNull); 152 expect(response.error, isNotNull);
71 expect(response.toJson(), equals({ 153 expect(response.toJson(), equals({
72 Response.ID: '0', 154 Response.ID: '0',
73 Response.ERROR: {'code': -1, 'message': 'Context does not exist'} 155 Response.ERROR: {'code': -1, 'message': 'Context does not exist'}
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 Response response = new Response('0'); 192 Response response = new Response('0');
111 response.setResult(resultName, resultValue); 193 response.setResult(resultName, resultValue);
112 expect(response.toJson(), equals({ 194 expect(response.toJson(), equals({
113 Response.ID: '0', 195 Response.ID: '0',
114 Response.ERROR: null, 196 Response.ERROR: null,
115 Response.RESULT: { 197 Response.RESULT: {
116 resultName: resultValue 198 resultName: resultValue
117 } 199 }
118 })); 200 }));
119 } 201 }
202
203 static void fromJson() {
204 Response original = new Response('myId');
205 Response response = new Response.fromJson(original.toJson());
206 expect(response.id, equals('myId'));
207 }
208
209 static void fromJson_withError() {
210 Response original = new Response.invalidRequestFormat();
211 Response response = new Response.fromJson(original.toJson());
212 expect(response.id, equals(''));
213 expect(response.error, isNotNull);
214 RequestError error = response.error;
215 expect(error.code, equals(-4));
216 expect(error.message, equals('Invalid request'));
217 }
218
219 static void fromJson_withResult() {
220 Response original = new Response('myId');
221 original.setResult('foo', 'bar');
222 Response response = new Response.fromJson(original.toJson());
223 expect(response.id, equals('myId'));
224 Map<String, Object> result = response.result;
225 expect(result.length, equals(1));
226 expect(result['foo'], equals('bar'));
227 }
120 } 228 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/mocks.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698