Exemplo n.º 1
0
  @Test
  public void testBadJSONCustomHandler() {

    serviceEndpointServer.stop();

    openPort = PortUtils.findOpenPort();
    serviceEndpointServer =
        EndpointServerBuilder.endpointServerBuilder()
            .setPort(openPort)
            .setErrorHandler(
                new Consumer<Throwable>() {
                  @Override
                  public void accept(Throwable throwable) {
                    final Optional<HttpRequest> httpRequest = new HttpContext().getHttpRequest();
                    if (httpRequest.isPresent()) {
                      httpRequest
                          .get()
                          .getReceiver()
                          .respondOK("\"Bad JSON" + throwable.getMessage() + "\"");
                      httpRequest.get().handled();
                    }
                  }
                })
            .build();
    serviceEndpointServer.initServices(new TestService());
    serviceEndpointServer.startServerAndWait();

    HTTP.Response response =
        HTTP.jsonRestCallViaPOST(
            buildURL("addall"),
            "\"i\": 1, \"s\": \"string\"}, " + "{\"i\": 2, \"s\": \"string2\"}]");

    assertEquals(200, response.status());
  }
Exemplo n.º 2
0
  @Test
  public void testBadJSON() {

    HTTP.Response response =
        HTTP.jsonRestCallViaPOST(
            buildURL("addall"),
            "\"i\": 1, \"s\": \"string\"}, " + "{\"i\": 2, \"s\": \"string2\"}]");

    assertEquals(400, response.status());
  }
Exemplo n.º 3
0
  @Test
  public void testPing() {
    HTTP.Response response = HTTP.getResponse(buildURL("ping"));
    assertEquals(200, response.status());

    final List<String> controls = response.headers().get(HttpHeaders.CACHE_CONTROL);

    Assert.assertEquals("no-cache, no-store", controls.get(0));

    Assert.assertEquals("max-age=0", controls.get(1));

    assertEquals("\"love rocket\"", response.body());
  }
Exemplo n.º 4
0
  @Test
  public void test() {

    HTTP.Response response =
        HTTP.jsonRestCallViaPOST(
            buildURL("addall"),
            "[{\"i\": 1, \"s\": \"string\"}, " + "{\"i\": 2, \"s\": \"string2\"}]");

    assertEquals(202, response.status());

    while (ref.get() == null) {
      Sys.sleep(10);
    }

    assertNotNull(ref.get());
  }
Exemplo n.º 5
0
 @Test
 public void testPing3() {
   HTTP.Response response = HTTP.jsonRestCallViaPUT(buildURL("ping3"), "\"foo\"");
   assertEquals(777, response.status());
   assertEquals("hello mom foo", response.body());
 }
Exemplo n.º 6
0
 @Test
 public void testPing2() {
   HTTP.Response response = HTTP.getResponse(buildURL("ping2"));
   assertEquals(777, response.status());
   assertEquals("hello mom", response.body());
 }