| OLD | NEW |
| 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 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 | 143 |
| 144 @reflectiveTest | 144 @reflectiveTest |
| 145 class RequestTest { | 145 class RequestTest { |
| 146 void test_fromJson() { | 146 void test_fromJson() { |
| 147 Request original = new Request('one', 'aMethod'); | 147 Request original = new Request('one', 'aMethod'); |
| 148 String json = JSON.encode(original.toJson()); | 148 String json = JSON.encode(original.toJson()); |
| 149 Request request = new Request.fromString(json); | 149 Request request = new Request.fromString(json); |
| 150 expect(request.id, equals('one')); | 150 expect(request.id, equals('one')); |
| 151 expect(request.method, equals('aMethod')); | 151 expect(request.method, equals('aMethod')); |
| 152 expect(request.clientRequestTime, isNull); |
| 152 } | 153 } |
| 153 | 154 |
| 154 void test_fromJson_invalidId() { | 155 void test_fromJson_invalidId() { |
| 155 String json = | 156 String json = |
| 156 '{"id":{"one":"two"},"method":"aMethod","params":{"foo":"bar"}}'; | 157 '{"id":{"one":"two"},"method":"aMethod","params":{"foo":"bar"}}'; |
| 157 Request request = new Request.fromString(json); | 158 Request request = new Request.fromString(json); |
| 158 expect(request, isNull); | 159 expect(request, isNull); |
| 159 } | 160 } |
| 160 | 161 |
| 161 void test_fromJson_invalidMethod() { | 162 void test_fromJson_invalidMethod() { |
| 162 String json = | 163 String json = |
| 163 '{"id":"one","method":{"boo":"aMethod"},"params":{"foo":"bar"}}'; | 164 '{"id":"one","method":{"boo":"aMethod"},"params":{"foo":"bar"}}'; |
| 164 Request request = new Request.fromString(json); | 165 Request request = new Request.fromString(json); |
| 165 expect(request, isNull); | 166 expect(request, isNull); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void test_fromJson_invalidParams() { | 169 void test_fromJson_invalidParams() { |
| 169 String json = '{"id":"one","method":"aMethod","params":"foobar"}'; | 170 String json = '{"id":"one","method":"aMethod","params":"foobar"}'; |
| 170 Request request = new Request.fromString(json); | 171 Request request = new Request.fromString(json); |
| 171 expect(request, isNull); | 172 expect(request, isNull); |
| 172 } | 173 } |
| 173 | 174 |
| 175 void test_fromJson_withBadClientTime() { |
| 176 Request original = new Request('one', 'aMethod', null, 347); |
| 177 Map<String, Object> map = original.toJson(); |
| 178 // Insert bad value - should be int but client sent string instead |
| 179 map[Request.CLIENT_REQUEST_TIME] = '347'; |
| 180 String json = JSON.encode(map); |
| 181 Request request = new Request.fromString(json); |
| 182 expect(request, isNull); |
| 183 } |
| 184 |
| 185 void test_fromJson_withClientTime() { |
| 186 Request original = new Request('one', 'aMethod', null, 347); |
| 187 String json = JSON.encode(original.toJson()); |
| 188 Request request = new Request.fromString(json); |
| 189 expect(request.id, equals('one')); |
| 190 expect(request.method, equals('aMethod')); |
| 191 expect(request.clientRequestTime, 347); |
| 192 } |
| 193 |
| 174 void test_fromJson_withParams() { | 194 void test_fromJson_withParams() { |
| 175 Request original = new Request('one', 'aMethod', { | 195 Request original = new Request('one', 'aMethod', { |
| 176 'foo': 'bar' | 196 'foo': 'bar' |
| 177 }); | 197 }); |
| 178 String json = JSON.encode(original.toJson()); | 198 String json = JSON.encode(original.toJson()); |
| 179 Request request = new Request.fromString(json); | 199 Request request = new Request.fromString(json); |
| 180 expect(request.id, equals('one')); | 200 expect(request.id, equals('one')); |
| 181 expect(request.method, equals('aMethod')); | 201 expect(request.method, equals('aMethod')); |
| 182 expect(request.toJson()['params'], equals({ | 202 expect(request.toJson()['params'], equals({ |
| 183 'foo': 'bar' | 203 'foo': 'bar' |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 expect(response.toJson(), equals({ | 236 expect(response.toJson(), equals({ |
| 217 Response.ID: '', | 237 Response.ID: '', |
| 218 Response.ERROR: { | 238 Response.ERROR: { |
| 219 'code': 'INVALID_REQUEST', | 239 'code': 'INVALID_REQUEST', |
| 220 'message': 'Invalid request' | 240 'message': 'Invalid request' |
| 221 } | 241 } |
| 222 })); | 242 })); |
| 223 } | 243 } |
| 224 | 244 |
| 225 void test_create_unanalyzedPriorityFiles() { | 245 void test_create_unanalyzedPriorityFiles() { |
| 226 Response response = | 246 Response response = new Response.unanalyzedPriorityFiles('0', 'file list'); |
| 227 new Response.unanalyzedPriorityFiles('0', 'file list'); | |
| 228 expect(response.id, equals('0')); | 247 expect(response.id, equals('0')); |
| 229 expect(response.error, isNotNull); | 248 expect(response.error, isNotNull); |
| 230 expect(response.toJson(), equals({ | 249 expect(response.toJson(), equals({ |
| 231 Response.ID: '0', | 250 Response.ID: '0', |
| 232 Response.ERROR: { | 251 Response.ERROR: { |
| 233 'code': 'UNANALYZED_PRIORITY_FILES', | 252 'code': 'UNANALYZED_PRIORITY_FILES', |
| 234 'message': "Unanalyzed files cannot be a priority: 'file list'" | 253 'message': "Unanalyzed files cannot be a priority: 'file list'" |
| 235 } | 254 } |
| 236 })); | 255 })); |
| 237 } | 256 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 Response original = new Response('myId', result: { | 288 Response original = new Response('myId', result: { |
| 270 'foo': 'bar' | 289 'foo': 'bar' |
| 271 }); | 290 }); |
| 272 Response response = new Response.fromJson(original.toJson()); | 291 Response response = new Response.fromJson(original.toJson()); |
| 273 expect(response.id, equals('myId')); | 292 expect(response.id, equals('myId')); |
| 274 Map<String, Object> result = response.toJson()['result']; | 293 Map<String, Object> result = response.toJson()['result']; |
| 275 expect(result.length, equals(1)); | 294 expect(result.length, equals(1)); |
| 276 expect(result['foo'], equals('bar')); | 295 expect(result['foo'], equals('bar')); |
| 277 } | 296 } |
| 278 } | 297 } |
| OLD | NEW |