@Override protected void assertValueAttribute(String output, String expectedValue) { if (this.getPasswordTag().isShowPassword()) { super.assertValueAttribute(output, expectedValue); } else { super.assertValueAttribute(output, ""); } }
@Test public void simpleBind() throws Exception { this.tag.setPath("name"); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", getType()); assertValueAttribute(output, "Rob"); }
@Test public void dynamicTypeAttribute() throws JspException { this.tag.setPath("myFloat"); this.tag.setDynamicAttribute(null, "type", "number"); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", "number"); assertValueAttribute(output, "12.34"); }
@Test public void simpleBindWithHtmlEscaping() throws Exception { final String NAME = "Rob \"I Love Mangos\" Harrop"; final String HTML_ESCAPED_NAME = "Rob "I Love Mangos" Harrop"; this.tag.setPath("name"); this.rob.setName(NAME); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", getType()); assertValueAttribute(output, HTML_ESCAPED_NAME); }
@Test public void complexBind() throws Exception { this.tag.setPath("spouse.name"); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "id", "spouse.name"); assertContainsAttribute(output, "name", "spouse.name"); assertContainsAttribute(output, "type", getType()); assertValueAttribute(output, "Sally"); }
/** * See SPR-3127 (http://opensource.atlassian.com/projects/spring/browse/SPR-3127) */ @Test public void readOnlyAttributeRenderingWhenReadonlyIsTrue() throws Exception { this.tag.setPath("name"); this.tag.setReadonly(true); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", getType()); assertContainsAttribute(output, "readonly", "readonly"); assertValueAttribute(output, "Rob"); }
@Test public void withCustomBinder() throws Exception { this.tag.setPath("myFloat"); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.rob, COMMAND_NAME); errors.getPropertyAccessor().registerCustomEditor(Float.class, new SimpleFloatEditor()); exposeBindingResult(errors); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", getType()); assertValueAttribute(output, "12.34f"); }
@Test public void withNestedBind() throws Exception { NestedPathTag nestedPathTag = new NestedPathTag(); nestedPathTag.setPath("spouse."); nestedPathTag.setPageContext(getPageContext()); nestedPathTag.doStartTag(); this.tag.setPath("name"); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", getType()); assertValueAttribute(output, "Sally"); }
@Test public void withErrors() throws Exception { this.tag.setPath("name"); this.tag.setCssClass("good"); this.tag.setCssErrorClass("bad"); BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.rob, COMMAND_NAME); errors.rejectValue("name", "some.code", "Default Message"); errors.rejectValue("name", "too.short", "Too Short"); exposeBindingResult(errors); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", getType()); assertValueAttribute(output, "Rob"); assertContainsAttribute(output, "class", "bad"); }
assertValueAttribute(output, "Rob"); assertContainsAttribute(output, "size", size); assertContainsAttribute(output, "class", cssClass);