Struts2; 为StrutsSpringTestCase JUnit测试保持会话打开

Struts2; 为StrutsSpringTestCase JUnit测试保持会话打开,第1张

Struts2; 为StrutsSpringTestCase JUnit测试保持会话打开

您可以将

@Transactional
注解放在测试方法上,并且需要使用spring运行测试才能找到
@Transactional
注解。要在Struts2测试中使用JUnit4,您需要扩展
StrutsSpringJUnit4TestCase
。因此您的测试类应如下所示:

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations={"classpath:applicationContext.xml"})public class ActionTest extends StrutsSpringJUnit4TestCase {  @Transactional  @Test  public void testHelperActionLoggedIn() throws Exception {    // ...  }}

注意:如果需要获取

ActionProxy
,可以通过调用
getActionProxy
method获得。您可能需要为其创建新的会话映射,然后才能致电
execute

ActionProxy actionProxy = getActionProxy("/action");Map<String, Object> sessionMap = new HashMap<String, Object>();actionProxy.getInvocation().getInvocationContext().setSession(sessionMap);actionProxy.execute();

但是,如果您不需要引用,

ActionProxy
则可以使用
executeAction
方法执行 *** 作,而无需创建新的会话映射。

executeAction("/action");


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5124980.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存