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();
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 checkboxElement = spanElement.elements().get(0);
assertThat(checkboxElement.getName()).isEqualTo("input");
assertThat(checkboxElement.attribute("type").getValue()).isEqualTo("checkbox");
assertThat(checkboxElement.attribute("name").getValue()).isEqualTo("stringArray");
assertThat(checkboxElement.attribute("checked").getValue()).isEqualTo("checked");
assertThat(checkboxElement.attribute("disabled").getValue()).isEqualTo("disabled");
assertThat(checkboxElement.attribute("value").getValue()).isEqualTo("foo");
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class OptionsTagTests method withoutItems.
@Test
void withoutItems() throws Exception {
this.tag.setItemValue("isoCode");
this.tag.setItemLabel("name");
this.selectTag.setPath("testBean");
this.selectTag.doStartTag();
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
this.tag.doEndTag();
this.selectTag.doEndTag();
String output = getOutput();
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(output));
Element rootElement = document.getRootElement();
List children = rootElement.elements();
assertThat(children.size()).as("Incorrect number of children").isEqualTo(0);
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class OptionsTagTests method withoutItemsEnumParent.
@Test
void withoutItemsEnumParent() throws Exception {
BeanWithEnum testBean = new BeanWithEnum();
testBean.setTestEnum(TestEnum.VALUE_2);
getPageContext().getRequest().setAttribute("testBean", testBean);
this.selectTag.setPath("testBean.testEnum");
this.selectTag.doStartTag();
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(BodyTag.SKIP_BODY);
result = this.tag.doEndTag();
assertThat(result).isEqualTo(Tag.EVAL_PAGE);
this.selectTag.doEndTag();
String output = getWriter().toString();
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(output));
Element rootElement = document.getRootElement();
assertThat(rootElement.elements().size()).isEqualTo(2);
Node value1 = rootElement.selectSingleNode("option[@value = 'VALUE_1']");
Node value2 = rootElement.selectSingleNode("option[@value = 'VALUE_2']");
assertThat(value1.getText()).isEqualTo("TestEnum: VALUE_1");
assertThat(value2.getText()).isEqualTo("TestEnum: VALUE_2");
assertThat(rootElement.selectSingleNode("option[@selected]")).isEqualTo(value2);
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class OptionsTagTests method withCollectionAndCustomEditor.
@Test
void withCollectionAndCustomEditor() throws Exception {
PropertyEditor propertyEditor = new SimpleFloatEditor();
TestBean target = new TestBean();
target.setMyFloat(Float.valueOf("12.34"));
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor);
exposeBindingResult(errors);
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.myFloat", false));
List<Float> floats = new ArrayList<>();
floats.add(Float.valueOf("12.30"));
floats.add(Float.valueOf("12.31"));
floats.add(Float.valueOf("12.32"));
floats.add(Float.valueOf("12.33"));
floats.add(Float.valueOf("12.34"));
floats.add(Float.valueOf("12.35"));
this.tag.setItems(floats);
int result = this.tag.doStartTag();
assertThat(result).isEqualTo(Tag.SKIP_BODY);
String output = getOutput();
output = "<doc>" + output + "</doc>";
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(output));
Element rootElement = document.getRootElement();
List children = rootElement.elements();
assertThat(children.size()).as("Incorrect number of children").isEqualTo(6);
Element element = (Element) rootElement.selectSingleNode("option[text() = '12.34f']");
assertThat(element).as("Option node should not be null").isNotNull();
assertThat(element.attribute("selected").getValue()).as("12.34 node not selected").isEqualTo("selected");
assertThat(element.attribute("id")).as("No id rendered").isNull();
element = (Element) rootElement.selectSingleNode("option[text() = '12.35f']");
assertThat(element).as("Option node should not be null").isNotNull();
assertThat(element.attribute("selected")).as("12.35 node incorrectly selected").isNull();
assertThat(element.attribute("id")).as("No id rendered").isNull();
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class RadioButtonTagTests method collectionOfPetsNotSelected.
@Test
void collectionOfPetsNotSelected() throws Exception {
this.tag.setPath("pets");
this.tag.setValue(new Pet("Santa's Little Helper"));
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 checkboxElement = document.getRootElement().elements().get(0);
assertThat(checkboxElement.getName()).isEqualTo("input");
assertThat(checkboxElement.attribute("type").getValue()).isEqualTo("radio");
assertThat(checkboxElement.attribute("name").getValue()).isEqualTo("pets");
assertThat(checkboxElement.attribute("value").getValue()).isEqualTo("Santa's Little Helper");
assertThat(checkboxElement.attribute("checked")).isNull();
}
Aggregations