protected NotificationMessage createNotificationMessage(String method, Object parameter) { NotificationMessage notificationMessage = new NotificationMessage(); notificationMessage.setJsonrpc(MessageConstants.JSONRPC_VERSION); notificationMessage.setMethod(method); notificationMessage.setParams(parameter); return notificationMessage; }
protected NotificationMessage createNotificationMessage(String method, Object parameter) { NotificationMessage notificationMessage = new NotificationMessage(); notificationMessage.setJsonrpc(MessageConstants.JSONRPC_VERSION); notificationMessage.setMethod(method); notificationMessage.setParams(parameter); return notificationMessage; }
public void notify(String method, Object parameter) { notifications.add(init(new NotificationMessage(), it -> { it.setMethod(method); it.setParams(parameter); })); }
@Test public void testSerializeImmutableList() { MessageJsonHandler handler = new MessageJsonHandler(Collections.emptyMap()); NotificationMessage message = new NotificationMessage(); message.setMethod("foo"); List<Object> list = new ArrayList<>(); list.add("a"); list.add("b"); message.setParams(Collections.unmodifiableList(list)); String json = handler.serialize(message); Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"method\":\"foo\",\"params\":[\"a\",\"b\"]}", json); }
@Test public void testSkipJsonElement() { final AtomicBoolean result = new AtomicBoolean(false); ReflectiveMessageValidator validator = new ReflectiveMessageValidator((message) -> { result.set(true); }); NotificationMessage message = new NotificationMessage(); message.setMethod("foo"); message.setParams(new JsonObject()); validator.consume(message); Assert.assertTrue(result.get()); }
@Test public void testSerializeEmptyList() { MessageJsonHandler handler = new MessageJsonHandler(Collections.emptyMap()); NotificationMessage message = new NotificationMessage(); message.setMethod("foo"); message.setParams(Collections.EMPTY_LIST); String json = handler.serialize(message); Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"method\":\"foo\",\"params\":[]}", json); }
protected Message createMessage(String jsonrpc, Either<String, Number> id, String method, Object params, Object responseResult, ResponseError responseError) throws JsonParseException { if (id != null && method != null) { RequestMessage message = new RequestMessage(); message.setJsonrpc(jsonrpc); message.setRawId(id); message.setMethod(method); message.setParams(params); return message; } else if (id != null) { ResponseMessage message = new ResponseMessage(); message.setJsonrpc(jsonrpc); message.setRawId(id); if (responseError != null) message.setError(responseError); else message.setResult(responseResult); return message; } else if (method != null) { NotificationMessage message = new NotificationMessage(); message.setJsonrpc(jsonrpc); message.setMethod(method); message.setParams(params); return message; } else { throw new JsonParseException("Unable to identify the input message."); } }
protected Message createMessage(String jsonrpc, Either<String, Number> id, String method, Object params, Object responseResult, ResponseError responseError) throws JsonParseException { if (id != null && method != null) { RequestMessage message = new RequestMessage(); message.setJsonrpc(jsonrpc); message.setRawId(id); message.setMethod(method); message.setParams(params); return message; } else if (id != null) { ResponseMessage message = new ResponseMessage(); message.setJsonrpc(jsonrpc); message.setRawId(id); if (responseError != null) message.setError(responseError); else message.setResult(responseResult); return message; } else if (method != null) { NotificationMessage message = new NotificationMessage(); message.setJsonrpc(jsonrpc); message.setMethod(method); message.setParams(params); return message; } else { throw new JsonParseException("Unable to identify the input message."); } }
@Test public void testNoViolation() { ReflectiveMessageValidator validator = new ReflectiveMessageValidator(); NotificationMessage message = new NotificationMessage(); message.setMethod("foo"); Foo foo = new Foo(); foo.nonNullString = "test"; foo.nested = new Foo() {{ nonNullString = "something"; }}; message.setParams(foo); validator.consume(message); }
@Test public void testReflectionOnPropertiesOnly() { ReflectiveMessageValidator validator = new ReflectiveMessageValidator(); NotificationMessage message = new NotificationMessage(); message.setMethod("foo"); Foo foo = new Foo(); foo.nonNullString = "test"; foo.nested = new Foo() {{ nonNullString = "something"; }}; foo.foos = new ArrayList<>(); foo.foos.add(new Foo()); message.setParams(foo); try { validator.consume(message); Assert.fail(); } catch (MessageIssueException e) { Assert.assertEquals("The accessor 'Foo.getNonNullString()' must return a non-null value. Path: $.params.foos[0].nonNullString", e.getMessage()); } }
@Test public void testNotification() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); endpoint.consume(init(new NotificationMessage(), it -> { it.setMethod("foo"); it.setParams("myparam"); })); NotificationMessage notificationMessage = endp.notifications.get(0); assertEquals("foo", notificationMessage.getMethod()); assertEquals("myparam", notificationMessage.getParams()); assertTrue(consumer.messages.isEmpty()); }
@Test public void testNonNullViolated() { ReflectiveMessageValidator validator = new ReflectiveMessageValidator(); NotificationMessage message = new NotificationMessage(); message.setMethod("foo"); message.setParams(new Foo()); try { validator.consume(message); Assert.fail(); } catch (MessageIssueException e) { Assert.assertEquals("The accessor 'Foo.getNonNullString()' must return a non-null value. Path: $.params.nonNullString", e.getMessage()); } }
@Test public void testRecursionViolation() { ReflectiveMessageValidator validator = new ReflectiveMessageValidator(); NotificationMessage message = new NotificationMessage(); message.setMethod("foo"); Foo foo = new Foo(); foo.nonNullString = "test"; foo.nested = foo; message.setParams(foo); try { validator.consume(message); Assert.fail(); } catch (MessageIssueException e) { Assert.assertEquals("An element of the message has a direct or indirect reference to itself. Path: $.params.nested", e.getMessage()); } }
@Test public void testNonNullViolated_nested() { ReflectiveMessageValidator validator = new ReflectiveMessageValidator(); NotificationMessage message = new NotificationMessage(); message.setMethod("foo"); Foo foo = new Foo(); foo.nonNullString = "test"; foo.nested = new Foo(); message.setParams(foo); try { validator.consume(message); Assert.fail(); } catch (MessageIssueException e) { Assert.assertEquals("The accessor 'Foo.getNonNullString()' must return a non-null value. Path: $.params.nested.nonNullString", e.getMessage()); } }
final Procedure1<NotificationMessage> _function = (NotificationMessage it) -> { it.setJsonrpc("2.0"); it.setMethod(MessageMethods.TELEMETRY_EVENT); Pair<String, Double> _mappedTo = Pair.<String, Double>of("foo", Double.valueOf(12.3)); Pair<String, String> _mappedTo_1 = Pair.<String, String>of("bar", "qwertz");
final Procedure1<NotificationMessage> _function = (NotificationMessage it) -> { it.setJsonrpc("2.0"); it.setMethod(MessageMethods.TELEMETRY_EVENT); JsonSerializeTest.TestObject _testObject = new JsonSerializeTest.TestObject(); it.setParams(_testObject);
final Procedure1<NotificationMessage> _function = (NotificationMessage it) -> { it.setJsonrpc("2.0"); it.setMethod(MessageMethods.DID_CHANGE_DOC); DidChangeTextDocumentParams _didChangeTextDocumentParams = new DidChangeTextDocumentParams(); final Procedure1<DidChangeTextDocumentParams> _function_1 = (DidChangeTextDocumentParams it_1) -> {
final Procedure1<NotificationMessage> _function = (NotificationMessage it) -> { it.setJsonrpc("2.0"); it.setMethod(MessageMethods.DID_CHANGE_DOC); DidChangeTextDocumentParams _didChangeTextDocumentParams = new DidChangeTextDocumentParams(); final Procedure1<DidChangeTextDocumentParams> _function_1 = (DidChangeTextDocumentParams it_1) -> {
final Procedure1<NotificationMessage> _function = (NotificationMessage it) -> { it.setJsonrpc("2.0"); it.setMethod(MessageMethods.SHOW_DIAGNOSTICS); PublishDiagnosticsParams _publishDiagnosticsParams = new PublishDiagnosticsParams(); final Procedure1<PublishDiagnosticsParams> _function_1 = (PublishDiagnosticsParams it_1) -> {
final Procedure1<NotificationMessage> _function = (NotificationMessage it) -> { it.setJsonrpc("2.0"); it.setMethod(MessageMethods.SHOW_DIAGNOSTICS); PublishDiagnosticsParams _publishDiagnosticsParams = new PublishDiagnosticsParams(); final Procedure1<PublishDiagnosticsParams> _function_1 = (PublishDiagnosticsParams it_1) -> {