Search in sources :

Example 6 with XMLMarkupModel

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();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) OptionModelImpl(org.apache.tapestry5.internal.OptionModelImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Example 7 with XMLMarkupModel

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>");
}
Also used : MarkupWriterListener(org.apache.tapestry5.MarkupWriterListener) Element(org.apache.tapestry5.dom.Element) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 8 with XMLMarkupModel

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");
}
Also used : XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 9 with XMLMarkupModel

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.");
    }
}
Also used : XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 10 with XMLMarkupModel

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/>");
}
Also used : XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) 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