Struts2 JUnit ActionContext objects

前端 未结 1 999
囚心锁ツ
囚心锁ツ 2021-01-16 05:55

Problem: Struts ActionContext is null during test

Using Struts2 JUnit plugin I have the following test:

public class MainActionIT extend         


        
相关标签:
1条回答
  • 2021-01-16 06:17

    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);
    }
    

    About the template

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

    0 讨论(0)
提交回复
热议问题