Search in sources :

Example 11 with XMLMarkupModel

use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.

the class MarkupWriterImplTest method write_whitespace_before_start_of_root_element_is_retained.

@Test
public void write_whitespace_before_start_of_root_element_is_retained() {
    MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
    w.write("  ");
    w.element("root");
    w.end();
    assertEquals(w.toString(), "<?xml version=\"1.0\"?>\n" + "  <root/>");
}
Also used : XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 12 with XMLMarkupModel

use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.

the class MarkupWriterImplTest method namespaced_elements_and_attributes.

@Test
public void namespaced_elements_and_attributes() {
    MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
    Element root = w.elementNS("fredns", "root");
    assertSame(root.defineNamespace("fredns", "fred"), root);
    root.defineNamespace("barneyns", "barney");
    assertSame(w.attributeNS("fredns", "foo", "bar"), root);
    Element child = w.elementNS("barneyns", "child");
    assertSame(child.getContainer(), root);
    // child
    w.end();
    // root
    w.end();
    assertEquals(w.toString(), "<?xml version=\"1.0\"?>\n<fred:root fred:foo=\"bar\" xmlns:barney=\"barneyns\" xmlns:fred=\"fredns\"><barney:child/></fred:root>");
}
Also used : Element(org.apache.tapestry5.dom.Element) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 13 with XMLMarkupModel

use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.

the class MarkupWriterImplTest method preamble_content.

@Test
public void preamble_content() throws Exception {
    MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
    w.comment(" preamble start ");
    w.write("preamble text");
    w.cdata("CDATA content");
    w.writeRaw("&nbsp;");
    w.element("root");
    w.end();
    // You really shouldn't have any text after the close tag of the document, so it
    // gets moved to the top, to the "preamble", before the first element.
    w.comment(" content after root element in preamble ");
    assertEquals(w.getDocument().toString(), readFile("preamble_content.txt"));
}
Also used : XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 14 with XMLMarkupModel

use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.

the class MarkupWriterImplTest method cdata_content.

@Test
public void cdata_content() {
    MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
    w.element("root");
    w.write("Normal Text ");
    w.cdata("< & >");
    w.write("More Normal Text");
    assertEquals(w.toString(), "<?xml version=\"1.0\"?>\n<root>Normal Text <![CDATA[< & >]]>More Normal Text</root>");
}
Also used : XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 15 with XMLMarkupModel

use of org.apache.tapestry5.dom.XMLMarkupModel in project tapestry-5 by apache.

the class SelectTest method current_selection_from_validation_tracker.

@Test
public void current_selection_from_validation_tracker() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    List<OptionModel> options = TapestryInternalUtils.toOptionModels("fred=Fred Flintstone,barney=Barney Rubble");
    Select select = new Select();
    train_getInput(tracker, select, "fred");
    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();
    // fred will be selected, not barney, because the validation tracker
    // takes precendence.
    assertEquals(writer.toString(), read("current_selection_from_validation_tracker.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)19 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)18 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)11 MarkupWriter (org.apache.tapestry5.MarkupWriter)10 SelectModelImpl (org.apache.tapestry5.internal.SelectModelImpl)9 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)9 OptionGroupModelImpl (org.apache.tapestry5.internal.OptionGroupModelImpl)3 Element (org.apache.tapestry5.dom.Element)2 OptionModelImpl (org.apache.tapestry5.internal.OptionModelImpl)2 MarkupWriterListener (org.apache.tapestry5.MarkupWriterListener)1