@Test public void spanElementCustomizable() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); this.tag.setElement("element"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element spanElement = (Element) document.getRootElement().elements().get(0); assertEquals("element", spanElement.getName()); }
@Test public void withNullValue() throws Exception { try { this.tag.setPath("name"); this.tag.doStartTag(); fail("Should not be able to render with a null value when binding to a non-boolean."); } catch (IllegalArgumentException ex) { // success } }
@Test public void hiddenElementOmittedOnDisabled() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); this.tag.setDisabled(true); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals("Both tag and hidden element rendered incorrectly", 3, rootElement.elements().size()); Element spanElement = (Element) document.getRootElement().elements().get(0); Element checkboxElement = (Element) spanElement.elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("stringArray", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals("disabled", checkboxElement.attribute("disabled").getValue()); assertEquals("foo", checkboxElement.attribute("value").getValue()); }
@Test public void withMultiValueMap() throws Exception { this.tag.setPath("stringArray"); Map m = new LinkedHashMap(); m.put("foo", "FOO");
@Test public void withMultiValueArrayWithDelimiter() throws Exception { this.tag.setDelimiter("<br/>"); this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); int result = this.tag.doStartTag();
String delimiter = " | "; this.tag.setDelimiter(delimiter); this.tag.setPath("stringArray"); Map m = new LinkedHashMap(); m.put("foo", "FOO");
@Test public void withPetItemsMap() throws Exception { this.tag.setPath("someSet"); Map m = new LinkedHashMap(); m.put(new ItemPet("PET1"), "PET1Label");
@Test public void withMultiValueWithReverseEditor() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"FOO", "BAR", "BAZ"}); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
@Test public void withMultiValueArray() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); int result = this.tag.doStartTag();
@Test public void withMultiValueWithEditor() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {" foo", " bar", " baz"}); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
@Test public void withMultiValueWithFormatter() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {" foo", " bar", " baz"}); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
this.tag.setPath("someSet"); List allPets = new ArrayList(); allPets.add(new ItemPet("PET1"));
@Test public void collectionOfPets() throws Exception { this.tag.setPath("pets"); List allPets = new ArrayList(); allPets.add(new ItemPet("Rudiger"));
@Test public void collectionOfPetsWithEditor() throws Exception { this.tag.setPath("pets"); List allPets = new ArrayList(); allPets.add(new ItemPet("Rudiger"));
String dynamicAttribute2 = "attr2"; this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);