Let's say you need to configure an incoming directory on a component using external configuration. For example in Spring Integration:
I'm using expression language to load a property from a config object, which I wire in turn as a Spring bean. In my main application this config object can just be a
public static class Config {
public static final Map
}
If you then use the containing context in a JUnit test it will be loaded up once the context is created, so you need to make sure to put the store value in the map @BeforeClass. Now I'd like to use a TemporaryFolder, to store files in the input directory of the channel adapter, but you can't refresh the property of a singleton bean each test. The @Rule will be applied before each test, resulting in the second test using a different directory from the context. A shame.
A working solution is to just remove the @Rule annotation from the TemporaryFolder and manually invoke create() and delete(). I'd like to know if there is a better solution.
Maven sample project can be found on GitHub.
If you give it a go, let me know if you find a neater option!
No comments:
Post a Comment