@Test public void simpleRender() throws Exception { this.tag.setPath("name"); int startResult = this.tag.doStartTag(); int endResult = this.tag.doEndTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, startResult); assertEquals(Tag.EVAL_PAGE, endResult); String output = getOutput(); // we are using a nested path (see extendPageContext(..)), so... assertContainsAttribute(output, "for", "spouse.name"); // name attribute is not supported by <label/> assertAttributeNotPresent(output, "name"); // id attribute is supported, but we don't want it assertAttributeNotPresent(output, "id"); assertTrue(output.startsWith("<label ")); assertTrue(output.endsWith("</label>")); }
@Test public void simpleRenderWithMapElement() throws Exception { this.tag.setPath("someMap[1]"); int startResult = this.tag.doStartTag(); int endResult = this.tag.doEndTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, startResult); assertEquals(Tag.EVAL_PAGE, endResult); String output = getOutput(); // we are using a nested path (see extendPageContext(..)), so... assertContainsAttribute(output, "for", "spouse.someMap1"); // name attribute is not supported by <label/> assertAttributeNotPresent(output, "name"); // id attribute is supported, but we don't want it assertAttributeNotPresent(output, "id"); assertTrue(output.startsWith("<label ")); assertTrue(output.endsWith("</label>")); }
@Test public void overrideFor() throws Exception { this.tag.setPath("name"); this.tag.setFor("myElement"); int startResult = this.tag.doStartTag(); int endResult = this.tag.doEndTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, startResult); assertEquals(Tag.EVAL_PAGE, endResult); String output = getOutput(); assertContainsAttribute(output, "for", "myElement"); // name attribute is not supported by <label/> assertAttributeNotPresent(output, "name"); // id attribute is supported, but we don't want it assertAttributeNotPresent(output, "id"); assertTrue(output.startsWith("<label ")); assertTrue(output.endsWith("</label>")); }
@Test public void simpleRenderWithDynamicAttributes() throws Exception { String dynamicAttribute1 = "attr1"; String dynamicAttribute2 = "attr2"; this.tag.setPath("name"); this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1); this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2); int startResult = this.tag.doStartTag(); int endResult = this.tag.doEndTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, startResult); assertEquals(Tag.EVAL_PAGE, endResult); String output = getOutput(); // we are using a nested path (see extendPageContext(..)), so... assertContainsAttribute(output, "for", "spouse.name"); assertContainsAttribute(output, dynamicAttribute1, dynamicAttribute1); assertContainsAttribute(output, dynamicAttribute2, dynamicAttribute2); // name attribute is not supported by <label/> assertAttributeNotPresent(output, "name"); // id attribute is supported, but we don't want it assertAttributeNotPresent(output, "id"); assertTrue(output.startsWith("<label ")); assertTrue(output.endsWith("</label>")); }