I have different plugins implemented the Plugin
interface. Now I have them hard-coded in play.plugins like this:
100:test.A
200:test.B
However in my unit tests I don't want both of them to be loaded at one time. In other words, in test A I want to load only plugin A and in test B load B only. Instead of changing the configuration file manually, is there a way to change it programmatically? I guess when fakeApplication()
is invoked all plugins are loaded by default.
You can start a FakeApplication
with added or excluded plugins and also with custom configuration.
Here is an example in scala (I believe the Java API has an equivalent mechanism) :
val app = FakeApplication(
withoutPlugins = List("test.A", "test.B"),
additionalPlugins = List("test.C"),
additionalConfiguration = Map("customConfigKey" -> "customConfigValue")
)
In Java, you can use one of the fakeApplication
static methods available in the play.test.Helpers
class. Here is the equivalent of the scala example :
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import play.test.FakeApplication;
import static play.test.Helpers.*;
Map<String, Object> additionalConfiguration = new HashMap<String, Object>();
additionalConfiguration.put("customConfigKey", "customConfigValue");
List<String> withoutPlugins = Arrays.asList("test.A", "test.B");
List<String> additionalPlugins = Arrays.asList("test.C");
FakeApplication app = fakeApplication(additionalConfiguration, additionalPlugins, withoutPlugins);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With