Search in sources :

Example 26 with Component

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

the class AnyTest method render_with_id.

@Test
public void render_with_id() {
    ComponentResources resources = mockComponentResources();
    JavaScriptSupport support = mockJavaScriptSupport();
    MarkupWriter writer = new MarkupWriterImpl(new DefaultMarkupModel());
    resources.renderInformalParameters(writer);
    String clientId = "bar";
    String uniqueId = "bar_0";
    expect(support.allocateClientId(clientId)).andReturn(uniqueId);
    replay();
    Any component = new Any();
    component.inject(support, resources, "div", clientId);
    component.beginRender(writer);
    writer.write("content");
    component.afterRender(writer);
    assertEquals(writer.toString(), "<div>content</div>");
    assertEquals(component.getClientId(), uniqueId);
    assertEquals(writer.toString(), "<div id=\"bar_0\">content</div>");
    assertEquals(component.getClientId(), uniqueId);
    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)

Example 27 with Component

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

the class AnyTest method attempt_to_get_client_id_before_render.

@Test
public void attempt_to_get_client_id_before_render() {
    ComponentResources resources = mockComponentResources();
    JavaScriptSupport support = mockJavaScriptSupport();
    train_getCompleteId(resources, "Foo/bar.baz");
    replay();
    Any component = new Any();
    component.inject(support, resources, "div", null);
    try {
        component.getClientId();
        unreachable();
    } catch (IllegalStateException ex) {
        assertEquals(ex.getMessage(), "Unable to provide client id for component Foo/bar.baz as it has not yet rendered.");
    }
    verify();
}
Also used : JavaScriptSupport(org.apache.tapestry5.services.javascript.JavaScriptSupport) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 28 with Component

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

the class BeanEditorTest method refresh_bean_validation_context.

@Test
public void refresh_bean_validation_context() {
    ComponentResources resources = mockComponentResources();
    BeanModelSource source = mockBeanModelSource();
    BeanModel model = mockBeanModel();
    Environment env = mockEnvironment();
    RegistrationData data = new RegistrationData();
    Messages messages = mockMessages();
    PropertyOverrides overrides = mockPropertyOverrides();
    BeanValidationContext beanValidationContext = newMock(BeanValidationContext.class);
    train_getBoundType(resources, "object", RegistrationData.class);
    train_createEditModel(source, RegistrationData.class, messages, model);
    train_getOverrideMessages(overrides, messages);
    expect(model.newInstance()).andReturn(data);
    expect(env.push(eq(BeanValidationContext.class), isA(BeanValidationContext.class))).andReturn(beanValidationContext);
    expect(model.getBeanType()).andReturn(RegistrationData.class);
    BeanEditContext ctxt = new BeanEditContext() {

        public Class<?> getBeanClass() {
            return RegistrationData.class;
        }

        public <T extends Annotation> T getAnnotation(Class<T> type) {
            return null;
        }
    };
    expect(env.push(eq(BeanEditContext.class), contextEq())).andReturn(ctxt);
    replay();
    BeanEditor component = new BeanEditor();
    component.inject(resources, overrides, source, env);
    component.doPrepare();
    verify();
}
Also used : RegistrationData(org.apache.tapestry5.integration.app1.data.RegistrationData) BeanModelSource(org.apache.tapestry5.beanmodel.services.BeanModelSource) Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) BeanValidationContext(org.apache.tapestry5.internal.BeanValidationContext) Environment(org.apache.tapestry5.services.Environment) PropertyOverrides(org.apache.tapestry5.PropertyOverrides) Annotation(java.lang.annotation.Annotation) ComponentResources(org.apache.tapestry5.ComponentResources) BeanEditContext(org.apache.tapestry5.services.BeanEditContext) Test(org.testng.annotations.Test)

Example 29 with Component

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

the class RenderableProvider method setup.

@SetupRender
void setup() {
    Renderable r = new Renderable() {

        public void render(MarkupWriter writer) {
            writer.element("strong");
            writer.write("A message provided by the RenderableProvider component.");
            writer.end();
        }
    };
    environment.push(Renderable.class, r);
}
Also used : Renderable(org.apache.tapestry5.Renderable) MarkupWriter(org.apache.tapestry5.MarkupWriter) SetupRender(org.apache.tapestry5.annotations.SetupRender)

Example 30 with Component

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

the class ResponseRendererImplTest method content_type_from_component.

@Test
public void content_type_from_component() {
    RequestPageCache cache = mockRequestPageCache();
    PageContentTypeAnalyzer analyzer = mockPageContentTypeAnalyzer();
    Component component = mockComponent();
    String pageName = "foo/bar";
    Page page = mockPage();
    ContentType contentType = new ContentType("zig/zag");
    ComponentResources resources = mockComponentResources();
    train_getComponentResources(component, resources);
    train_getPageName(resources, pageName);
    train_get(cache, pageName, page);
    train_findContentType(analyzer, page, contentType);
    replay();
    ResponseRenderer renderer = new ResponseRendererImpl(cache, analyzer, null);
    assertSame(renderer.findContentType(component), contentType);
    verify();
}
Also used : ContentType(org.apache.tapestry5.http.ContentType) ResponseRenderer(org.apache.tapestry5.services.ResponseRenderer) Page(org.apache.tapestry5.internal.structure.Page) Component(org.apache.tapestry5.runtime.Component) 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