use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class HtmlEscapeTagTests method escapeBodyWithHtmlEscape.
@Test
void escapeBodyWithHtmlEscape() throws JspException {
PageContext pc = createPageContext();
final StringBuilder result = new StringBuilder();
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);
assertThat(tag.doStartTag()).isEqualTo(BodyTag.EVAL_BODY_BUFFERED);
assertThat(tag.doAfterBody()).isEqualTo(Tag.SKIP_BODY);
assertThat(result.toString()).isEqualTo("test & text");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class MessageTagTests method messageTagWithTextAndJavaScriptEscape.
@Test
void messageTagWithTextAndJavaScriptEscape() throws JspException {
PageContext pc = createPageContext();
final StringBuilder message = new StringBuilder();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setText("' test & text \\");
tag.setJavaScriptEscape(true);
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
assertThat(message.toString()).as("Correct message").isEqualTo("\\' test & text \\\\");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class MessageTagTests method messageTagWithText.
@Test
void messageTagWithText() throws JspException {
PageContext pc = createPageContext();
final StringBuilder message = new StringBuilder();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setText("test & text é");
tag.setHtmlEscape(true);
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
assertThat(message.toString().startsWith("test & text &")).as("Correct message").isTrue();
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class MessageTagTests method messageTagWithCodeAndObjectArgument.
@Test
void messageTagWithCodeAndObjectArgument() throws JspException {
PageContext pc = createPageContext();
final StringBuilder message = new StringBuilder();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setCode("testArgs");
tag.setArguments(5);
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
assertThat(message.toString()).as("Correct message").isEqualTo("test 5 message {1}");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class MessageTagTests method messageTagWithMessageSourceResolvable.
@Test
void messageTagWithMessageSourceResolvable() throws JspException {
PageContext pc = createPageContext();
final StringBuilder message = new StringBuilder();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setMessage(new DefaultMessageSourceResolvable("test"));
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
assertThat(message.toString()).as("Correct message").isEqualTo("test message");
}
Aggregations