Search in sources :

Example 6 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class PrepareInterceptorTest method testPrefixInvocation1.

public void testPrefixInvocation1() throws Exception {
    ActionProxy mockActionProxy = (ActionProxy) createMock(ActionProxy.class);
    expect(mockActionProxy.getMethod()).andStubReturn("submit");
    ActionInvocation mockActionInvocation = (ActionInvocation) createMock(ActionInvocation.class);
    expect(mockActionInvocation.getAction()).andStubReturn(mockAction);
    expect(mockActionInvocation.invoke()).andStubReturn("okok");
    expect(mockActionInvocation.getProxy()).andStubReturn(mockActionProxy);
    mockAction.prepareSubmit();
    expectLastCall().times(1);
    mockAction.prepare();
    expectLastCall().times(1);
    replay(mockAction, mockActionProxy, mockActionInvocation);
    PrepareInterceptor interceptor = new PrepareInterceptor();
    String result = interceptor.intercept(mockActionInvocation);
    assertEquals("okok", result);
    verify(mockAction, mockActionProxy, mockActionInvocation);
}
Also used : MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation)

Example 7 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class ScopedModelDrivenInterceptorTest method testScopedModelDrivenActionWithSetClassName.

public void testScopedModelDrivenActionWithSetClassName() throws Exception {
    inter.setScope("request");
    inter.setClassName("com.opensymphony.xwork2.test.Equidae");
    inter.setName("queen");
    ScopedModelDriven action = new MyEquidaeScopedModelDrivenAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").build();
    map.setConfig(ac);
    mai.setAction(action);
    mai.setProxy(map);
    inter.intercept(mai);
    inter.destroy();
    assertNotNull(action.getModel());
    assertNotNull(action.getScopeKey());
    assertEquals("queen", action.getScopeKey());
    Object model = ActionContext.getContext().get(action.getScopeKey());
    assertNotNull(model);
    assertTrue("Model should be an Equidae object", model instanceof Equidae);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) Equidae(com.opensymphony.xwork2.test.Equidae) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 8 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class ScopedModelDrivenInterceptorTest method testModelOnSession.

public void testModelOnSession() throws Exception {
    inter.setScope("session");
    inter.setName("king");
    User user = new User();
    user.setName("King George");
    Map session = new HashMap();
    ActionContext.getContext().setSession(session);
    ActionContext.getContext().getSession().put("king", user);
    ScopedModelDriven action = new MyUserScopedModelDrivenAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").build();
    map.setConfig(ac);
    mai.setAction(action);
    mai.setProxy(map);
    inter.intercept(mai);
    inter.destroy();
    assertNotNull(action.getModel());
    assertNotNull(action.getScopeKey());
    assertEquals("king", action.getScopeKey());
    Object model = ActionContext.getContext().getSession().get(action.getScopeKey());
    assertNotNull(model);
    assertTrue("Model should be an User object", model instanceof User);
    assertEquals("King George", ((User) model).getName());
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) User(com.opensymphony.xwork2.test.User) HashMap(java.util.HashMap) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) HashMap(java.util.HashMap) Map(java.util.Map) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 9 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class ScopedModelDrivenInterceptorTest method testScopedModelDrivenAction.

public void testScopedModelDrivenAction() throws Exception {
    inter.setScope("request");
    ScopedModelDriven action = new MyUserScopedModelDrivenAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").build();
    map.setConfig(ac);
    mai.setAction(action);
    mai.setProxy(map);
    inter.intercept(mai);
    inter.destroy();
    assertNotNull(action.getModel());
    assertNotNull(action.getScopeKey());
    assertEquals("com.opensymphony.xwork2.test.User", action.getScopeKey());
    Object model = ActionContext.getContext().get(action.getScopeKey());
    assertNotNull(model);
    assertTrue("Model should be an User object", model instanceof User);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) User(com.opensymphony.xwork2.test.User) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 10 with MockActionProxy

use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.

the class StaticParametersInterceptorTest method testWithOneParametersNoParse.

public void testWithOneParametersNoParse() throws Exception {
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").addParam("top.name", "${top.hero}").build();
    map.setConfig(ac);
    mai.setProxy(map);
    mai.setAction(new SimpleFooAction());
    User user = new User();
    ActionContext.getContext().getValueStack().push(user);
    int before = ActionContext.getContext().getValueStack().size();
    interceptor.setParse("false");
    interceptor.intercept(mai);
    assertEquals(before, ActionContext.getContext().getValueStack().size());
    assertEquals("${top.hero}", user.getName());
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) SimpleFooAction(com.opensymphony.xwork2.SimpleFooAction) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Aggregations

MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)43 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)34 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)29 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)19 ActionProxy (com.opensymphony.xwork2.ActionProxy)17 HashMap (java.util.HashMap)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)13 ActionContext (com.opensymphony.xwork2.ActionContext)12 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)11 SimpleFooAction (com.opensymphony.xwork2.SimpleFooAction)10 ServletActionContext (org.apache.struts2.ServletActionContext)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)10 OgnlUtil (com.opensymphony.xwork2.ognl.OgnlUtil)8 ActionMapper (org.apache.struts2.dispatcher.mapper.ActionMapper)7 IMocksControl (org.easymock.IMocksControl)7 ValueStack (com.opensymphony.xwork2.util.ValueStack)6 DefaultUrlHelper (org.apache.struts2.views.util.DefaultUrlHelper)6 Mock (com.mockobjects.dynamic.Mock)5 Action (com.opensymphony.xwork2.Action)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5