Search in sources :

Example 11 with MockBodyContent

use of org.springframework.mock.web.test.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();
    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));
}
Also used : Errors(org.springframework.validation.Errors) MockBodyContent(org.springframework.mock.web.test.MockBodyContent) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) TestBean(org.springframework.tests.sample.beans.TestBean) List(java.util.List) Test(org.junit.Test)

Example 12 with MockBodyContent

use of org.springframework.mock.web.test.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();
    assertEquals(Tag.EVAL_PAGE, action);
    assertEquals("name1", parent.getParam().getName());
    assertEquals("value1", parent.getParam().getValue());
    tag.release();
    parent = new MockParamSupportTag();
    tag.setPageContext(createPageContext());
    tag.setParent(parent);
    tag.setName("name2");
    tag.setBodyContent(new MockBodyContent("value2", new MockHttpServletResponse()));
    action = tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, action);
    assertEquals("name2", parent.getParam().getName());
    assertEquals("value2", parent.getParam().getValue());
}
Also used : MockBodyContent(org.springframework.mock.web.test.MockBodyContent) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 13 with MockBodyContent

use of org.springframework.mock.web.test.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();
    assertEquals(Tag.EVAL_PAGE, action);
    assertEquals("value3", parent.getArgument());
    tag.release();
    parent = new MockArgumentSupportTag();
    tag.setPageContext(createPageContext());
    tag.setParent(parent);
    tag.setBodyContent(new MockBodyContent("value4", new MockHttpServletResponse()));
    action = tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, action);
    assertEquals("value4", parent.getArgument());
}
Also used : MockBodyContent(org.springframework.mock.web.test.MockBodyContent) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 MockBodyContent (org.springframework.mock.web.test.MockBodyContent)13 TestBean (org.springframework.tests.sample.beans.TestBean)6 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)6 Errors (org.springframework.validation.Errors)6 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)4 BindStatus (org.springframework.web.servlet.support.BindStatus)3 List (java.util.List)2