Search in sources :

Example 16 with XMLMarkupModel

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

the class SelectTest method option_groups_precede_ungroup_options.

@Test
public void option_groups_precede_ungroup_options() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils.toOptionModels("Fred,Barney"));
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(Collections.singletonList(husbands), TapestryInternalUtils.toOptionModels("Wilma,Betty")));
    select.setValueEncoder(new StringValueEncoder());
    select.setValue("Fred");
    select.setValidationTracker(tracker);
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    writer.element("select");
    select.options(writer);
    writer.end();
    assertEquals(writer.toString(), read("option_groups_precede_ungroup_options.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) OptionGroupModelImpl(org.apache.tapestry5.internal.OptionGroupModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Example 17 with XMLMarkupModel

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

the class SelectTest method option_group_attributes.

@Test
public void option_group_attributes() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    Map<String, String> attributes = Collections.singletonMap("class", "pixie");
    OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils.toOptionModels("Fred,Barney"), attributes);
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(Collections.singletonList(husbands), null));
    select.setValueEncoder(new StringValueEncoder());
    select.setValue("Fred");
    select.setValidationTracker(tracker);
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    writer.element("select");
    select.options(writer);
    writer.end();
    assertEquals(writer.toString(), read("option_group_attributes.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) OptionGroupModelImpl(org.apache.tapestry5.internal.OptionGroupModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Example 18 with XMLMarkupModel

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

the class TextOutputTest method normal_output.

@Test
public void normal_output() {
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    TextOutput component = new TextOutput();
    component.injectValue("Fred\nBarney\rWilma\r\nBetty\nBam-Bam\n");
    writer.element("div");
    component.beginRender(writer);
    writer.end();
    assertEquals(writer.toString(), "<?xml version=\"1.0\"?>\n" + "<div><p>Fred</p><p>Barney</p><p>Wilma</p><p>Betty</p><p>Bam-Bam</p></div>");
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 19 with XMLMarkupModel

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

the class DOMTest method remove_while_rendering.

@Test
public void remove_while_rendering() {
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    writer.element("ul");
    for (int i = 0; i < 4; i++) {
        Element e = writer.element("li");
        if (i != 2) {
            writer.write(String.valueOf(i));
        }
        writer.end();
        if (e.getChildren().isEmpty()) {
            e.remove();
        }
    }
    writer.end();
    assertEquals(writer.toString(), "<?xml version=\"1.0\"?>\n" + "<ul><li>0</li><li>1</li><li>3</li></ul>");
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) MarkupWriter(org.apache.tapestry5.MarkupWriter) 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