Ejemplo n.º 1
0
  @Test
  public void testNoRouteHandler() throws Exception {
    final HttpRequestHandler dummyHandler =
        new HttpRequestHandler() {
          @Override
          public void handle(ChannelHandlerContext ctx, HttpRequest request) {
            // pass
          }
        };

    routeMatcher.get("/", dummyHandler);
    routeMatcher.get("/blah", dummyHandler);

    routeMatcher.route(null, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/chat"));
    Assert.assertTrue(testRouteHandlerCalled);
  }
Ejemplo n.º 2
0
 @Test
 public void testValidRouteHandler() throws Exception {
   RouteMatcher router = new RouteMatcher();
   router.get("/", new TestRouteHandler());
   router.route(null, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
   Assert.assertTrue(testRouteHandlerCalled);
 }
Ejemplo n.º 3
0
  private HttpRequest testPattern(String pattern, String URI) throws Exception {
    RouteMatcher router = new RouteMatcher();
    final TestRouteHandler handler = new TestRouteHandler();
    // Register handler for pattern
    router.get(pattern, handler);
    // See if handler is called when URI matching pattern is received
    router.route(null, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, URI));

    // Return modified request (headers might be updated with paramsPositionMap from URI)
    return handler.getRequest();
  }
Ejemplo n.º 4
0
 @Test
 public void testMultiMethodSupport() throws Exception {
   final HttpRequestHandler dummyHandler =
       new HttpRequestHandler() {
         @Override
         public void handle(ChannelHandlerContext ctx, HttpRequest request) {
           // pass
         }
       };
   RouteMatcher router = new RouteMatcher();
   router.get("/test/1234/abc", dummyHandler);
   router.post("/test/1234/abc", dummyHandler);
   router.options("/test/1234/abc", dummyHandler);
   Object[] supportedMethods = router.getSupportedMethodsForURL("/test/1234/abc").toArray();
   Arrays.sort(supportedMethods);
   Assert.assertArrayEquals(new String[] {"GET", "OPTIONS", "POST"}, supportedMethods);
 }