Java 类org.eclipse.lsp4j.jsonrpc.messages.RequestMessage 实例源码

项目:dsp4e    文件:DebugRemoteEndpointTest.java   
@Test public void testRequest() {
    TestEndpoint endp = new TestEndpoint();
    TestMessageConsumer consumer = new TestMessageConsumer();
    RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp);

    endpoint.consume(new RequestMessage() {{
        setId("1");
        setMethod("foo");
        setParams("myparam");
    }});

    Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next();
    entry.getValue().complete("success");
    assertEquals("foo", entry.getKey().getMethod());
    assertEquals("myparam", entry.getKey().getParams());
    assertEquals("success", ((ResponseMessage)consumer.messages.get(0)).getResult());
}
项目:dsp4e    文件:DebugRemoteEndpointTest.java   
@Test public void testCancellation() {
    TestEndpoint endp = new TestEndpoint();
    TestMessageConsumer consumer = new TestMessageConsumer();
    RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp);

    endpoint.consume(new RequestMessage() {{
        setId("1");
        setMethod("foo");
        setParams("myparam");
    }});

    Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next();
    entry.getValue().cancel(true);
    ResponseMessage message = (ResponseMessage) consumer.messages.get(0);
    assertNotNull(message);
    ResponseError error = message.getError();
    assertNotNull(error);
    assertEquals(error.getCode(), ResponseErrorCode.RequestCancelled.getValue());
    assertEquals(error.getMessage(), "The request (id: 1, method: 'foo') has been cancelled");

}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testParamsParsing_01() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");
    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"foo\",\n"
            + "\"arguments\": {\"uri\": \"dummy://mymodel.mydsl\"}\n"
            + "}");
    Object params = message.getParams();
    Class<? extends Object> class1 = params.getClass();
    Assert.assertEquals(Location.class, class1);
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testParamsParsing_AllOrders() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {
            }.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");
    String[] properties = new String[] {
            "\"seq\":2",
            "\"type\":\"request\"",
            "\"command\":\"foo\"",
            "\"arguments\": {\"uri\": \"dummy://mymodel.mydsl\"}"
            };
    testAllPermutations(properties, json -> {
        RequestMessage message = (RequestMessage) handler.parseMessage(json);
        Object params = message.getParams();
        Class<? extends Object> class1 = params.getClass();
        Assert.assertEquals(Location.class, class1);
    });
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testParamsParsing_02() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"foo\",\n"
            + "\"arguments\": {\"uri\": \"dummy://mymodel.mydsl\"}\n"
            + "}");
    Assert.assertEquals(Location.class, message.getParams().getClass());
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testParamsParsing_03() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"bar\",\n"
            + "\"arguments\": {\"uri\": \"dummy://mymodel.mydsl\"}\n"
            + "}");
    Assert.assertEquals(JsonObject.class, message.getParams().getClass());
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testParamsParsing_04() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"bar\",\n"
            + "\"arguments\": null\n"
            + "}");
    Assert.assertEquals(null, message.getParams());
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_01() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"foo\",\n"
            + "\"arguments\": [\"foo\", 2]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(2, parameters.size());
    Assert.assertEquals("foo", parameters.get(0));
    Assert.assertEquals(2, parameters.get(1));
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_02() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"bar\",\n"
            + "\"arguments\": [\"foo\", 2]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof JsonArray);
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_03() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<String>>() {}.getType(),
            new TypeToken<List<Integer>>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"foo\",\n"
            + "\"arguments\": [[\"foo\", \"bar\"], [1, 2], {\"uri\": \"dummy://mymodel.mydsl\"}]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals("[foo, bar]", parameters.get(0).toString());
    Assert.assertEquals("[1, 2]", parameters.get(1).toString());
    Assert.assertTrue("" + parameters.get(2).getClass(), parameters.get(2) instanceof Location);
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_04() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<String>>() {}.getType(),
            new TypeToken<List<Integer>>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"foo\",\n"
            + "\"arguments\": [[\"foo\", \"bar\"], [1, 2]]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals("[foo, bar]", parameters.get(0).toString());
    Assert.assertEquals("[1, 2]", parameters.get(1).toString());
    Assert.assertNull(parameters.get(2));
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testMultiParamsParsing_01() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": [\"foo\", 2],\n"
            + "\"command\":\"foo\"\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(2, parameters.size());
    Assert.assertEquals("foo", parameters.get(0));
    Assert.assertEquals(2, parameters.get(1));
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testMultiParamsParsing_02() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": [\"foo\", 2],\n"
            + "\"command\":\"bar\"\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof JsonArray);
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testMultiParamsParsing_03() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<String>>() {}.getType(),
            new TypeToken<List<Integer>>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": [[\"foo\", \"bar\"], [1, 2], {\"uri\": \"dummy://mymodel.mydsl\"}],\n"
            + "\"command\":\"foo\"\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals("[foo, bar]", parameters.get(0).toString());
    Assert.assertEquals("[1, 2]", parameters.get(1).toString());
    Assert.assertTrue("" + parameters.get(2).getClass(), parameters.get(2) instanceof Location);
}
项目:dsp4e    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testMultiParamsParsing_04() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<String>>() {}.getType(),
            new TypeToken<List<Integer>>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": [[\"foo\", \"bar\"], [1, 2]],\n"
            + "\"command\":\"foo\"\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals("[foo, bar]", parameters.get(0).toString());
    Assert.assertEquals("[1, 2]", parameters.get(1).toString());
    Assert.assertNull(parameters.get(2));
}
项目:lsp4j    文件:NullResponseTest.java   
@Test public void testNullResponse() throws InterruptedException, ExecutionException {
    Endpoint endpoint = ServiceEndpoints.toEndpoint(this);
    Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(LanguageServer.class);
    MessageJsonHandler handler = new MessageJsonHandler(methods);
    List<Message> msgs = new ArrayList<>();
    MessageConsumer consumer = (message) -> {
        msgs.add(message);
    };
    RemoteEndpoint re = new RemoteEndpoint(consumer, endpoint);

    RequestMessage request = new RequestMessage();
    request.setId("1");
    request.setMethod("shutdown");
    re.consume(request);
    Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":null}", handler.serialize(msgs.get(0)));
    msgs.clear();
    shutdownReturn = new Object();
    re.consume(request);
    Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":{}}", handler.serialize(msgs.get(0)));
}
项目:lsp4j    文件:DebugRemoteEndpointTest.java   
@Test public void testRequest() {
    TestEndpoint endp = new TestEndpoint();
    TestMessageConsumer consumer = new TestMessageConsumer();
    RemoteEndpoint endpoint = new DebugRemoteEndpoint(consumer, endp);

    endpoint.consume(new RequestMessage() {{
        setId("1");
        setMethod("foo");
        setParams("myparam");
    }});

    Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next();
    entry.getValue().complete("success");
    assertEquals("foo", entry.getKey().getMethod());
    assertEquals("myparam", entry.getKey().getParams());
    assertEquals("success", ((ResponseMessage)consumer.messages.get(0)).getResult());
}
项目:lsp4j    文件:DebugRemoteEndpointTest.java   
@Test public void testCancellation() {
    TestEndpoint endp = new TestEndpoint();
    TestMessageConsumer consumer = new TestMessageConsumer();
    RemoteEndpoint endpoint = new DebugRemoteEndpoint(consumer, endp);

    endpoint.consume(new RequestMessage() {{
        setId("1");
        setMethod("foo");
        setParams("myparam");
    }});

    Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next();
    entry.getValue().cancel(true);
    ResponseMessage message = (ResponseMessage) consumer.messages.get(0);
    assertNotNull(message);
    ResponseError error = message.getError();
    assertNotNull(error);
    assertEquals(error.getCode(), ResponseErrorCode.RequestCancelled.getValue());
    assertEquals(error.getMessage(), "The request (id: 1, method: 'foo') has been cancelled");

}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testParamsParsing_01() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");
    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": {\"uri\": \"dummy://mymodel.mydsl\"},\n"
            + "\"command\":\"foo\"\n"
            + "}");
    Object params = message.getParams();
    Class<? extends Object> class1 = params.getClass();
    Assert.assertEquals(Location.class, class1);
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testParamsParsing_02() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"foo\",\n"
            + "\"arguments\": {\"uri\": \"dummy://mymodel.mydsl\"}\n"
            + "}");
    Assert.assertEquals(Location.class, message.getParams().getClass());
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testParamsParsing_03() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"bar\",\n"
            + "\"arguments\": {\"uri\": \"dummy://mymodel.mydsl\"}\n"
            + "}");
    Assert.assertEquals(JsonObject.class, message.getParams().getClass());
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testParamsParsing_04() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"bar\",\n"
            + "\"arguments\": null\n"
            + "}");
    Assert.assertEquals(null, message.getParams());
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_01() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"foo\",\n"
            + "\"arguments\": [\"foo\", 2]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(2, parameters.size());
    Assert.assertEquals("foo", parameters.get(0));
    Assert.assertEquals(2, parameters.get(1));
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_02() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"bar\",\n"
            + "\"arguments\": [\"foo\", 2]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof JsonArray);
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_03() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<String>>() {}.getType(),
            new TypeToken<List<Integer>>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"foo\",\n"
            + "\"arguments\": [[\"foo\", \"bar\"], [1, 2], {\"uri\": \"dummy://mymodel.mydsl\"}]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals("[foo, bar]", parameters.get(0).toString());
    Assert.assertEquals("[1, 2]", parameters.get(1).toString());
    Assert.assertTrue("" + parameters.get(2).getClass(), parameters.get(2) instanceof Location);
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_04() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<String>>() {}.getType(),
            new TypeToken<List<Integer>>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"command\":\"foo\",\n"
            + "\"arguments\": [[\"foo\", \"bar\"], [1, 2]]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals("[foo, bar]", parameters.get(0).toString());
    Assert.assertEquals("[1, 2]", parameters.get(1).toString());
    Assert.assertNull(parameters.get(2));
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testMultiParamsParsing_01() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": [\"foo\", 2],\n"
            + "\"command\":\"foo\"\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(2, parameters.size());
    Assert.assertEquals("foo", parameters.get(0));
    Assert.assertEquals(2, parameters.get(1));
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testMultiParamsParsing_02() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": [\"foo\", 2],\n"
            + "\"command\":\"bar\"\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof JsonArray);
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testMultiParamsParsing_03() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<String>>() {}.getType(),
            new TypeToken<List<Integer>>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": [[\"foo\", \"bar\"], [1, 2], {\"uri\": \"dummy://mymodel.mydsl\"}],\n"
            + "\"command\":\"foo\"\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals("[foo, bar]", parameters.get(0).toString());
    Assert.assertEquals("[1, 2]", parameters.get(1).toString());
    Assert.assertTrue("" + parameters.get(2).getClass(), parameters.get(2) instanceof Location);
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testMultiParamsParsing_04() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<String>>() {}.getType(),
            new TypeToken<List<Integer>>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": [[\"foo\", \"bar\"], [1, 2]],\n"
            + "\"command\":\"foo\"\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals("[foo, bar]", parameters.get(0).toString());
    Assert.assertEquals("[1, 2]", parameters.get(1).toString());
    Assert.assertNull(parameters.get(2));
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testEnumParam() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<MyDebugEnum>>() {}.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");
    RequestMessage message = (RequestMessage) handler.parseMessage("{"
            + "\"seq\":2,\n"
            + "\"type\":\"request\",\n"
            + "\"arguments\": [\"enum1\", \"anotherEnum\", \"aStrangeEnumUTC\"],\n"
            + "\"command\":\"foo\"\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals(Arrays.asList(MyDebugEnum.ENUM1, MyDebugEnum.ANOTHER_ENUM, MyDebugEnum.A_STRANGE_ENUM_UTC),
            parameters);
}
项目:lsp4j    文件:DebugMessageJsonHandlerTest.java   
@Test
public void testRequest_AllOrders() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {
            }.getType()));
    DebugMessageJsonHandler handler = new DebugMessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");
    String[] properties = new String[] {
            "\"seq\":2",
            "\"type\":\"request\"",
            "\"command\":\"foo\"",
            "\"arguments\": {\"uri\": \"dummy://mymodel.mydsl\"}"
            };
    testAllPermutations(properties, json -> {
        RequestMessage message = (RequestMessage) handler.parseMessage(json);
        Object params = message.getParams();
        Class<? extends Object> class1 = params.getClass();
        Assert.assertEquals(Location.class, class1);
        Assert.assertEquals("dummy://mymodel.mydsl", ((Location)params).uri);
    });
}
项目:lsp4j    文件:RemoteEndpoint.java   
@Override
public CompletableFuture<Object> request(String method, Object parameter) {
    RequestMessage requestMessage = createRequestMessage(method, parameter);
    final String id = requestMessage.getId();
    final CompletableFuture<Object> result = new CompletableFuture<Object>() {
        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
            sendCancelNotification(id);
            return super.cancel(mayInterruptIfRunning);
        }
    };
    Consumer<ResponseMessage> responseHandler = (responseMessage) -> {
        if (responseMessage.getError() != null) {
            result.completeExceptionally(new ResponseErrorException(responseMessage.getError()));
        } else {
            result.complete(responseMessage.getResult());
        }
    };
    synchronized(sentRequestMap) {
        sentRequestMap.put(id, new PendingRequestInfo(requestMessage, responseHandler));
    }
    out.consume(requestMessage);
    return result;
}
项目:lsp4j    文件:MessageJsonHandlerTest.java   
@Test
public void testParamsParsing_01() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    MessageJsonHandler handler = new MessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\","
            + "\"id\":\"2\",\n"
            + "\"params\": {\"uri\": \"dummy://mymodel.mydsl\"},\n"
            + "\"method\":\"foo\"\n"
            + "}");
    Assert.assertEquals(Location.class, message.getParams().getClass());
}
项目:lsp4j    文件:MessageJsonHandlerTest.java   
@Test
public void testParamsParsing_02() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    MessageJsonHandler handler = new MessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\","
            + "\"id\":\"2\",\n"
            + "\"method\":\"foo\",\n"
            + "\"params\": {\"uri\": \"dummy://mymodel.mydsl\"}\n"
            + "}");
    Assert.assertEquals(Location.class, message.getParams().getClass());
}
项目:lsp4j    文件:MessageJsonHandlerTest.java   
@Test
public void testParamsParsing_03() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    MessageJsonHandler handler = new MessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\","
            + "\"id\":\"2\",\n"
            + "\"method\":\"bar\",\n"
            + "\"params\": {\"uri\": \"dummy://mymodel.mydsl\"}\n"
            + "}");
    Assert.assertEquals(JsonObject.class, message.getParams().getClass());
}
项目:lsp4j    文件:MessageJsonHandlerTest.java   
@Test
public void testParamsParsing_04() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    MessageJsonHandler handler = new MessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\","
            + "\"id\":\"2\",\n"
            + "\"method\":\"bar\",\n"
            + "\"params\": null\n"
            + "}");
    Assert.assertEquals(null, message.getParams());
}
项目:lsp4j    文件:MessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_01() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    MessageJsonHandler handler = new MessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\","
            + "\"id\":\"2\",\n"
            + "\"method\":\"foo\",\n"
            + "\"params\": [\"foo\", 2]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(2, parameters.size());
    Assert.assertEquals("foo", parameters.get(0));
    Assert.assertEquals(2, parameters.get(1));
}
项目:lsp4j    文件:MessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_02() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<String>() {}.getType(),
            new TypeToken<Integer>() {}.getType()));
    MessageJsonHandler handler = new MessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\","
            + "\"id\":\"2\",\n"
            + "\"method\":\"bar\",\n"
            + "\"params\": [\"foo\", 2]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof JsonArray);
}
项目:lsp4j    文件:MessageJsonHandlerTest.java   
@Test
public void testRawMultiParamsParsing_03() {
    Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>();
    supportedMethods.put("foo", JsonRpcMethod.request("foo",
            new TypeToken<Void>() {}.getType(),
            new TypeToken<List<String>>() {}.getType(),
            new TypeToken<List<Integer>>() {}.getType(),
            new TypeToken<Location>() {}.getType()));
    MessageJsonHandler handler = new MessageJsonHandler(supportedMethods);
    handler.setMethodProvider((id) -> "foo");

    RequestMessage message = (RequestMessage) handler.parseMessage("{\"jsonrpc\":\"2.0\","
            + "\"id\":\"2\",\n"
            + "\"method\":\"foo\",\n"
            + "\"params\": [[\"foo\", \"bar\"], [1, 2], {\"uri\": \"dummy://mymodel.mydsl\"}]\n"
            + "}");
    Assert.assertTrue("" + message.getParams().getClass(), message.getParams() instanceof List);

    List<?> parameters = (List<?>) message.getParams();
    Assert.assertEquals(3, parameters.size());
    Assert.assertEquals("[foo, bar]", parameters.get(0).toString());
    Assert.assertEquals("[1, 2]", parameters.get(1).toString());
    Assert.assertTrue("" + parameters.get(2).getClass(), parameters.get(2) instanceof Location);
}