下面列出了怎么用javax.servlet.jsp.tagext.BodyTag的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void withExplicitNonWhitespaceBodyContent() throws Exception {
String mockContent = "This is some explicit body content";
this.tag.setBodyContent(new MockBodyContent(mockContent, getWriter()));
// construct an errors instance of the tag
TestBean target = new TestBean();
target.setName("Rob Harrop");
Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.rejectValue("name", "some.code", "Default Message");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
assertEquals(mockContent, getOutput());
}
@Test
public void withExplicitWhitespaceBodyContent() throws Exception {
this.tag.setBodyContent(new MockBodyContent("\t\n ", getWriter()));
// construct an errors instance of the tag
TestBean target = new TestBean();
target.setName("Rob Harrop");
Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.rejectValue("name", "some.code", "Default Message");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertElementTagOpened(output);
assertElementTagClosed(output);
assertContainsAttribute(output, "id", "name.errors");
assertBlockTagContains(output, "Default Message");
}
@Test
public void withExplicitEmptyWhitespaceBodyContent() throws Exception {
this.tag.setBodyContent(new MockBodyContent("", getWriter()));
// construct an errors instance of the tag
TestBean target = new TestBean();
target.setName("Rob Harrop");
Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.rejectValue("name", "some.code", "Default Message");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertElementTagOpened(output);
assertElementTagClosed(output);
assertContainsAttribute(output, "id", "name.errors");
assertBlockTagContains(output, "Default Message");
}
@Test
public void withErrors() throws Exception {
// construct an errors instance of the tag
TestBean target = new TestBean();
target.setName("Rob Harrop");
Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.rejectValue("name", "some.code", "Default Message");
errors.rejectValue("name", "too.short", "Too Short");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertElementTagOpened(output);
assertElementTagClosed(output);
assertContainsAttribute(output, "id", "name.errors");
assertBlockTagContains(output, "<br/>");
assertBlockTagContains(output, "Default Message");
assertBlockTagContains(output, "Too Short");
}
@Test
public void withEscapedErrors() throws Exception {
// construct an errors instance of the tag
TestBean target = new TestBean();
target.setName("Rob Harrop");
Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.rejectValue("name", "some.code", "Default <> Message");
errors.rejectValue("name", "too.short", "Too & Short");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertElementTagOpened(output);
assertElementTagClosed(output);
assertContainsAttribute(output, "id", "name.errors");
assertBlockTagContains(output, "<br/>");
assertBlockTagContains(output, "Default <> Message");
assertBlockTagContains(output, "Too & Short");
}
@Test
public void withCustomObjectAndEditorNotSelected() throws Exception {
final PropertyEditor floatEditor = new SimpleFloatEditor();
String selectName = "testBean.someNumber";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
public PropertyEditor getEditor() {
return floatEditor;
}
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue(new Float(12.35));
this.tag.setLabel("12.35f");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertAttributeNotPresent(output, "selected");
assertBlockTagContains(output, "12.35f");
}
@Test
public void asBodyTag() throws Exception {
Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
errors.rejectValue("name", "some.code", "Default Message");
errors.rejectValue("name", "too.short", "Too Short");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
String bodyContent = "Foo";
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
this.tag.doEndTag();
this.tag.doFinally();
assertEquals(bodyContent, getOutput());
assertNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
}
@Test
@SuppressWarnings("rawtypes")
public void withJavaEnum() throws Exception {
GenericBean testBean = new GenericBean();
testBean.setCustomEnum(CustomEnum.VALUE_1);
getPageContext().getRequest().setAttribute("testBean", testBean);
String selectName = "testBean.customEnum";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
this.tag.setValue("VALUE_1");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getWriter().toString();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "value", "VALUE_1");
assertContainsAttribute(output, "selected", "selected");
}
/**
* https://jira.spring.io/browse/SPR-2788
*/
@Test
public void asBodyTagWithErrorsAndExistingMessagesAttributeInNonPageScopeAreNotClobbered() throws Exception {
String existingAttribute = "something";
getPageContext().setAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, existingAttribute, PageContext.APPLICATION_SCOPE);
Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
errors.rejectValue("name", "some.code", "Default Message");
errors.rejectValue("name", "too.short", "Too Short");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
assertTrue(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE) instanceof List);
String bodyContent = "Foo";
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
this.tag.doEndTag();
this.tag.doFinally();
assertEquals(bodyContent, getOutput());
assertEquals(existingAttribute,
getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, PageContext.APPLICATION_SCOPE));
}
@Test
public void canBeDisabledEvenWhenSelected() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue("bar");
this.tag.setLabel("Bar");
this.tag.setDisabled(true);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "value", "bar");
assertContainsAttribute(output, "disabled", "disabled");
assertBlockTagContains(output, "Bar");
}
@Test
public void renderNotSelected() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue("bar");
this.tag.setLabel("Bar");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "value", "bar");
assertBlockTagContains(output, "Bar");
}
@Test
public void renderSelected() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setId("myOption");
this.tag.setValue("foo");
this.tag.setLabel("Foo");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "id", "myOption");
assertContainsAttribute(output, "value", "foo");
assertContainsAttribute(output, "selected", "selected");
assertBlockTagContains(output, "Foo");
}
@Test
public void withNoLabel() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue("bar");
this.tag.setCssClass("myClass");
this.tag.setOnclick("CLICK");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "value", "bar");
assertContainsAttribute(output, "class", "myClass");
assertContainsAttribute(output, "onclick", "CLICK");
assertBlockTagContains(output, "bar");
}
@Test
public void escapeBodyWithHtmlEscapeAndJavaScriptEscape() throws JspException {
PageContext pc = createPageContext();
final StringBuffer result = new StringBuffer();
EscapeBodyTag tag = new EscapeBodyTag() {
@Override
protected String readBodyContent() {
return "' test & text \\";
}
@Override
protected void writeBodyContent(String content) {
result.append(content);
}
};
tag.setPageContext(pc);
tag.setHtmlEscape(true);
tag.setJavaScriptEscape(true);
assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
assertEquals("Correct content", "' test & text \\\\", result.toString());
}
@Test
public void asBodyTagWithEditor() throws Exception {
String selectName = "testBean.stringArray";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
public PropertyEditor getEditor() {
return new RulesVariantEditor();
}
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
RulesVariant rulesVariant = new RulesVariant("someRules", "someVariant");
this.tag.setValue(rulesVariant);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
assertEquals(rulesVariant, getPageContext().getAttribute("value"));
assertEquals(rulesVariant.toId(), getPageContext().getAttribute("displayValue"));
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
}
@Test
public void withCustomObjectAndEditorNotSelected() throws Exception {
final PropertyEditor floatEditor = new SimpleFloatEditor();
String selectName = "testBean.someNumber";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
public PropertyEditor getEditor() {
return floatEditor;
}
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue(new Float(12.35));
this.tag.setLabel("12.35f");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertAttributeNotPresent(output, "selected");
assertBlockTagContains(output, "12.35f");
}
@Test
public void asBodyTag() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
String bodyContent = "some content";
this.tag.setValue("foo");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "selected", "selected");
assertBlockTagContains(output, bodyContent);
}
@Test
public void asBodyTagSelected() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
String bodyContent = "some content";
this.tag.setValue("Rob Harrop");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertBlockTagContains(output, bodyContent);
}
@Test
public void asBodyTagCollapsed() throws Exception {
String selectName = "testBean.name";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
String bodyContent = "some content";
this.tag.setValue(bodyContent);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "value", bodyContent);
assertBlockTagContains(output, bodyContent);
}
@Test
public void asBodyTagWithEditor() throws Exception {
String selectName = "testBean.stringArray";
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
@Override
public PropertyEditor getEditor() {
return new RulesVariantEditor();
}
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
RulesVariant rulesVariant = new RulesVariant("someRules", "someVariant");
this.tag.setValue(rulesVariant);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
assertEquals(rulesVariant, getPageContext().getAttribute("value"));
assertEquals(rulesVariant.toId(), getPageContext().getAttribute("displayValue"));
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
}
/**
* Test method for {@link org.apache.velocity.tools.view.jsp.jspimpl.JspUtils#executeTag(org.apache.velocity.context.InternalContextAdapter, org.apache.velocity.runtime.parser.node.Node, javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)}.
* @throws JspException If something goes wrong.
* @throws IOException If something goes wrong.
* @throws ParseErrorException If something goes wrong.
* @throws ResourceNotFoundException If something goes wrong.
* @throws MethodInvocationException If something goes wrong.
*/
@Test
public void testExecuteTag() throws JspException, MethodInvocationException, ResourceNotFoundException, ParseErrorException, IOException
{
InternalContextAdapter context = createMock(InternalContextAdapter.class);
Node node = createMock(Node.class);
PageContext pageContext = createMock(PageContext.class);
BodyTag tag = createMock(BodyTag.class);
ASTBlock block = createMock(ASTBlock.class);
JspWriter writer = createMock(JspWriter.class);
expect(tag.doStartTag()).andReturn(BodyTag.EVAL_BODY_BUFFERED);
tag.setBodyContent(isA(VelocityBodyContent.class));
tag.doInitBody();
expect(node.jjtGetChild(1)).andReturn(block);
expect(tag.doAfterBody()).andReturn(BodyTag.SKIP_BODY);
expect(tag.doEndTag()).andReturn(BodyTag.EVAL_PAGE);
expect(pageContext.getOut()).andReturn(writer);
expect(block.render(eq(context), isA(StringWriter.class))).andReturn(true);
replay(context, node, pageContext, block, tag, writer);
JspUtils.executeTag(context, node, pageContext, tag);
verify(context, node, pageContext, block, tag, writer);
}
@Test
public void withCustomObjectNotSelected() throws Exception {
String selectName = "testBean.someNumber";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
this.tag.setValue(new Float(12.35));
this.tag.setLabel("GBP 12.35");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "value", "12.35");
assertAttributeNotPresent(output, "selected");
assertBlockTagContains(output, "GBP 12.35");
}
@Test
public void escapeBodyWithHtmlEscape() throws JspException {
PageContext pc = createPageContext();
final StringBuffer result = new StringBuffer();
EscapeBodyTag tag = new EscapeBodyTag() {
@Override
protected String readBodyContent() {
return "test & text";
}
@Override
protected void writeBodyContent(String content) {
result.append(content);
}
};
tag.setPageContext(pc);
tag.setHtmlEscape(true);
assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
assertEquals("test & text", result.toString());
}
@Test
public void escapeBodyWithHtmlEscape() throws JspException {
PageContext pc = createPageContext();
final StringBuffer result = new StringBuffer();
EscapeBodyTag tag = new EscapeBodyTag() {
@Override
protected String readBodyContent() {
return "test & text";
}
@Override
protected void writeBodyContent(String content) {
result.append(content);
}
};
tag.setPageContext(pc);
tag.setHtmlEscape(true);
assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
assertEquals("test & text", result.toString());
}
@Test
public void escapeBodyWithJavaScriptEscape() throws JspException {
PageContext pc = createPageContext();
final StringBuffer result = new StringBuffer();
EscapeBodyTag tag = new EscapeBodyTag() {
@Override
protected String readBodyContent() {
return "' test & text \\";
}
@Override
protected void writeBodyContent(String content) {
result.append(content);
}
};
tag.setPageContext(pc);
tag.setJavaScriptEscape(true);
assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
assertEquals("Correct content", "\\' test & text \\\\", result.toString());
}
@Test
public void escapeBodyWithHtmlEscapeAndJavaScriptEscape() throws JspException {
PageContext pc = createPageContext();
final StringBuffer result = new StringBuffer();
EscapeBodyTag tag = new EscapeBodyTag() {
@Override
protected String readBodyContent() {
return "' test & text \\";
}
@Override
protected void writeBodyContent(String content) {
result.append(content);
}
};
tag.setPageContext(pc);
tag.setHtmlEscape(true);
tag.setJavaScriptEscape(true);
assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
assertEquals("Correct content", "' test & text \\\\", result.toString());
}
@Test
public void withExplicitNonWhitespaceBodyContent() throws Exception {
String mockContent = "This is some explicit body content";
this.tag.setBodyContent(new MockBodyContent(mockContent, getWriter()));
// construct an errors instance of the tag
TestBean target = new TestBean();
target.setName("Rob Harrop");
Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.rejectValue("name", "some.code", "Default Message");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
assertEquals(mockContent, getOutput());
}
@Test
public void withExplicitWhitespaceBodyContent() throws Exception {
this.tag.setBodyContent(new MockBodyContent("\t\n ", getWriter()));
// construct an errors instance of the tag
TestBean target = new TestBean();
target.setName("Rob Harrop");
Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.rejectValue("name", "some.code", "Default Message");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertElementTagOpened(output);
assertElementTagClosed(output);
assertContainsAttribute(output, "id", "name.errors");
assertBlockTagContains(output, "Default Message");
}
@Test
public void withErrors() throws Exception {
// construct an errors instance of the tag
TestBean target = new TestBean();
target.setName("Rob Harrop");
Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.rejectValue("name", "some.code", "Default Message");
errors.rejectValue("name", "too.short", "Too Short");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertElementTagOpened(output);
assertElementTagClosed(output);
assertContainsAttribute(output, "id", "name.errors");
assertBlockTagContains(output, "<br/>");
assertBlockTagContains(output, "Default Message");
assertBlockTagContains(output, "Too Short");
}
@Test
public void renderSelected() throws Exception {
String selectName = "testBean.name";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
this.tag.setId("myOption");
this.tag.setValue("foo");
this.tag.setLabel("Foo");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
String output = getOutput();
assertOptionTagOpened(output);
assertOptionTagClosed(output);
assertContainsAttribute(output, "id", "myOption");
assertContainsAttribute(output, "value", "foo");
assertContainsAttribute(output, "selected", "selected");
assertBlockTagContains(output, "Foo");
}