use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class MessageTagTests method messageTagWithTextAndHtmlEscapeAndJavaScriptEscape.
@Test
void messageTagWithTextAndHtmlEscapeAndJavaScriptEscape() 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);
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 messageTagWithCodeAndNestedArguments.
@Test
void messageTagWithCodeAndNestedArguments() 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");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
tag.addArgument("arg1");
tag.addArgument(6);
assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
assertThat(message.toString()).as("Correct message").isEqualTo("test arg1 message 6");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class MessageTagTests method requestContext.
@Test
@SuppressWarnings("rawtypes")
void requestContext() throws ServletException {
PageContext pc = createPageContext();
RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
assertThat(rc.getMessage("test")).isEqualTo("test message");
assertThat(rc.getMessage("test", (Object[]) null)).isEqualTo("test message");
assertThat(rc.getMessage("test", "default")).isEqualTo("test message");
assertThat(rc.getMessage("test", (Object[]) null, "default")).isEqualTo("test message");
assertThat(rc.getMessage("testArgs", new String[] { "arg1", "arg2" }, "default")).isEqualTo("test arg1 message arg2");
assertThat(rc.getMessage("testArgs", Arrays.asList(new String[] { "arg1", "arg2" }), "default")).isEqualTo("test arg1 message arg2");
assertThat(rc.getMessage("testa", "default")).isEqualTo("default");
assertThat(rc.getMessage("testa", (List) null, "default")).isEqualTo("default");
MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] { "test" });
assertThat(rc.getMessage(resolvable)).isEqualTo("test message");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method propertyExposing.
@Test
void propertyExposing() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
tb.setName("name1");
Errors errors = new BindException(tb, "tb");
errors.rejectValue("name", "code1", null, "message & 1");
errors.rejectValue("name", "code2", null, "message2");
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
// test global property (should be null)
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
assertThat(tag.getProperty()).isNull();
// test property set (tb.name)
tag.release();
tag.setPageContext(pc);
tag.setPath("tb.name");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
assertThat(tag.getProperty()).isEqualTo("name");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class ParamTagTests method setUp.
@BeforeEach
public void setUp() throws Exception {
PageContext context = createPageContext();
tag.setPageContext(context);
tag.setParent(parent);
}
Aggregations