且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Struts2 JUnit ActionContext对象

更新时间:2023-02-24 21:18:40

在操作执行期间创建操作上下文。您应该检查此代码以证明该概念。

Action context is created during the action execution. You should check this code to proof the concept.

@Test
public void shouldAdditionalContextParamsBeAvailable() throws Exception {
    // given
    String key = "application";
    assertNull(ActionContext.getContext().get(key));

    // when
    String output = executeAction("/home");

    // then
    assertNotNull(ActionContext.getContext().get(key));
}

@Override
protected void applyAdditionalParams(ActionContext context) {
    Map<String, Object> application = new HashMap<String, Object>();
    application.put("options","home");
    context.put("application", application);
}

关于模板

applyAdditionalParams(ActionContext)可以在子类中覆盖
,以提供
动作调用期间使用的其他参数和设置

applyAdditionalParams(ActionContext) Can be overwritten in subclass to provide additional params and settings used during action invocation