use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class RadioButtonsTagTests method withMultiValueMap.
@Test
public void withMultiValueMap() throws Exception {
this.tag.setPath("stringArray");
Map m = new LinkedHashMap();
m.put("foo", "FOO");
m.put("bar", "BAR");
m.put("baz", "BAZ");
this.tag.setItems(m);
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
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 = document.getRootElement().elements().get(0);
Element radioButtonElement1 = spanElement1.elements().get(0);
assertThat(radioButtonElement1.getName()).isEqualTo("input");
assertThat(radioButtonElement1.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement1.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement1.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement1.attribute("value").getValue()).isEqualTo("foo");
assertThat(spanElement1.getStringValue()).isEqualTo("FOO");
Element spanElement2 = document.getRootElement().elements().get(1);
Element radioButtonElement2 = spanElement2.elements().get(0);
assertThat(radioButtonElement2.getName()).isEqualTo("input");
assertThat(radioButtonElement2.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement2.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement2.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement2.attribute("value").getValue()).isEqualTo("bar");
assertThat(spanElement2.getStringValue()).isEqualTo("BAR");
Element spanElement3 = document.getRootElement().elements().get(2);
Element radioButtonElement3 = spanElement3.elements().get(0);
assertThat(radioButtonElement3.getName()).isEqualTo("input");
assertThat(radioButtonElement3.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement3.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement3.attribute("checked")).as("not checked").isNull();
assertThat(radioButtonElement3.attribute("value").getValue()).isEqualTo("baz");
assertThat(spanElement3.getStringValue()).isEqualTo("BAZ");
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class RadioButtonsTagTests method withMultiValueWithEditor.
@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);
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();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
assertThat(editor.allProcessedValues.size()).isEqualTo(3);
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 = document.getRootElement().elements().get(0);
Element radioButtonElement1 = spanElement1.elements().get(0);
assertThat(radioButtonElement1.getName()).isEqualTo("input");
assertThat(radioButtonElement1.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement1.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement1.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement1.attribute("value").getValue()).isEqualTo(" foo");
Element spanElement2 = document.getRootElement().elements().get(1);
Element radioButtonElement2 = spanElement2.elements().get(0);
assertThat(radioButtonElement2.getName()).isEqualTo("input");
assertThat(radioButtonElement2.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement2.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement2.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement2.attribute("value").getValue()).isEqualTo(" bar");
Element spanElement3 = document.getRootElement().elements().get(2);
Element radioButtonElement3 = spanElement3.elements().get(0);
assertThat(radioButtonElement3.getName()).isEqualTo("input");
assertThat(radioButtonElement3.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement3.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement3.attribute("checked")).as("not checked").isNull();
assertThat(radioButtonElement3.attribute("value").getValue()).isEqualTo(" baz");
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class RadioButtonsTagTests 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();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
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();
assertThat(rootElement.elements().size()).as("Both tag and hidden element rendered incorrectly").isEqualTo(3);
Element spanElement = document.getRootElement().elements().get(0);
Element radioButtonElement = spanElement.elements().get(0);
assertThat(radioButtonElement.getName()).isEqualTo("input");
assertThat(radioButtonElement.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement.attribute("disabled").getValue()).isEqualTo("disabled");
assertThat(radioButtonElement.attribute("value").getValue()).isEqualTo("foo");
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class RadioButtonsTagTests method withMultiValueArray.
@Test
public void withMultiValueArray() throws Exception {
this.tag.setPath("stringArray");
this.tag.setItems(new Object[] { "foo", "bar", "baz" });
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
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 = document.getRootElement().elements().get(0);
Element radioButtonElement1 = spanElement1.elements().get(0);
assertThat(radioButtonElement1.getName()).isEqualTo("input");
assertThat(radioButtonElement1.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement1.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement1.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement1.attribute("value").getValue()).isEqualTo("foo");
assertThat(spanElement1.getStringValue()).isEqualTo("foo");
Element spanElement2 = document.getRootElement().elements().get(1);
Element radioButtonElement2 = spanElement2.elements().get(0);
assertThat(radioButtonElement2.getName()).isEqualTo("input");
assertThat(radioButtonElement2.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement2.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement2.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement2.attribute("value").getValue()).isEqualTo("bar");
assertThat(spanElement2.getStringValue()).isEqualTo("bar");
Element spanElement3 = document.getRootElement().elements().get(2);
Element radioButtonElement3 = spanElement3.elements().get(0);
assertThat(radioButtonElement3.getName()).isEqualTo("input");
assertThat(radioButtonElement3.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement3.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(radioButtonElement3.attribute("checked")).as("not checked").isNull();
assertThat(radioButtonElement3.attribute("value").getValue()).isEqualTo("baz");
assertThat(spanElement3.getStringValue()).isEqualTo("baz");
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class RadioButtonsTagTests method collectionOfPetsWithEditor.
@Test
public void collectionOfPetsWithEditor() throws Exception {
this.tag.setPath("pets");
List allPets = new ArrayList();
allPets.add(new ItemPet("Rudiger"));
allPets.add(new ItemPet("Spot"));
allPets.add(new ItemPet("Checkers"));
allPets.add(new ItemPet("Fluffy"));
allPets.add(new ItemPet("Mufty"));
this.tag.setItems(allPets);
this.tag.setItemLabel("label");
this.tag.setId("myId");
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
PropertyEditorSupport editor = new ItemPet.CustomEditor();
bindingResult.getPropertyEditorRegistry().registerCustomEditor(ItemPet.class, editor);
getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
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 = document.getRootElement().elements().get(0);
Element radioButtonElement1 = spanElement1.elements().get(0);
assertThat(radioButtonElement1.getName()).isEqualTo("input");
assertThat(radioButtonElement1.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement1.attribute("name").getValue()).isEqualTo("pets");
assertThat(radioButtonElement1.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement1.attribute("value").getValue()).isEqualTo("Rudiger");
assertThat(spanElement1.getStringValue()).isEqualTo("RUDIGER");
Element spanElement2 = document.getRootElement().elements().get(1);
Element radioButtonElement2 = spanElement2.elements().get(0);
assertThat(radioButtonElement2.getName()).isEqualTo("input");
assertThat(radioButtonElement2.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement2.attribute("name").getValue()).isEqualTo("pets");
assertThat(radioButtonElement2.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement2.attribute("value").getValue()).isEqualTo("Spot");
assertThat(spanElement2.getStringValue()).isEqualTo("SPOT");
Element spanElement3 = document.getRootElement().elements().get(2);
Element radioButtonElement3 = spanElement3.elements().get(0);
assertThat(radioButtonElement3.getName()).isEqualTo("input");
assertThat(radioButtonElement3.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement3.attribute("name").getValue()).isEqualTo("pets");
assertThat(radioButtonElement3.attribute("checked")).as("not checked").isNull();
assertThat(radioButtonElement3.attribute("value").getValue()).isEqualTo("Checkers");
assertThat(spanElement3.getStringValue()).isEqualTo("CHECKERS");
Element spanElement4 = document.getRootElement().elements().get(3);
Element radioButtonElement4 = spanElement4.elements().get(0);
assertThat(radioButtonElement4.getName()).isEqualTo("input");
assertThat(radioButtonElement4.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement4.attribute("name").getValue()).isEqualTo("pets");
assertThat(radioButtonElement4.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement4.attribute("value").getValue()).isEqualTo("Fluffy");
assertThat(spanElement4.getStringValue()).isEqualTo("FLUFFY");
Element spanElement5 = document.getRootElement().elements().get(4);
Element radioButtonElement5 = spanElement5.elements().get(0);
assertThat(radioButtonElement5.getName()).isEqualTo("input");
assertThat(radioButtonElement5.attribute("type").getValue()).isEqualTo("radio");
assertThat(radioButtonElement5.attribute("name").getValue()).isEqualTo("pets");
assertThat(radioButtonElement5.attribute("checked").getValue()).isEqualTo("checked");
assertThat(radioButtonElement5.attribute("value").getValue()).isEqualTo("Mufty");
assertThat(spanElement5.getStringValue()).isEqualTo("MUFTY");
}
Aggregations