How to load various plugins in modular modules of Play Framework?

I have different plugins implemented in the Plugin interface. Now I have them hardcoded in play.plugins like this:

 100:test.A 200:test.B 

However, in my unit tests, I do not want both to be loaded at a time. In other words, in test A, I want to load only plugin A and only in test B load B. Instead of manually changing the configuration file, is there any way to change it programmatically? I assume that when fakeApplication() is called, all plugins load by default.

+4
source share
1 answer

You can run FakeApplication with added or excluded plugins, as well as with a 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 static FakeApplication methods available in the play.test.Helpers class. Here is the equivalent of a 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); 
+10
source

Source: https://habr.com/ru/post/1493956/