use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class CheckboxTagTests method withMultiValueUnchecked.
@Test
public void withMultiValueUnchecked() throws Exception {
this.tag.setPath("stringArray");
this.tag.setValue("abc");
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 checkboxElement = (Element) document.getRootElement().elements().get(0);
assertEquals("input", checkboxElement.getName());
assertEquals("checkbox", checkboxElement.attribute("type").getValue());
assertEquals("stringArray", checkboxElement.attribute("name").getValue());
assertNull(checkboxElement.attribute("checked"));
assertEquals("abc", checkboxElement.attribute("value").getValue());
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class CheckboxTagTests method withMultiValueIntegerWithEditor.
@Test
public void withMultiValueIntegerWithEditor() throws Exception {
this.tag.setPath("someIntegerArray");
this.tag.setValue(" 1");
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
MyIntegerEditor editor = new MyIntegerEditor();
bindingResult.getPropertyEditorRegistry().registerCustomEditor(Integer.class, editor);
getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);
int result = this.tag.doStartTag();
assertEquals(Tag.SKIP_BODY, result);
assertEquals(1, editor.count);
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 checkboxElement = (Element) document.getRootElement().elements().get(0);
assertEquals("input", checkboxElement.getName());
assertEquals("checkbox", checkboxElement.attribute("type").getValue());
assertEquals("someIntegerArray", checkboxElement.attribute("name").getValue());
assertEquals("checked", checkboxElement.attribute("checked").getValue());
assertEquals(" 1", checkboxElement.attribute("value").getValue());
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class CheckboxTagTests method withMultiValueWithEditor.
@Test
public void withMultiValueWithEditor() throws Exception {
this.tag.setPath("stringArray");
this.tag.setValue(" foo");
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
MyStringTrimmerEditor editor = new MyStringTrimmerEditor();
bindingResult.getPropertyEditorRegistry().registerCustomEditor(String.class, editor);
getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);
int result = this.tag.doStartTag();
assertEquals(Tag.SKIP_BODY, result);
assertEquals(1, editor.count);
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 checkboxElement = (Element) document.getRootElement().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(" foo", checkboxElement.attribute("value").getValue());
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class CheckboxesTagTests method hiddenElementOmittedOnDisabled.
@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());
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class CheckboxesTagTests method withPetItemsMap.
@Test
public void withPetItemsMap() throws Exception {
this.tag.setPath("someSet");
Map m = new LinkedHashMap();
m.put(new ItemPet("PET1"), "PET1Label");
m.put(new ItemPet("PET2"), "PET2Label");
m.put(new ItemPet("PET3"), "PET3Label");
this.tag.setItems(m);
tag.setItemValue("name");
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 spanElement1 = (Element) document.getRootElement().elements().get(0);
Element checkboxElement1 = (Element) spanElement1.elements().get(0);
assertEquals("input", checkboxElement1.getName());
assertEquals("checkbox", checkboxElement1.attribute("type").getValue());
assertEquals("someSet", checkboxElement1.attribute("name").getValue());
assertEquals("checked", checkboxElement1.attribute("checked").getValue());
assertEquals("PET1", checkboxElement1.attribute("value").getValue());
assertEquals("PET1Label", spanElement1.getStringValue());
Element spanElement2 = (Element) document.getRootElement().elements().get(1);
Element checkboxElement2 = (Element) spanElement2.elements().get(0);
assertEquals("input", checkboxElement2.getName());
assertEquals("checkbox", checkboxElement2.attribute("type").getValue());
assertEquals("someSet", checkboxElement2.attribute("name").getValue());
assertEquals("checked", checkboxElement2.attribute("checked").getValue());
assertEquals("PET2", checkboxElement2.attribute("value").getValue());
assertEquals("PET2Label", spanElement2.getStringValue());
Element spanElement3 = (Element) document.getRootElement().elements().get(2);
Element checkboxElement3 = (Element) spanElement3.elements().get(0);
assertEquals("input", checkboxElement3.getName());
assertEquals("checkbox", checkboxElement3.attribute("type").getValue());
assertEquals("someSet", checkboxElement3.attribute("name").getValue());
assertNull("not checked", checkboxElement3.attribute("checked"));
assertEquals("PET3", checkboxElement3.attribute("value").getValue());
assertEquals("PET3Label", spanElement3.getStringValue());
}
Aggregations