use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class ThemeTagTests method requestContext.
@Test
@SuppressWarnings("rawtypes")
void requestContext() throws ServletException {
PageContext pc = createPageContext();
RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
assertThat(rc.getThemeMessage("themetest")).isEqualTo("theme test message");
assertThat(rc.getThemeMessage("themetest", (String[]) null)).isEqualTo("theme test message");
assertThat(rc.getThemeMessage("themetest", "default")).isEqualTo("theme test message");
assertThat(rc.getThemeMessage("themetest", (Object[]) null, "default")).isEqualTo("theme test message");
assertThat(rc.getThemeMessage("themetestArgs", new String[] { "arg1" })).isEqualTo("theme test message arg1");
assertThat(rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] { "arg1" }))).isEqualTo("theme test message arg1");
assertThat(rc.getThemeMessage("themetesta", "default")).isEqualTo("default");
assertThat(rc.getThemeMessage("themetesta", (List) null, "default")).isEqualTo("default");
MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] { "themetest" });
assertThat(rc.getThemeMessage(resolvable)).isEqualTo("theme test message");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithGlobalErrorsAndDefaultMessageOnly.
@Test
void bindTagWithGlobalErrorsAndDefaultMessageOnly() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
errors.reject(null, "message1");
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat(status.getExpression() == null).as("Correct expression").isTrue();
assertThat(status.getValue() == null).as("Correct value").isTrue();
assertThat("".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorMessages().length == 1).as("Correct errorMessages").isTrue();
assertThat("message1".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("message1".equals(status.getErrorMessagesAsString(","))).as("Correct errorMessagesAsString").isTrue();
tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.*");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat("*".equals(status.getExpression())).as("Correct expression").isTrue();
assertThat(status.getValue() == null).as("Correct value").isTrue();
assertThat("".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorMessages().length == 1).as("Correct errorMessages").isTrue();
assertThat("message1".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("message1".equals(status.getErrorMessagesAsString(","))).as("Correct errorMessagesAsString").isTrue();
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithSetValueAndHtmlEscaping.
@Test
void bindTagWithSetValueAndHtmlEscaping() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.someSet");
tag.setHtmlEscape(true);
pc.getRequest().setAttribute("tb", new TestBean("juergen&eva", 99));
tag.doStartTag();
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status.getExpression()).isEqualTo("someSet");
boolean condition = status.getValue() instanceof Set;
assertThat(condition).isTrue();
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithBeanButWithoutErrorsInstance.
@Test
void bindTagWithBeanButWithoutErrorsInstance() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb");
pc.getRequest().setAttribute("tb", new TestBean("juergen", 99));
tag.doStartTag();
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status.getExpression()).isNull();
assertThat(status.getValue()).isNull();
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method nestedPathWithBindTag.
@Test
void nestedPathWithBindTag() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
NestedPathTag nestedPathTag = new NestedPathTag();
nestedPathTag.setPath("tb");
nestedPathTag.setPageContext(pc);
nestedPathTag.doStartTag();
BindTag bindTag = new BindTag();
bindTag.setPageContext(pc);
bindTag.setPath("name");
assertThat(bindTag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat(status.getPath()).isEqualTo("tb.name");
assertThat(status.getDisplayValue()).as("Correct field value").isEqualTo("");
BindTag bindTag2 = new BindTag();
bindTag2.setPageContext(pc);
bindTag2.setPath("age");
assertThat(bindTag2.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
BindStatus status2 = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status2 != null).as("Has status variable").isTrue();
assertThat(status2.getPath()).isEqualTo("tb.age");
assertThat(status2.getDisplayValue()).as("Correct field value").isEqualTo("0");
bindTag2.doEndTag();
BindStatus status3 = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status3).as("Status matches previous status").isSameAs(status);
assertThat(status.getPath()).isEqualTo("tb.name");
assertThat(status.getDisplayValue()).as("Correct field value").isEqualTo("");
bindTag.doEndTag();
nestedPathTag.doEndTag();
}
Aggregations