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