FakeApplication使用特定的application.conf? [英] FakeApplication using a specific application.conf?

查看:121
本文介绍了FakeApplication使用特定的application.conf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用我的 dev.conf 而不是默认<$来创建 FakeApplication 来运行我的测试c $ c> application.conf ?

How can I create a FakeApplication to run my tests using my dev.conf instead of the default application.conf?

我当前的测试包含以下结构:

My current test consists of the following construct:

Map<String, String> map = new HashMap<>();
map.put("config.file", "/path/to/dev.conf");
FakeApplication fakeApplication = fakeApplication(map);
TestServer testServer = testServer(3333, fakeApplication);
// testServer.start();
running(testServer, HTMLUNIT, new F.Callback<TestBrowser>() {
    public void invoke(TestBrowser browser) {
        //do something
    }
});

此代码改编自 Play Framework关于编写测试的文档抛出以下异常,因为默认的 application.conf 不起作用在我的开发系统上。如果我取消注释 testServer.start(); 我可以更清楚地看到它。

This code adapted from the Play Framework Documentation about writing test throws the following Exception, as the default application.conf does not work on my development-system. If I uncomment testServer.start(); I can see it even more clearly.

[WARN] [01/01/2013 18:36:59.505] [pool-4-thread-3] [Dispatchers] Dispatcher [akka.actor.promises-dispatcher] not configured, using default-dispatcher
[WARN] [01/01/2013 18:36:59.521] [play-akka.actor.default-dispatcher-2] [Dispatchers] Dispatcher [akka.actor.actions-dispatcher] not configured, using default-dispatcher
[error] Test test.ApplicationTest.runInBrowser failed: Server is not started!
[error]     at scala.sys.package$.error(package.scala:27)
[error]     at play.api.test.TestServer.stop(Selenium.scala:117)
[error]     at play.test.Helpers.stop(Helpers.java:325)
[error]     at play.test.Helpers.running(Helpers.java:355)
[error]     at test.ApplicationTest.runInBrowser(ApplicationTest.java:74)
[error]     ...

我假设行

map.put("config.file", "/path/to/dev.conf");

错误,必须进行调整。但是如何?

is wrong and has to be adapted. But how?

推荐答案

用这种方式替换主配置是不可能的。您只能通过将地图传递到 fakeApplication 来覆盖特定设置。

It is impossible to substitute main config with another this way. You only could override specific settings by passing a map to fakeApplication.

I.e。如果你的配置包含:

I.e. if you config contains:

mongodb.default.uri = ...
logger.root = ERROR

您可以通过在地图中放置新值来覆盖它:

You can override it by placing new values inside a map:

Map<String, String> map = new HashMap<>();
map.put("mongodb.default.uri", "...");
map.put("logger.root", "INFO");

FakeApplication fakeApplication = fakeApplication(map);

这篇关于FakeApplication使用特定的application.conf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆