Пример #1
0
  @Test
  public void testHandleMethodRejection() {
    RejectionHandler rejectionHandler =
        new RejectionHandler() {
          @Override
          public RouteResult handleMethodRejection(RequestContext ctx, HttpMethod supported) {
            return ctx.complete(
                HttpResponse.create()
                    .withStatus(400)
                    .withEntity(
                        "Whoopsie! Unsupported method. Supported would have been "
                            + supported.value()));
          }
        };

    TestRoute route = testRoute(handleRejections(rejectionHandler, get(complete("Successful!"))));

    route.run(HttpRequest.GET("/")).assertStatusCode(200).assertEntity("Successful!");

    route
        .run(HttpRequest.POST("/"))
        .assertStatusCode(400)
        .assertEntity("Whoopsie! Unsupported method. Supported would have been GET");
  }