javax.servlet.jsp.tagext.BodyTag Java Examples
The following examples show how to use
javax.servlet.jsp.tagext.BodyTag.
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: OptionTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void canBeDisabledEvenWhenSelected() throws Exception { String selectName = "testBean.name"; getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false)); 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"); }
Example #2
Source File: HtmlEscapeTagTests.java From java-technology-stack with MIT License | 6 votes |
@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()); }
Example #3
Source File: OptionTagTests.java From java-technology-stack with MIT License | 6 votes |
@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); }
Example #4
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 #5
Source File: OptionTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void renderNotSelected() throws Exception { String selectName = "testBean.name"; getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false)); 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"); }
Example #6
Source File: OptionTagEnumTests.java From java-technology-stack with MIT License | 6 votes |
@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"); }
Example #7
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 #8
Source File: HtmlEscapeTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void escapeBody() 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); assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag()); assertEquals(Tag.SKIP_BODY, tag.doAfterBody()); assertEquals("test text", result.toString()); }
Example #9
Source File: OptionTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void withNoLabel() throws Exception { String selectName = "testBean.name"; getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false)); 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"); }
Example #10
Source File: ErrorsTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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"); }
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: HtmlEscapeTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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()); }
Example #15
Source File: OptionTagTests.java From java-technology-stack with MIT License | 6 votes |
@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"); }
Example #16
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 #17
Source File: OptionTagTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void withCustomObjectNotSelected() throws Exception { String selectName = "testBean.someNumber"; BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false); getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus); 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"); }
Example #18
Source File: OptionTagTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void withCustomObjectSelected() throws Exception { String selectName = "testBean.someNumber"; BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false); getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus); this.tag.setValue(new Float(12.34)); this.tag.setLabel("GBP 12.34"); 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.34"); assertContainsAttribute(output, "selected", "selected"); assertBlockTagContains(output, "GBP 12.34"); }
Example #19
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 #20
Source File: OptionTagTests.java From java-technology-stack with MIT License | 6 votes |
@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"); }
Example #21
Source File: OptionTagTests.java From java-technology-stack with MIT License | 6 votes |
@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"); }
Example #22
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 #23
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 #24
Source File: ErrorsTagTests.java From java-technology-stack 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 #25
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 #26
Source File: OptionTagTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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"); }
Example #27
Source File: ErrorsTagTests.java From java-technology-stack with MIT License | 6 votes |
@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"); }
Example #28
Source File: ErrorsTagTests.java From java-technology-stack 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 #29
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()); }
Example #30
Source File: HtmlEscapeTagTests.java From spring-analysis-note with MIT License | 6 votes |
@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()); }