Search in sources :

Example 11 with MarkupWriter

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

the class OutputTest method simple_output_with_filter_disabled.

@Test
public void simple_output_with_filter_disabled() {
    MarkupWriter writer = createMarkupWriter();
    ComponentResources resources = mockComponentResources();
    replay();
    Output component = new Output();
    component.setup(value, filterFormat, false, null, resources);
    writer.element("root");
    assertFalse(component.beginRender(writer));
    writer.end();
    verify();
    // It's not valid XML output, but that's why it's called programmer error :-)
    assertEquals(writer.toString(), "<root><22.70></root>");
}
Also used : MarkupWriter(org.apache.tapestry5.MarkupWriter) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 12 with MarkupWriter

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

the class OutputTest method simple_output_with_filter.

@Test
public void simple_output_with_filter() {
    MarkupWriter writer = createMarkupWriter();
    ComponentResources resources = mockComponentResources();
    replay();
    Output component = new Output();
    component.setup(value, filterFormat, true, null, resources);
    writer.element("root");
    assertFalse(component.beginRender(writer));
    writer.end();
    verify();
    assertEquals(writer.toString(), "<root>&lt;22.70&gt;</root>");
}
Also used : MarkupWriter(org.apache.tapestry5.MarkupWriter) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 13 with MarkupWriter

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

the class OutputTest method null_format_is_a_noop.

@Test
public void null_format_is_a_noop() {
    String elementName = "span";
    MarkupWriter writer = createMarkupWriter();
    ComponentResources resources = mockComponentResources();
    Format format = new Format() {

        private static final long serialVersionUID = -4360045992642727894L;

        @Override
        public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
            return toAppendTo;
        }

        @Override
        public Object parseObject(String source, ParsePosition pos) {
            return null;
        }
    };
    replay();
    Output component = new Output();
    component.setup(value, format, true, elementName, resources);
    writer.element("root");
    assertFalse(component.beginRender(writer));
    writer.end();
    verify();
    assertEquals(writer.toString(), "<root></root>");
}
Also used : Format(java.text.Format) DecimalFormat(java.text.DecimalFormat) FieldPosition(java.text.FieldPosition) MarkupWriter(org.apache.tapestry5.MarkupWriter) ComponentResources(org.apache.tapestry5.ComponentResources) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 14 with MarkupWriter

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

the class SelectTest method option_groups.

@Test
public void option_groups() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils.toOptionModels("Fred,Barney"));
    OptionGroupModel wives = new OptionGroupModelImpl("Wives", true, TapestryInternalUtils.toOptionModels("Wilma,Betty"));
    List<OptionGroupModel> groupModels = CollectionFactory.newList(husbands, wives);
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(groupModels, 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_groups.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 15 with MarkupWriter

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

the class SelectTest method just_options.

@Test
public void just_options() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    List<OptionModel> options = TapestryInternalUtils.toOptionModels("fred=Fred Flintstone,barney=Barney Rubble");
    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("just_options.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

MarkupWriter (org.apache.tapestry5.MarkupWriter)72 Test (org.testng.annotations.Test)69 Element (org.apache.tapestry5.dom.Element)21 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)19 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)16 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)14 RenderQueue (org.apache.tapestry5.runtime.RenderQueue)14 ComponentResources (org.apache.tapestry5.ComponentResources)13 Link (org.apache.tapestry5.http.Link)11 SelectModelImpl (org.apache.tapestry5.internal.SelectModelImpl)9 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)9 FormSupport (org.apache.tapestry5.services.FormSupport)9 JSONObject (org.apache.tapestry5.json.JSONObject)7 PartialMarkupRenderer (org.apache.tapestry5.services.PartialMarkupRenderer)6 PartialMarkupRendererFilter (org.apache.tapestry5.services.PartialMarkupRendererFilter)6 Map (java.util.Map)5 FieldTranslator (org.apache.tapestry5.FieldTranslator)5 Translator (org.apache.tapestry5.Translator)5 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)5 Messages (org.apache.tapestry5.commons.Messages)5