Exemplo n.º 1
0
 public static Result route(Application app, FakeRequest fakeRequest, byte[] body, long timeout) {
   return wrapScalaResult(
       Scala.orNull(
           play.api.test.Helpers.jRoute(
               app.getWrappedApplication(), fakeRequest.getWrappedRequest(), body)),
       timeout);
 }
Exemplo n.º 2
0
 // --
 @SuppressWarnings(value = "unchecked")
 private static Result invokeHandler(
     play.api.mvc.Handler handler, FakeRequest fakeRequest, long timeout) {
   if (handler instanceof play.core.j.JavaAction) {
     play.api.mvc.Action action = (play.api.mvc.Action) handler;
     return wrapScalaResult(action.apply(fakeRequest.getWrappedRequest()), timeout);
   } else {
     throw new RuntimeException("This is not a JavaAction and can't be invoked this way.");
   }
 }
Exemplo n.º 3
0
 public static Result routeAndCall(
     Class<? extends Routes> router, FakeRequest fakeRequest, long timeout) {
   try {
     Routes routes =
         (Routes)
             router
                 .getClassLoader()
                 .loadClass(router.getName() + "$")
                 .getDeclaredField("MODULE$")
                 .get(null);
     if (routes.routes().isDefinedAt(fakeRequest.getWrappedRequest())) {
       return invokeHandler(
           routes.routes().apply(fakeRequest.getWrappedRequest()), fakeRequest, timeout);
     } else {
       return null;
     }
   } catch (RuntimeException e) {
     throw e;
   } catch (Throwable t) {
     throw new RuntimeException(t);
   }
 }