OLD | NEW |
---|---|
(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 test.channel; | |
6 | |
7 import 'package:analysis_server/src/protocol.dart'; | |
8 import 'package:unittest/matcher.dart'; | |
9 import 'package:unittest/unittest.dart'; | |
10 import 'package:analysis_server/src/channel.dart'; | |
11 import 'mocks.dart'; | |
12 | |
13 main() { | |
14 test('invalidJsonToClient', ChannelTest.invalidJsonToClient); | |
Brian Wilkerson
2014/02/27 19:06:02
Put these in a group? I'm guessing that it will ma
danrubel
2014/02/27 20:21:14
Good point. Done.
| |
15 test('invalidJsonToServer', ChannelTest.invalidJsonToServer); | |
16 test('notification', ChannelTest.notification); | |
17 test('request', ChannelTest.request); | |
18 test('response', ChannelTest.response); | |
19 } | |
20 | |
21 class ChannelTest { | |
22 | |
23 static void invalidJsonToClient() { | |
24 InvalidJsonMockSocket mockSocket = new InvalidJsonMockSocket(); | |
25 WebSocketClientChannel client = new WebSocketClientChannel(mockSocket); | |
26 var responsesReceived = new List(); | |
27 var notificationsReceived = new List(); | |
28 client.listen((Response response) => responsesReceived.add(response), | |
29 (Notification notification) => notificationsReceived.add(notification)); | |
30 | |
31 mockSocket.addInvalid('"blat"'); | |
32 mockSocket.addInvalid('{foo:bar}'); | |
33 | |
34 expect(responsesReceived.length, equals(0)); | |
35 expect(notificationsReceived.length, equals(0)); | |
36 expect(mockSocket.responseCount, equals(0)); | |
37 } | |
38 | |
39 static void invalidJsonToServer() { | |
40 InvalidJsonMockSocket mockSocket = new InvalidJsonMockSocket(); | |
41 WebSocketServerChannel server = new WebSocketServerChannel(mockSocket); | |
42 var received = new List(); | |
43 server.listen((Request request) => received.add(request)); | |
44 | |
45 mockSocket.addInvalid('"blat"'); | |
46 mockSocket.addInvalid('{foo:bar}'); | |
47 | |
48 expect(received.length, equals(0)); | |
49 expect(mockSocket.responseCount, equals(2)); | |
50 } | |
51 | |
52 static void notification() { | |
53 MockSocket mockSocket = new MockSocket(); | |
54 WebSocketClientChannel client = new WebSocketClientChannel(mockSocket); | |
55 WebSocketServerChannel server = new WebSocketServerChannel(mockSocket); | |
56 var responsesReceived = new List(); | |
57 var notificationsReceived = new List(); | |
58 client.listen((Response response) => responsesReceived.add(response), | |
59 (Notification notification) => notificationsReceived.add(notification)); | |
60 | |
61 server.sendNotification(new Notification('myEvent')); | |
62 | |
63 expect(responsesReceived.length, equals(0)); | |
64 expect(notificationsReceived.length, equals(1)); | |
65 expect(notificationsReceived.first.runtimeType, equals(Notification)); | |
66 Notification actual = notificationsReceived.first; | |
67 expect(actual.event, equals('myEvent')); | |
68 } | |
69 | |
70 static void request() { | |
71 MockSocket mockSocket = new MockSocket(); | |
72 WebSocketClientChannel client = new WebSocketClientChannel(mockSocket); | |
73 WebSocketServerChannel server = new WebSocketServerChannel(mockSocket); | |
74 var requestsReceived = new List(); | |
75 server.listen((Request request) => requestsReceived.add(request)); | |
76 | |
77 client.sendRequest(new Request('myId', 'aMethod')); | |
78 | |
79 expect(requestsReceived.length, equals(1)); | |
80 expect(requestsReceived.first.runtimeType, equals(Request)); | |
81 Request actual = requestsReceived.first; | |
82 expect(actual.id, equals('myId')); | |
83 expect(actual.method, equals('aMethod')); | |
84 } | |
85 | |
86 static void response() { | |
87 MockSocket mockSocket = new MockSocket(); | |
88 WebSocketClientChannel client = new WebSocketClientChannel(mockSocket); | |
89 WebSocketServerChannel server = new WebSocketServerChannel(mockSocket); | |
90 var responsesReceived = new List(); | |
91 var notificationsReceived = new List(); | |
92 client.listen((Response response) => responsesReceived.add(response), | |
93 (Notification notification) => notificationsReceived.add(notification)); | |
94 | |
95 server.sendResponse(new Response('myId')); | |
96 | |
97 expect(responsesReceived.length, equals(1)); | |
98 expect(notificationsReceived.length, equals(0)); | |
99 expect(responsesReceived.first.runtimeType, equals(Response)); | |
100 Response actual = responsesReceived.first; | |
101 expect(actual.id, equals('myId')); | |
102 } | |
103 } | |
OLD | NEW |