use of com.mockobjects.servlet.MockJspWriter in project struts by apache.
the class ElseIfTagTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
stack = ActionContext.getContext().getValueStack();
jspWriter = new MockJspWriter();
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
StrutsMockServletContext servletContext = new StrutsMockServletContext();
servletContext.setServletInfo("not-weblogic");
pageContext = new MockPageContext();
pageContext.setJspWriter(jspWriter);
pageContext.setRequest(request);
pageContext.setServletContext(servletContext);
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
}
use of com.mockobjects.servlet.MockJspWriter in project struts by apache.
the class TextTagTest method testDefaultMessageOk.
public void testDefaultMessageOk() throws Exception {
// NOTE:
// simulate the condition
// <s:text name="some.invalid.key">My Default Message</s:text>
StrutsMockBodyContent mockBodyContent = new StrutsMockBodyContent(new MockJspWriter());
mockBodyContent.setString("Sample Of Default Message");
tag.setBodyContent(mockBodyContent);
tag.setName("some.invalid.key.so.we.should.get.the.default.message");
int startStatus = tag.doStartTag();
tag.doEndTag();
assertEquals(startStatus, BodyTag.EVAL_BODY_BUFFERED);
assertEquals("Sample Of Default Message", writer.toString());
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
TextTag freshTag = new TextTag();
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.servlet.MockJspWriter in project struts by apache.
the class TextTagTest method testDefaultMessageOk_clearTagStateSet.
public void testDefaultMessageOk_clearTagStateSet() throws Exception {
// NOTE:
// simulate the condition
// <s:text name="some.invalid.key">My Default Message</s:text>
StrutsMockBodyContent mockBodyContent = new StrutsMockBodyContent(new MockJspWriter());
mockBodyContent.setString("Sample Of Default Message");
// Explicitly request tag state clearing.
tag.setPerformClearTagStateForTagPoolingServers(true);
tag.setBodyContent(mockBodyContent);
tag.setName("some.invalid.key.so.we.should.get.the.default.message");
int startStatus = tag.doStartTag();
// Ensure component tag state clearing is set true (to match tag).
setComponentTagClearTagState(tag, true);
tag.doEndTag();
assertEquals(startStatus, BodyTag.EVAL_BODY_BUFFERED);
assertEquals("Sample Of Default Message", writer.toString());
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
TextTag freshTag = new TextTag();
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.servlet.MockJspWriter in project struts by apache.
the class IfTagTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
// create the needed objects
tag = new IfTag();
stack = ActionContext.getContext().getValueStack();
// create the mock http servlet request
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
// create the mock page context
pageContext = new MockPageContext();
pageContext.setRequest(request);
pageContext.setJspWriter(new MockJspWriter());
// associate the tag with the mock page request
tag.setPageContext(pageContext);
}
use of com.mockobjects.servlet.MockJspWriter in project struts by apache.
the class PropertyTagTest method testDefaultValue_clearTagStateSet.
public void testDefaultValue_clearTagStateSet() {
PropertyTag tag = new PropertyTag();
Foo foo = new Foo();
stack.push(foo);
MockJspWriter jspWriter = new MockJspWriter();
jspWriter.setExpectedData("TEST");
MockPageContext pageContext = new MockPageContext();
pageContext.setJspWriter(jspWriter);
pageContext.setRequest(request);
// Explicitly request tag state clearing.
tag.setPerformClearTagStateForTagPoolingServers(true);
tag.setPageContext(pageContext);
tag.setValue("title");
tag.setDefault("TEST");
try {
tag.doStartTag();
// Ensure component tag state clearing is set true (to match tag).
setComponentTagClearTagState(tag, true);
} catch (JspException e) {
e.printStackTrace();
fail();
}
request.verify();
jspWriter.verify();
pageContext.verify();
try {
tag.doEndTag();
} catch (JspException e) {
e.printStackTrace();
fail();
}
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
PropertyTag freshTag = new PropertyTag();
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.", objectsAreReflectionEqual(tag, freshTag));
}
Aggregations