Search in sources :

Example 21 with Component

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

the class OutputTest method output_with_element_and_informals.

@Test
public void output_with_element_and_informals() {
    String elementName = "span";
    MarkupWriter writer = createMarkupWriter();
    ComponentResources resources = mockComponentResources();
    train_renderInformalParameters(resources, writer, "foo", "bar");
    replay();
    Output component = new Output();
    component.setup(value, format, true, elementName, resources);
    assertFalse(component.beginRender(writer));
    verify();
    assertEquals(writer.toString(), "<span foo=\"bar\">22.70</span>");
}
Also used : MarkupWriter(org.apache.tapestry5.MarkupWriter) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 22 with Component

use of org.apache.tapestry5.annotations.Component 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 23 with Component

use of org.apache.tapestry5.annotations.Component 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 24 with Component

use of org.apache.tapestry5.annotations.Component 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 25 with Component

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

the class AnyTest method render_simple.

@Test
public void render_simple() {
    ComponentResources resources = mockComponentResources();
    JavaScriptSupport support = mockJavaScriptSupport();
    MarkupWriter writer = new MarkupWriterImpl(new DefaultMarkupModel());
    resources.renderInformalParameters(writer);
    replay();
    Any component = new Any();
    component.inject(support, resources, "span", "foo");
    component.beginRender(writer);
    writer.write("content");
    component.afterRender(writer);
    assertEquals(writer.toString(), "<span>content</span>");
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) JavaScriptSupport(org.apache.tapestry5.services.javascript.JavaScriptSupport) DefaultMarkupModel(org.apache.tapestry5.dom.DefaultMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)68 Component (org.apache.tapestry5.runtime.Component)43 ComponentResources (org.apache.tapestry5.ComponentResources)41 MarkupWriter (org.apache.tapestry5.MarkupWriter)18 ComponentModel (org.apache.tapestry5.model.ComponentModel)18 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)17 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)16 Binding (org.apache.tapestry5.Binding)14 Location (org.apache.tapestry5.commons.Location)14 Instantiator (org.apache.tapestry5.internal.services.Instantiator)12 Page (org.apache.tapestry5.internal.structure.Page)12 Messages (org.apache.tapestry5.commons.Messages)8 Resource (org.apache.tapestry5.commons.Resource)8 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)7 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)7 BindingFactory (org.apache.tapestry5.services.BindingFactory)7 Logger (org.slf4j.Logger)7 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)6 BindingSource (org.apache.tapestry5.services.BindingSource)6 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)5