@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"); }
@Override protected void onSetUp() { this.tag = createTag(getWriter()); this.tag.setParent(getFormTag()); this.tag.setPageContext(getPageContext()); }
@Test public void disabledFalse() throws Exception { this.tag.setPath("name"); this.tag.setDisabled(false); this.tag.doStartTag(); String output = getOutput(); assertAttributeNotPresent(output, "disabled"); }
@Test public void simpleBindTagWithinForm() throws Exception { BindTag bindTag = new BindTag(); bindTag.setPath("name"); bindTag.setPageContext(getPageContext()); bindTag.doStartTag(); BindStatus bindStatus = (BindStatus) getPageContext().findAttribute(BindTag.STATUS_VARIABLE_NAME); assertEquals("Rob", bindStatus.getValue()); }
protected void assertValueAttribute(String output, String expectedValue) { assertContainsAttribute(output, "value", expectedValue); }
@Override protected void assertValueAttribute(String output, String expectedValue) { if (this.getPasswordTag().isShowPassword()) { super.assertValueAttribute(output, expectedValue); } else { super.assertValueAttribute(output, ""); } }
@Test public void withNestedBindTagWithinForm() throws Exception { NestedPathTag nestedPathTag = new NestedPathTag(); nestedPathTag.setPath("spouse."); nestedPathTag.setPageContext(getPageContext()); nestedPathTag.doStartTag(); BindTag bindTag = new BindTag(); bindTag.setPath("name"); bindTag.setPageContext(getPageContext()); bindTag.doStartTag(); BindStatus bindStatus = (BindStatus) getPageContext().findAttribute(BindTag.STATUS_VARIABLE_NAME); assertEquals("Sally", bindStatus.getValue()); }
@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"); }
/** * 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 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 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 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"); }
String output = getOutput(); assertTagOpened(output); assertTagClosed(output); assertContainsAttribute(output, "type", getType()); assertContainsAttribute(output, "id", id); assertValueAttribute(output, "Rob"); assertContainsAttribute(output, "size", size); assertContainsAttribute(output, "class", cssClass); assertContainsAttribute(output, "style", cssStyle); assertContainsAttribute(output, "title", title); assertContainsAttribute(output, "lang", lang); assertContainsAttribute(output, "dir", dir); assertContainsAttribute(output, "tabindex", tabindex); assertContainsAttribute(output, "disabled", "disabled"); assertContainsAttribute(output, "onclick", onclick); assertContainsAttribute(output, "ondblclick", ondblclick); assertContainsAttribute(output, "onkeydown", onkeydown); assertContainsAttribute(output, "onkeypress", onkeypress); assertContainsAttribute(output, "onkeyup", onkeyup); assertContainsAttribute(output, "onmousedown", onmousedown); assertContainsAttribute(output, "onmousemove", onmousemove); assertContainsAttribute(output, "onmouseout", onmouseout); assertContainsAttribute(output, "onmouseover", onmouseover); assertContainsAttribute(output, "onmouseup", onmouseup); assertContainsAttribute(output, "onfocus", onfocus); assertContainsAttribute(output, "onblur", onblur); assertContainsAttribute(output, "onchange", onchange);