use of org.springframework.mock.web.test.MockBodyContent in project spring-framework by spring-projects.
the class OptionTagTests method asBodyTag.
@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);
}
use of org.springframework.mock.web.test.MockBodyContent in project spring-framework by spring-projects.
the class OptionTagTests method asBodyTagSelected.
@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);
}
use of org.springframework.mock.web.test.MockBodyContent in project spring-framework by spring-projects.
the class OptionTagTests method asBodyTagCollapsed.
@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);
}
use of org.springframework.mock.web.test.MockBodyContent in project spring-framework by spring-projects.
the class ErrorsTagTests method withExplicitNonWhitespaceBodyContent.
@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());
}
use of org.springframework.mock.web.test.MockBodyContent in project spring-framework by spring-projects.
the class ErrorsTagTests method asBodyTag.
@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));
}
Aggregations