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