Search in sources :

Example 66 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class StrutsLocalizedTextProviderTest method testFindTextInInterface.

public void testFindTextInInterface() throws Exception {
    Action action = new ModelDrivenAction2();
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
    String message = localizedTextProvider.findText(ModelDrivenAction2.class, "test.foo", Locale.getDefault());
    assertEquals("Foo!", message);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) SimpleAction(com.opensymphony.xwork2.SimpleAction) Action(com.opensymphony.xwork2.Action) Mock(com.mockobjects.dynamic.Mock)

Example 67 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class StrutsLocalizedTextProviderTest method testFindTextInPackage.

public void testFindTextInPackage() throws Exception {
    ModelDriven action = new ModelDrivenAction2();
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
    String message = localizedTextProvider.findText(ModelDrivenAction2.class, "package.properties", Locale.getDefault());
    assertEquals("It works!", message);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) ModelDriven(com.opensymphony.xwork2.ModelDriven) Mock(com.mockobjects.dynamic.Mock)

Example 68 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class StrutsLocalizedTextProviderTest method testActionGetTextWithNullObject.

public void testActionGetTextWithNullObject() throws Exception {
    MyAction action = new MyAction();
    container.inject(action);
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy()).getValueStack().push(action);
    String message = action.getText("barObj.title");
    assertEquals("Title:", message);
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 69 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class StrutsLocalizedTextProviderTest method testActionGetTextXXX.

public void testActionGetTextXXX() throws Exception {
    localizedTextProvider.addDefaultResourceBundle("com/opensymphony/xwork2/util/FindMe");
    SimpleAction action = new SimpleAction();
    container.inject(action);
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy()).getValueStack().push(action);
    String message = action.getText("bean.name");
    String foundBean2 = action.getText("bean2.name");
    assertEquals("Okay! You found Me!", foundBean2);
    assertEquals("Haha you cant FindMe!", message);
}
Also used : SimpleAction(com.opensymphony.xwork2.SimpleAction) Mock(com.mockobjects.dynamic.Mock)

Example 70 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class StrutsConversionErrorInterceptorTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    interceptor = new StrutsConversionErrorInterceptor();
    mockInvocation = new Mock(ActionInvocation.class);
    invocation = (ActionInvocation) mockInvocation.proxy();
    stack = ActionContext.getContext().getValueStack();
    conversionErrors = new HashMap<>();
    context = ActionContext.of(stack.getContext()).withConversionErrors(conversionErrors).bind();
    mockInvocation.matchAndReturn("getInvocationContext", context);
    mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
    mockInvocation.expectAndReturn("getStack", stack);
    mockInvocation.expect("addPreResultListener", C.ANY_ARGS);
}
Also used : ActionInvocation(com.opensymphony.xwork2.ActionInvocation) Mock(com.mockobjects.dynamic.Mock)

Aggregations

Mock (com.mockobjects.dynamic.Mock)91 HashMap (java.util.HashMap)14 ValidationException (com.opensymphony.xwork2.validator.ValidationException)12 StrutsException (org.apache.struts2.StrutsException)12 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 ActionContext (com.opensymphony.xwork2.ActionContext)8 TreeMap (java.util.TreeMap)8 ActionProxy (com.opensymphony.xwork2.ActionProxy)6 HttpParameters (org.apache.struts2.dispatcher.HttpParameters)6 MockHttpSession (org.springframework.mock.web.MockHttpSession)6 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)4 Container (com.opensymphony.xwork2.inject.Container)4 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)4 ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)4 LinkedHashMap (java.util.LinkedHashMap)4 Action (com.opensymphony.xwork2.Action)3