use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class HtmlEscapeTagTests method escapeBodyWithJavaScriptEscape.
@Test
void escapeBodyWithJavaScriptEscape() 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.setJavaScriptEscape(true);
assertThat(tag.doStartTag()).isEqualTo(BodyTag.EVAL_BODY_BUFFERED);
assertThat(tag.doAfterBody()).isEqualTo(Tag.SKIP_BODY);
assertThat(result.toString()).as("Correct content").isEqualTo("\\' test & text \\\\");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class HtmlEscapeTagTests method escapeBodyWithHtmlEscapeAndJavaScriptEscape.
@Test
void escapeBodyWithHtmlEscapeAndJavaScriptEscape() 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);
tag.setJavaScriptEscape(true);
assertThat(tag.doStartTag()).isEqualTo(BodyTag.EVAL_BODY_BUFFERED);
assertThat(tag.doAfterBody()).isEqualTo(Tag.SKIP_BODY);
assertThat(result.toString()).as("Correct content").isEqualTo("' test & text \\\\");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class MessageTagTests method nullMessageSource.
@Test
void nullMessageSource() throws JspException {
PageContext pc = createPageContext();
ConfigurableWebApplicationContext ctx = (ConfigurableWebApplicationContext) RequestContextUtils.findWebApplicationContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
ctx.close();
MessageTag tag = new MessageTag();
tag.setPageContext(pc);
tag.setCode("test");
tag.setVar("testvar2");
tag.doStartTag();
assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class MessageTagTests method messageTagWithCodeAndArgument.
@Test
void messageTagWithCodeAndArgument() 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("arg1");
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 arg1 message {1}");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class MessageTagTests method messageWithVar.
@Test
void messageWithVar() throws JspException {
PageContext pc = createPageContext();
MessageTag tag = new MessageTag();
tag.setPageContext(pc);
tag.setText("text & text");
tag.setVar("testvar");
tag.doStartTag();
assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
assertThat(pc.getAttribute("testvar")).isEqualTo("text & text");
tag.release();
// try to reuse
tag.setPageContext(pc);
tag.setCode("test");
tag.setVar("testvar");
tag.doStartTag();
assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
assertThat(pc.getAttribute("testvar")).as("Correct message").isEqualTo("test message");
}
Aggregations