Refine search
/** * Constructs a in-memory (h2) database configuration to add to a fake application. * * @param name the database name. * @param options the database options. * @return a map of String containing database config info. */ public static Map<String, String> inMemoryDatabase(String name, Map<String, String> options) { return Scala.asJava(play.api.test.Helpers.inMemoryDatabase(name, Scala.asScala(options))); }
@Deprecated public static Result route(Application app, RequestBuilder requestBuilder, byte[] body, long timeout) { return wrapScalaResult(Scala.orNull(play.api.test.Helpers.jRoute(app.getWrappedApplication(), requestBuilder.build()._underlyingRequest(), body)), timeout); }
/** * A test Netty web server with HTTPS support * @param port HTTP port to bind on * @param application The Application to load in this server * @param sslPort HTTPS port to bind on */ public TestServer(int port, Application application, int sslPort) { super(port, application.getWrappedApplication(), Option.<Object>apply(sslPort), play.libs.Scala.<ServerProvider>None()); }
/** * A Fake application. * * @param path The application path * @param classloader The application classloader * @param additionalConfiguration Additional configuration * @param additionalPlugins Additional plugins */ @SuppressWarnings("unchecked") public FakeApplication(File path, ClassLoader classloader, Map<String, ? extends Object> additionalConfiguration, List<String> additionalPlugins, play.GlobalSettings global) { play.api.GlobalSettings g = null; if(global != null) g = new play.core.j.JavaGlobalSettingsAdapter(global); wrappedApplication = new play.api.test.FakeApplication( path, classloader, Scala.toSeq(additionalPlugins), Scala.<String>emptySeq(), Scala.asScala((Map<String, Object>)additionalConfiguration), scala.Option.apply(g) ); }
/** * The context for loading an application. * * @param environment the application environment * @param initialSettings the initial settings. These settings are merged with the settings from the loaded * configuration files, and together form the initialConfiguration provided by the context. It * is intended for use in dev mode, to allow the build system to pass additional configuration * into the application. */ public Context(Environment environment, Map<String,Object> initialSettings) { this.underlying = new play.api.ApplicationLoader.Context( environment.underlying(), scala.Option.empty(), new play.core.DefaultWebCommands(), play.api.Configuration.load(environment.underlying(), play.libs.Scala.asScala(initialSettings))); }
/** * An alias for futures(stage, delay, unit) that uses a java.time.Duration. * * @param stage the input completion stage that may time out. * @param duration The duration after which there is a timeout. * @param <A> the completion stage that should be wrapped with a future. * @return the completion stage, or a completion stage that failed with futures. */ @Override public <A> CompletionStage<A> timeout(final CompletionStage<A> stage, final Duration duration) { requireNonNull(stage, "Null stage"); requireNonNull(duration, "Null duration"); FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.timeout(finiteDuration, Scala.asScalaWithFuture(() -> stage))); }
/** * Retrieves a configuration value as a <code>String</code>. * * @param key configuration key (relative to configuration root key) * @return a configuration value or <code>null</code> */ public String getString(String key) { return Scala.orNull(conf.getString(key, scala.Option.<scala.collection.immutable.Set<java.lang.String>>empty())); }
@Override public <T> CompletionStage<T> getOrElseUpdate(String key, Callable<CompletionStage<T>> block, int expiration) { return toJava( asyncCacheApi.getOrElseUpdate(key, intToDuration(expiration), Scala.asScalaWithFuture(block), Scala.<T>classTag())); }
/** * Create an application loading context. * * Locates and loads the necessary configuration files for the application. * * @param environment The application environment. * @param initialSettings The initial settings. These settings are merged with the settings from the loaded * configuration files, and together form the initialConfiguration provided by the context. It * is intended for use in dev mode, to allow the build system to pass additional configuration * into the application. */ public static Context create(Environment environment, Map<String, Object> initialSettings) { play.api.ApplicationLoader.Context scalaContext = play.api.ApplicationLoader$.MODULE$.createContext( environment.underlying(), Scala.asScala(initialSettings), Scala.<SourceMapper>None(), new DefaultWebCommands()); return new Context(scalaContext); }
@Inject public Langs(play.api.i18n.Langs langs) { this.langs = langs; List<Lang> availables = new ArrayList<>(); for (play.api.i18n.Lang lang : Scala.asJava(langs.availables())) { availables.add(new Lang(lang)); } this.availables = Collections.unmodifiableList(availables); }
/** * Generates a JavaScript reverse router. * * @param name the router's name * @param ajaxMethod which asynchronous call method the user's browser will use (e.g. "jQuery.ajax") * @param host the host to use for the reverse route * @param routes the reverse routes for this router * @return the router */ public static JavaScript create(String name, String ajaxMethod, String host, JavaScriptReverseRoute... routes) { return play.api.routing.JavaScriptReverseRouter.apply( name, Scala.Option(ajaxMethod), host, Scala.varargs(routes) ); }
/** * Retrieve the URL where the user should be redirected to start the OpenID authentication process */ @Override public CompletionStage<String> redirectURL( String openID, String callbackURL, Map<String, String> axRequired, Map<String, String> axOptional, String realm) { if (axRequired == null) axRequired = new HashMap<>(); if (axOptional == null) axOptional = new HashMap<>(); return FutureConverters.toJava(client.redirectURL(openID, callbackURL, JavaConversions.mapAsScalaMap(axRequired).toSeq(), JavaConversions.mapAsScalaMap(axOptional).toSeq(), Scala.Option(realm))); }
/** * Retrieve Lang availables from the application configuration. * * @param app the current application. * @return the list of available Lang. */ public static List<Lang> availables(Application app) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables()); return availableLangs.stream().map(Lang::new).collect(toList()); }
/** * Convert this result to a Scala result. * * @return the Scala result. */ public play.api.mvc.Result asScala() { return new play.api.mvc.Result( header.asScala(), body.asScala(), session == null ? Scala.None() : Scala.Option(play.api.mvc.Session.fromJavaSession(session)), flash == null ? Scala.None() : Scala.Option(play.api.mvc.Flash.fromJavaFlash(flash)), JavaHelpers$.MODULE$.cookiesToScalaCookies(cookies) ); } }
protected HttpErrorHandler preferred(Http.RequestHeader request) { String preferredContentType = Scala.orNull(MediaRange.preferred( Scala.toSeq(request.acceptedTypes()), Scala.toSeq(errorHandlerMap.keySet().toArray(new String[]{})) )); if (preferredContentType == null) { return errorHandlerMap.values().iterator().next(); } else { return errorHandlerMap.get(preferredContentType); } }
/** * Retrieves a resource from the classpath. * * @param relativePath relative path of the resource to fetch * @return URL to the resource (may be null) */ public URL resource(String relativePath) { return Scala.orNull(env.resource(relativePath)); }
/** * Executes a block of code in a running application. * * @param application the application context. * @param block the block to run after the Play app is started. */ public static void running(Application application, final Runnable block) { Helpers$.MODULE$.running(application.asScala(), asScala(() -> { block.run(); return null; })); }
/** * Executes a block of code in a running server. * @param server the server to start. * @param block the block of code to run after the server starts. */ public static void running(TestServer server, final Runnable block) { Helpers$.MODULE$.running(server, asScala(() -> { block.run(); return null; })); }