ReverseRouter implements WithControllerMethod<Builder> { public Builder with(Class<?> controllerClass, String methodName) { return builder(controllerClass, methodName); } @Inject  ReverseRouter(NinjaProperties ninjaProperties,
                         Router router); Builder with(Class<?> controllerClass, String methodName); Builder with(MethodReference methodRef); @Override Builder with(ControllerMethod controllerMethod);  }
@Test public void simple() { String route = reverseRouter.with(TestController::home).build(); assertThat(route, is("/home")); }
@Test public void simpleWithMethodReference() { MethodReference methodRef = new MethodReference(TestController.class, "home"); String route = reverseRouter.with(methodRef).build(); assertThat(route, is("/home")); }
@Test public void simpleWithClassReference() { String route = reverseRouter.with(TestController.class, "home").build(); assertThat(route, is("/home")); }
@Test public void simpleWithContext() { String contextPath = "/context"; when(ninjaProperties.getContextPath()).thenReturn(contextPath); String route = reverseRouter.with(TestController::home).build(); assertThat(route, is("/context/home")); }
@Test public void simpleWithQuery() { String route = reverseRouter.with(TestController::home) .queryParam("filter", true) .queryParam("a", 1L) .queryParam("foo", "bar") .queryParam("email", "test@example.com") .build(); assertThat(route, is("/home?filter=true&a=1&foo=bar&email=test%40example.com")); }
@Test public void simpleWithRawQuery() { String route = reverseRouter.with(TestController::home) .rawQueryParam("email", "test@example.com") .build(); assertThat(route, is("/home?email=test@example.com")); }
@Test(expected=IllegalArgumentException.class) public void routeNotFound() { reverseRouter.with(TestController::notfound) .build(); }
@Test(expected=IllegalArgumentException.class) public void simpleNoPathParamsThrowsException() { reverseRouter.with(TestController::home) .pathParam("id", 1000000L) .build(); }
@Test(expected=IllegalArgumentException.class) public void simpleInvalidPathParamThrowsException() { reverseRouter.with(TestController::user) .pathParam("id2", 1000000L) .build(); }
@Test(expected=IllegalArgumentException.class) public void simpleMissingAllPathParamThrowsException() { reverseRouter.with(TestController::user) .build(); }
@Test(expected=IllegalArgumentException.class) public void simpleNotEnoughPathParamThrowsException() { reverseRouter.with(TestController::user) .pathParam("id", 1000000L) .build(); }
@Test public void path() { String route = reverseRouter.with(TestController::user) .pathParam("email", "test@example.com") .pathParam("id", 1000000L) .build(); assertThat(route, is("/user/test%40example.com/1000000")); }
@Test public void rawPath() { String route = reverseRouter.with(TestController::user) .rawPathParam("email", "test@example.com") .pathParam("id", 1000000L) .build(); assertThat(route, is("/user/test@example.com/1000000")); }
@Test public void verifySecondRouteMatched() { String route = reverseRouter.with(TestController::index) .build(); assertThat(route, is("/home/index")); }
@Test public void absolute() { String route = reverseRouter.with(TestController::user) .absolute("https", "www.greenback.com") .pathParam("email", "test@example.com") .pathParam("id", 1000000L) .build(); assertThat(route, is("https: }
@Test public void absoluteWebSocket() { Context context = mock(Context.class); when(context.getScheme()).thenReturn("http"); when(context.getHostname()).thenReturn("www.example.com:8080"); String route = reverseRouter.with(TestController::websocket) .absolute(context) .queryParam("a", 1) .build(); assertThat(route, is("ws: }
@Test public void absoluteSecureWebSocket() { Context context = mock(Context.class); when(context.getScheme()).thenReturn("https"); when(context.getHostname()).thenReturn("www.example.com:8080"); String route = reverseRouter.with(TestController::websocket) .absolute(context) .build(); assertThat(route, is("wss: }