use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.
the class SelectTest method disabled_option.
@Test
public void disabled_option() throws Exception {
ValidationTracker tracker = mockValidationTracker();
// Extra cast needed for Sun compiler, not Eclipse compiler.
List<OptionModel> options = Arrays.asList((OptionModel) new OptionModelImpl("Fred", "fred") {
@Override
public boolean isDisabled() {
return true;
}
@Override
public Map<String, String> getAttributes() {
return Collections.singletonMap("class", "pixie");
}
});
Select select = new Select();
train_getInput(tracker, select, null);
replay();
select.setModel(new SelectModelImpl(null, options));
select.setValueEncoder(new StringValueEncoder());
select.setValue("barney");
select.setValidationTracker(tracker);
MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
writer.element("select");
select.options(writer);
writer.end();
assertEquals(writer.toString(), read("disabled_option.txt"));
verify();
}
use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.
the class MarkupWriterImplTest method listeners.
@Test
public void listeners() {
MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
MarkupWriterListener l = new MarkupWriterListener() {
public void elementDidStart(Element element) {
element.text("[Start: " + element.getName() + "]");
}
public void elementDidEnd(Element element) {
element.text("[End: " + element.getName() + "]");
}
};
w.element("root");
w.element("no-listener");
w.write("before listener");
w.addListener(l);
w.element("listener");
w.write("before n-w-l");
w.element("nested-with-listener");
w.write("n-w-l text");
w.end();
w.write("after n-w-l");
w.end();
w.removeListener(l);
w.write("after listener");
w.end();
w.end();
// Because we are invoking Element.text(), the text added by the listener is appended to the body of the
// element,
// which is correct but may not be what you'd expect.
assertEquals(w.toString(), "<?xml version=\"1.0\"?>\n" + "<root><no-listener>before listener<listener>[Start: listener]before n-w-l<nested-with-listener>[Start: nested-with-listener]n-w-l text[End: nested-with-listener]</nested-with-listener>after n-w-l[End: listener]</listener>after listener</no-listener></root>");
}
use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.
the class MarkupWriterImplTest method document_without_root_element.
/**
* TAP5-1145
*/
@Test
public void document_without_root_element() {
MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
w.write("preamble text");
assertEquals(w.getDocument().toString(), "<?xml version=\"1.0\"?>\n" + "preamble text");
}
use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.
the class MarkupWriterImplTest method single_root_element_only.
/**
* TAP5-349
*/
@Test
public void single_root_element_only() {
MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
w.element("root1");
w.end();
try {
w.element("root2");
unreachable();
} catch (RuntimeException ex) {
assertEquals(ex.getMessage(), "A document must have exactly one root element. Element <root1> is already the root element.");
}
}
use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.
the class MarkupWriterImplTest method write_whitespace_after_end_of_root_element_is_retained_in_preamble.
@Test
public void write_whitespace_after_end_of_root_element_is_retained_in_preamble() {
MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
w.element("root");
w.end();
w.write(" ");
assertEquals(w.toString(), "<?xml version=\"1.0\"?>\n <root/>");
}
Aggregations