use of org.springframework.web.testfixture.servlet.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();
assertThat(result).isEqualTo(BodyTag.EVAL_BODY_BUFFERED);
result = this.tag.doEndTag();
assertThat(result).isEqualTo(Tag.EVAL_PAGE);
assertThat(getOutput()).isEqualTo(mockContent);
}
use of org.springframework.web.testfixture.servlet.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();
assertThat(result).isEqualTo(BodyTag.EVAL_BODY_BUFFERED);
assertThat(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE)).isNotNull();
String bodyContent = "Foo";
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
this.tag.doEndTag();
this.tag.doFinally();
assertThat(getOutput()).isEqualTo(bodyContent);
assertThat(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE)).isNull();
}
use of org.springframework.web.testfixture.servlet.MockBodyContent in project spring-framework by spring-projects.
the class ErrorsTagTests method asBodyTagWithExistingMessagesAttribute.
@Test
public void asBodyTagWithExistingMessagesAttribute() throws Exception {
String existingAttribute = "something";
getPageContext().setAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, existingAttribute);
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();
assertThat(result).isEqualTo(BodyTag.EVAL_BODY_BUFFERED);
assertThat(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE)).isNotNull();
boolean condition = getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE) instanceof List;
assertThat(condition).isTrue();
String bodyContent = "Foo";
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
this.tag.doEndTag();
this.tag.doFinally();
assertThat(getOutput()).isEqualTo(bodyContent);
assertThat(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE)).isEqualTo(existingAttribute);
}
use of org.springframework.web.testfixture.servlet.MockBodyContent in project spring-framework by spring-projects.
the class ArgumentTagTests method argumentWithValueThenReleaseThenBodyValue.
@Test
public void argumentWithValueThenReleaseThenBodyValue() throws JspException {
tag.setValue("value3");
int action = tag.doEndTag();
assertThat(action).isEqualTo(Tag.EVAL_PAGE);
assertThat(parent.getArgument()).isEqualTo("value3");
tag.release();
parent = new MockArgumentSupportTag();
tag.setPageContext(createPageContext());
tag.setParent(parent);
tag.setBodyContent(new MockBodyContent("value4", new MockHttpServletResponse()));
action = tag.doEndTag();
assertThat(action).isEqualTo(Tag.EVAL_PAGE);
assertThat(parent.getArgument()).isEqualTo("value4");
}
use of org.springframework.web.testfixture.servlet.MockBodyContent in project spring-framework by spring-projects.
the class ParamTagTests method paramWithValueThenReleaseThenBodyValue.
@Test
public void paramWithValueThenReleaseThenBodyValue() throws JspException {
tag.setName("name1");
tag.setValue("value1");
int action = tag.doEndTag();
assertThat(action).isEqualTo(Tag.EVAL_PAGE);
assertThat(parent.getParam().getName()).isEqualTo("name1");
assertThat(parent.getParam().getValue()).isEqualTo("value1");
tag.release();
parent = new MockParamSupportTag();
tag.setPageContext(createPageContext());
tag.setParent(parent);
tag.setName("name2");
tag.setBodyContent(new MockBodyContent("value2", new MockHttpServletResponse()));
action = tag.doEndTag();
assertThat(action).isEqualTo(Tag.EVAL_PAGE);
assertThat(parent.getParam().getName()).isEqualTo("name2");
assertThat(parent.getParam().getValue()).isEqualTo("value2");
}
Aggregations