BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.name");
tag.setHtmlEscape("true");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertTrue("Has status variable", status != null);
assertTrue("Correct expression", "name".equals(status.getExpression()));
assertTrue("Correct value", "name1".equals(status.getValue()));
assertTrue("Correct displayValue", "name1".equals(status.getDisplayValue()));
assertTrue("Correct isError", status.isError());
assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
assertTrue("Correct errorCode", "code1".equals(status.getErrorCode()));
assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
assertTrue("Correct errorMessage", "message & 1".equals(status.getErrorMessage()));
assertTrue("Correct errorMessage", "message & 1".equals(status.getErrorMessages()[0]));
assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
assertTrue("Correct errorMessagesAsString",
"message & 1 - message2".equals(status.getErrorMessagesAsString(" - ")));
tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.age");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertTrue("Has status variable", status != null);
assertTrue("Correct expression", "age".equals(status.getExpression()));
assertTrue("Correct value", new Integer(0).equals(status.getValue()));
assertTrue("Correct displayValue", "0".equals(status.getDisplayValue()));
assertTrue("Correct isError", status.isError());
assertTrue("Correct errorCodes", status.getErrorCodes().length == 1);
assertTrue("Correct errorMessages", status.getErrorMessages().length == 1);
assertTrue("Correct errorCode", "code2".equals(status.getErrorCode()));
assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessage()));
assertTrue("Correct errorMessagesAsString", "message2".equals(status.getErrorMessagesAsString(" - ")));
tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.*");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertTrue("Has status variable", status != null);
assertTrue("Correct expression", "*".equals(status.getExpression()));
assertTrue("Correct value", status.getValue() == null);
assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
assertTrue("Correct isError", status.isError());
assertTrue("Correct errorCodes", status.getErrorCodes().length == 3);
assertTrue("Correct errorMessages", status.getErrorMessages().length == 3);
assertTrue("Correct errorCode", "code1".equals(status.getErrorCode()));
assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[2]));
assertTrue("Correct errorMessage", "message & 1".equals(status.getErrorMessage()));
assertTrue("Correct errorMessage", "message & 1".equals(status.getErrorMessages()[0]));
assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[2]));
}