My project architecture is Struts2 with Spring integration and JPA/Hibernate. StrutsSpringTestCase base class is utilized for JUnit integration tests.
Under normal circu
You can put @Transactional
annotation over test method and you need to run your tests with spring in order it could find @Transactional
annotation. To use JUnit4 in Struts2 tests you need to extend StrutsSpringJUnit4TestCase
. So your test class should look something like that:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class ActionTest extends StrutsSpringJUnit4TestCase {
@Transactional
@Test
public void testHelperActionLoggedIn() throws Exception {
// ...
}
}
Note: If you need to obtain ActionProxy
you can get it by calling getActionProxy
method. You probably need to create new session map for it and then you can call execute
.
ActionProxy actionProxy = getActionProxy("/action");
Map<String, Object> sessionMap = new HashMap<String, Object>();
actionProxy.getInvocation().getInvocationContext().setSession(sessionMap);
actionProxy.execute();
BUT if you don't need reference to ActionProxy
then you can use executeAction
method to execute action in this way you don't need to create new session map.
executeAction("/action");