类javax.servlet.jsp.tagext.BodyTag源码实例Demo

下面列出了怎么用javax.servlet.jsp.tagext.BodyTag的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: spring-analysis-note   文件: ErrorsTagTests.java
@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());
}
 
源代码2 项目: spring-analysis-note   文件: ErrorsTagTests.java
@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");
}
 
源代码3 项目: spring-analysis-note   文件: ErrorsTagTests.java
@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");
}
 
源代码4 项目: spring-analysis-note   文件: ErrorsTagTests.java
@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");
}
 
源代码5 项目: spring-analysis-note   文件: ErrorsTagTests.java
@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 &lt;&gt; Message");
	assertBlockTagContains(output, "Too &amp; Short");
}
 
源代码6 项目: spring4-understanding   文件: OptionTagTests.java
@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");
}
 
源代码7 项目: spring-analysis-note   文件: ErrorsTagTests.java
@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));
}
 
@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");
}
 
源代码9 项目: spring-analysis-note   文件: ErrorsTagTests.java
/**
 * 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));
}
 
源代码10 项目: spring-analysis-note   文件: OptionTagTests.java
@Test
public void canBeDisabledEvenWhenSelected() 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.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");
}
 
源代码11 项目: spring-analysis-note   文件: OptionTagTests.java
@Test
public void renderNotSelected() 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.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");
}
 
源代码12 项目: spring-analysis-note   文件: OptionTagTests.java
@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");
}
 
源代码13 项目: spring-analysis-note   文件: OptionTagTests.java
@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");
}
 
源代码14 项目: spring4-understanding   文件: HtmlEscapeTagTests.java
@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", "&#39; test &amp; text \\\\", result.toString());
}
 
源代码15 项目: spring4-understanding   文件: OptionTagTests.java
@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);
}
 
源代码16 项目: spring-analysis-note   文件: OptionTagTests.java
@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");
}
 
源代码17 项目: spring-analysis-note   文件: OptionTagTests.java
@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);
}
 
源代码18 项目: spring-analysis-note   文件: OptionTagTests.java
@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);
}
 
源代码19 项目: spring-analysis-note   文件: OptionTagTests.java
@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);
}
 
源代码20 项目: spring-analysis-note   文件: OptionTagTests.java
@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);
}
 
源代码21 项目: velocity-tools   文件: JspUtilsTest.java
/**
 * Test method for {@link org.apache.velocity.tools.view.jsp.jspimpl.JspUtils#executeTag(org.apache.velocity.context.InternalContextAdapter, org.apache.velocity.runtime.parser.node.Node, javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)}.
 * @throws JspException If something goes wrong.
 * @throws IOException If something goes wrong.
 * @throws ParseErrorException If something goes wrong.
 * @throws ResourceNotFoundException If something goes wrong.
 * @throws MethodInvocationException If something goes wrong.
 */
@Test
public void testExecuteTag() throws JspException, MethodInvocationException, ResourceNotFoundException, ParseErrorException, IOException
{
    InternalContextAdapter context = createMock(InternalContextAdapter.class);
    Node node = createMock(Node.class);
    PageContext pageContext = createMock(PageContext.class);
    BodyTag tag = createMock(BodyTag.class);
    ASTBlock block = createMock(ASTBlock.class);
    JspWriter writer = createMock(JspWriter.class);

    expect(tag.doStartTag()).andReturn(BodyTag.EVAL_BODY_BUFFERED);
    tag.setBodyContent(isA(VelocityBodyContent.class));
    tag.doInitBody();
    expect(node.jjtGetChild(1)).andReturn(block);
    expect(tag.doAfterBody()).andReturn(BodyTag.SKIP_BODY);
    expect(tag.doEndTag()).andReturn(BodyTag.EVAL_PAGE);
    expect(pageContext.getOut()).andReturn(writer);
    expect(block.render(eq(context), isA(StringWriter.class))).andReturn(true);

    replay(context, node, pageContext, block, tag, writer);
    JspUtils.executeTag(context, node, pageContext, tag);
    verify(context, node, pageContext, block, tag, writer);
}
 
源代码22 项目: spring4-understanding   文件: OptionTagTests.java
@Test
public void withCustomObjectNotSelected() throws Exception {
	String selectName = "testBean.someNumber";
	getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
	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");
}
 
源代码23 项目: spring4-understanding   文件: HtmlEscapeTagTests.java
@Test
public void escapeBodyWithHtmlEscape() 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);
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
	assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
	assertEquals("test &amp; text", result.toString());
}
 
源代码24 项目: spring-analysis-note   文件: HtmlEscapeTagTests.java
@Test
public void escapeBodyWithHtmlEscape() 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);
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
	assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
	assertEquals("test &amp; text", result.toString());
}
 
源代码25 项目: spring-analysis-note   文件: HtmlEscapeTagTests.java
@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());
}
 
源代码26 项目: spring-analysis-note   文件: HtmlEscapeTagTests.java
@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", "&#39; test &amp; text \\\\", result.toString());
}
 
源代码27 项目: java-technology-stack   文件: ErrorsTagTests.java
@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());
}
 
源代码28 项目: java-technology-stack   文件: ErrorsTagTests.java
@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");
}
 
源代码29 项目: java-technology-stack   文件: ErrorsTagTests.java
@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");
}
 
源代码30 项目: spring4-understanding   文件: OptionTagTests.java
@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");
}
 
 类所在包
 类方法
 同包方法