org.springframework.mock.web.test.MockBodyContent Java Examples
The following examples show how to use
org.springframework.mock.web.test.MockBodyContent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ErrorsTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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"); }
Example #2
Source File: ErrorsTagTests.java From java-technology-stack with MIT License | 6 votes |
/** * 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)); }
Example #3
Source File: ErrorsTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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()); }
Example #4
Source File: OptionTagTests.java From java-technology-stack with MIT License | 6 votes |
@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); }
Example #5
Source File: OptionTagTests.java From java-technology-stack with MIT License | 6 votes |
@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); }
Example #6
Source File: ArgumentTagTests.java From java-technology-stack with MIT License | 6 votes |
@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()); }
Example #7
Source File: ParamTagTests.java From java-technology-stack with MIT License | 6 votes |
@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()); }
Example #8
Source File: ErrorsTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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()); }
Example #9
Source File: ErrorsTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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"); }
Example #10
Source File: OptionTagTests.java From java-technology-stack with MIT License | 6 votes |
@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); }
Example #11
Source File: ErrorsTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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)); }
Example #12
Source File: ErrorsTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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)); }
Example #13
Source File: ErrorsTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * 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)); }
Example #14
Source File: OptionTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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); }
Example #15
Source File: OptionTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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); }
Example #16
Source File: OptionTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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); }
Example #17
Source File: ArgumentTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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()); }
Example #18
Source File: ParamTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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()); }
Example #19
Source File: ErrorsTagTests.java From java-technology-stack with MIT License | 6 votes |
@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)); }
Example #20
Source File: ErrorsTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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"); }
Example #21
Source File: ErrorsTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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"); }
Example #22
Source File: ErrorsTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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)); }
Example #23
Source File: ErrorsTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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)); }
Example #24
Source File: ErrorsTagTests.java From spring-analysis-note with MIT License | 6 votes |
/** * 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)); }
Example #25
Source File: OptionTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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); }
Example #26
Source File: OptionTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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); }
Example #27
Source File: OptionTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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); }
Example #28
Source File: ArgumentTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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()); }
Example #29
Source File: ParamTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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()); }
Example #30
Source File: ErrorsTagTests.java From java-technology-stack with MIT License | 6 votes |
@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()); }