Search in sources :

Example 61 with Mock

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

the class ActionTagTest method testExecuteButResetReturnSameInvocation_clearTagStateSet.

public void testExecuteButResetReturnSameInvocation_clearTagStateSet() throws Exception {
    Mock mockActionInv = new Mock(ActionInvocation.class);
    ActionTag tag = new ActionTag();
    // Explicitly request tag state clearing.
    tag.setPerformClearTagStateForTagPoolingServers(true);
    tag.setPageContext(pageContext);
    tag.setNamespace("");
    tag.setName("testActionTagAction");
    tag.setExecuteResult(true);
    ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInv.proxy());
    ActionInvocation oldInvocation = ActionContext.getContext().getActionInvocation();
    assertNotNull(oldInvocation);
    tag.doStartTag();
    // Ensure component tag state clearing is set true (to match tag).
    setComponentTagClearTagState(tag, true);
    // tag clear components on doEndTag
    ActionComponent component = (ActionComponent) tag.getComponent();
    tag.doEndTag();
    assertTrue(oldInvocation == ActionContext.getContext().getActionInvocation());
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    ActionTag freshTag = new ActionTag();
    freshTag.setPerformClearTagStateForTagPoolingServers(true);
    freshTag.setPageContext(pageContext);
    assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set.  " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(tag, freshTag));
}
Also used : ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ActionComponent(org.apache.struts2.components.ActionComponent) Mock(com.mockobjects.dynamic.Mock)

Example 62 with Mock

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

the class JspTemplateTest method testCheckBox.

public void testCheckBox() throws Exception {
    TestAction testAction = (TestAction) action;
    testAction.setFoo("true");
    CheckboxTag tag = new CheckboxTag();
    Mock rdMock = new Mock(RequestDispatcher.class);
    rdMock.expect("include", C.args(C.isA(HttpServletRequest.class), C.isA(HttpServletResponse.class)));
    RequestDispatcher dispatcher = (RequestDispatcher) rdMock.proxy();
    request.setupGetRequestDispatcher(dispatcher);
    tag.setPageContext(pageContext);
    tag.setTemplate("/test/checkbox.jsp");
    tag.doStartTag();
    tag.doEndTag();
    rdMock.verify();
    // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
    CheckboxTag freshTag = new CheckboxTag();
    freshTag.setPageContext(pageContext);
    assertFalse("Tag state after doEndTag() under default tag clear state is equal to new Tag with pageContext/parent set.  " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(tag, freshTag));
}
Also used : Mock(com.mockobjects.dynamic.Mock) RequestDispatcher(javax.servlet.RequestDispatcher) TestAction(org.apache.struts2.TestAction)

Example 63 with Mock

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

the class VelocityTemplateEngineTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    mgr = new TemplateEngineManager();
    Mock mockContainer = new Mock(Container.class);
    mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("jsp")), new JspTemplateEngine());
    mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("vm")), new VelocityTemplateEngine());
    mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("ftl")), new FreemarkerTemplateEngine());
    mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet<String>() {

        {
            add("jsp");
            add("vm");
            add("ftl");
        }
    });
    mgr.setContainer((Container) mockContainer.proxy());
    mgr.setDefaultTemplateType("jsp");
}
Also used : TemplateEngineManager(org.apache.struts2.components.template.TemplateEngineManager) Mock(com.mockobjects.dynamic.Mock) JspTemplateEngine(org.apache.struts2.components.template.JspTemplateEngine) FreemarkerTemplateEngine(org.apache.struts2.components.template.FreemarkerTemplateEngine)

Example 64 with Mock

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

the class DefaultValidatorFileParserTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mockValidatorFactory = new Mock(ValidatorFactory.class);
    parser = new DefaultValidatorFileParser();
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 65 with Mock

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

the class ExpressionValidatorTest method testNoBooleanExpression.

public void testNoBooleanExpression() throws Exception {
    Mock mock = new Mock(ValidationAware.class);
    mock.expect("addActionError", C.ANY_ARGS);
    ExpressionValidator ev = new ExpressionValidator();
    ev.setValidatorContext(new DelegatingValidatorContext(mock.proxy(), tpf));
    ev.setExpression("{top}");
    ev.setValueStack(ActionContext.getContext().getValueStack());
    // {top} will evaluate to Hello that is not a Boolean
    ev.validate("Hello");
    mock.verify();
}
Also used : ExpressionValidator(com.opensymphony.xwork2.validator.validators.ExpressionValidator) EasyMock(org.easymock.EasyMock) 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