use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithMappedProperties.
@Test
void bindTagWithMappedProperties() throws JspException {
PageContext pc = createPageContext();
IndexedTestBean tb = new IndexedTestBean();
Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
errors.rejectValue("map[key1]", "code1", "message1");
errors.rejectValue("map[key1]", "code2", "message2");
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.map[key1]");
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("map[key1]".equals(status.getExpression())).as("Correct expression").isTrue();
boolean condition = status.getValue() instanceof TestBean;
assertThat(condition).as("Value is TestBean").isTrue();
assertThat("name4".equals(((TestBean) status.getValue()).getName())).as("Correct value").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 2).as("Correct errorCodes").isTrue();
assertThat(status.getErrorMessages().length == 2).as("Correct errorMessages").isTrue();
assertThat("code1".equals(status.getErrorCodes()[0])).as("Correct errorCode").isTrue();
assertThat("code2".equals(status.getErrorCodes()[1])).as("Correct errorCode").isTrue();
assertThat("message1".equals(status.getErrorMessages()[0])).as("Correct errorMessage").isTrue();
assertThat("message2".equals(status.getErrorMessages()[1])).as("Correct errorMessage").isTrue();
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithoutErrors.
@Test
void bindTagWithoutErrors() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
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();
boolean condition = !status.isError();
assertThat(condition).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 0).as("Correct errorCodes").isTrue();
assertThat(status.getErrorMessages().length == 0).as("Correct errorMessages").isTrue();
assertThat("".equals(status.getErrorCode())).as("Correct errorCode").isTrue();
assertThat("".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("".equals(status.getErrorMessagesAsString(","))).as("Correct errorMessagesAsString").isTrue();
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method nestedPathWithBindTagWithIgnoreNestedPath.
@Test
void nestedPathWithBindTagWithIgnoreNestedPath() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb2").getBindingResult();
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb2", errors);
NestedPathTag tag = new NestedPathTag();
tag.setPath("tb");
tag.setPageContext(pc);
tag.doStartTag();
BindTag bindTag = new BindTag();
bindTag.setPageContext(pc);
bindTag.setIgnoreNestedPath(true);
bindTag.setPath("tb2.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("tb2.name");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithIndexedProperties.
@Test
void bindTagWithIndexedProperties() throws JspException {
PageContext pc = createPageContext();
IndexedTestBean tb = new IndexedTestBean();
Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
errors.rejectValue("array[0]", "code1", "message1");
errors.rejectValue("array[0]", "code2", "message2");
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.array[0]");
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("array[0]".equals(status.getExpression())).as("Correct expression").isTrue();
boolean condition = status.getValue() instanceof TestBean;
assertThat(condition).as("Value is TestBean").isTrue();
assertThat("name0".equals(((TestBean) status.getValue()).getName())).as("Correct value").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 2).as("Correct errorCodes").isTrue();
assertThat(status.getErrorMessages().length == 2).as("Correct errorMessages").isTrue();
assertThat("code1".equals(status.getErrorCodes()[0])).as("Correct errorCode").isTrue();
assertThat("code2".equals(status.getErrorCodes()[1])).as("Correct errorCode").isTrue();
assertThat("message1".equals(status.getErrorMessages()[0])).as("Correct errorMessage").isTrue();
assertThat("message2".equals(status.getErrorMessages()[1])).as("Correct errorMessage").isTrue();
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method nestedPathDoStartTagInternal.
@Test
void nestedPathDoStartTagInternal() throws JspException {
PageContext pc = createPageContext();
NestedPathTag tag = new NestedPathTag();
tag.setPath("foo");
tag.setPageContext(pc);
int returnValue = tag.doStartTag();
assertThat(returnValue).isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat(pc.getAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE)).isEqualTo("foo.");
}
Aggregations