use of org.springframework.web.bind.ServletRequestDataBinder in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithGlobalErrorsAndNoDefaultMessage.
@Test
void bindTagWithGlobalErrorsAndNoDefaultMessage() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
errors.reject("code1");
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.getErrorCodes().length == 1).as("Correct errorCodes").isTrue();
assertThat("code1".equals(status.getErrorCode())).as("Correct errorCode").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.getErrorCodes().length == 1).as("Correct errorCodes").isTrue();
assertThat("code1".equals(status.getErrorCode())).as("Correct errorCode").isTrue();
}
Aggregations