When testing an stand alone spring environment we can do:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:spring-*.xml" })
@ActiveProfiles( profiles = { "Prod","bsi"})
public class SampleTest
When testing Struts 2 with spring integration we can use:
public class SessionManagement extends StrutsSpringTestCase {
@Override
public String[] getContextLocations() {
return new String[] {"classpath:spring-*.xml"};
}
}
But how can I set the active spring profile here?
You can set active profiles in spring via application context environment.
Since
StrutsTestCase
usesGenericXmlContextLoader
which is not configurable you need to overridesetupBeforeInitDispatcher
method in your test and use some context (e.g.XmlWebApplicationContext
) where you can set profiles and callrefresh
.JUnit 4
Since you're using JUnit 4 there is
StrutsSpringJUnit4TestCase
abstract class. Extend it and you can use annotations just like in yourSampleTest
.