Search in sources :

Example 26 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class LinkSourceImpl method createPageRenderLink.

public Link createPageRenderLink(String pageName, boolean override, Object... pageActivationContext) {
    // Resolve the page name to its canonical format (the best version for URLs). This also
    // validates
    // the page name.
    String canonical = resolver.canonicalizePageName(pageName);
    Object[] context = (override || pageActivationContext.length != 0) ? pageActivationContext : contextCollector.collectPageActivationContext(canonical);
    boolean loopback = canonical.equals(requestGlobals.getActivePageName()) && pageCache.get(pageName).hasResetListeners();
    PageRenderRequestParameters parameters = new PageRenderRequestParameters(canonical, new ArrayEventContext(typeCoercer, context), loopback);
    Link link = linkEncoder.createPageRenderLink(parameters);
    for (LinkCreationListener2 listener : listeners) listener.createdPageRenderLink(link, parameters);
    return link;
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) Link(org.apache.tapestry5.http.Link)

Example 27 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class LinkSourceImplTest method testPageLinkCreation2.

private void testPageLinkCreation2(String pageName, boolean overrideContext, Object... context) {
    PageActivationContextCollector collector = mockPageActivationContextCollector();
    LinkCreationListener2 listener = mockLinkCreationListener2();
    ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
    Link link = mockLink();
    ComponentClassResolver resolver = mockComponentClassResolver();
    String canonical = "CanonicalPageName";
    RequestGlobals globals = mockRequestGlobals();
    // Ensure that the loopback logic is off; loopback logic is fully tested via an
    // integration test.
    expect(globals.getActivePageName()).andReturn("someOtherPage");
    train_canonicalizePageName(resolver, pageName, canonical);
    if (!overrideContext)
        train_collectPageActivationContext(collector, canonical, context);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters(canonical, new ArrayEventContext(typeCoercer, context), false);
    expect(linkEncoder.createPageRenderLink(parameters)).andReturn(link);
    listener.createdPageRenderLink(link, parameters);
    replay();
    LinkSource source = new LinkSourceImpl(null, collector, typeCoercer, resolver, linkEncoder, globals, null, emptyConfiguration);
    source.getLinkCreationHub().addListener(listener);
    Object[] passedContext = overrideContext ? context : new Object[0];
    Link returnedLink = source.createPageRenderLink(pageName, overrideContext, passedContext);
    assertSame(returnedLink, link);
    verify();
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Link(org.apache.tapestry5.http.Link)

Example 28 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class LinkSourceImplTest method testEventLinkCreation.

private void testEventLinkCreation(String pageName, String nestedId, String eventType, boolean forForm, Object... context) {
    Page primaryPage = mockPage();
    PageRenderQueue queue = mockPageRenderQueue();
    PageActivationContextCollector collector = mockPageActivationContextCollector();
    LinkCreationListener2 listener = mockLinkCreationListener2();
    ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
    Link link = mockLink();
    ArrayEventContext eventContext = new ArrayEventContext(typeCoercer, context);
    ArrayEventContext pageEventContext = new ArrayEventContext(typeCoercer, "a", "b");
    train_getRenderingPage(queue, null);
    train_getName(primaryPage, pageName);
    train_collectPageActivationContext(collector, pageName, "a", "b");
    ComponentEventRequestParameters parameters = new ComponentEventRequestParameters(pageName, pageName, nestedId, eventType, pageEventContext, eventContext);
    expect(linkEncoder.createComponentEventLink(parameters, forForm)).andReturn(link);
    listener.createdComponentEventLink(link, parameters);
    replay();
    LinkSource source = new LinkSourceImpl(queue, collector, typeCoercer, null, linkEncoder, null, null, emptyConfiguration);
    source.getLinkCreationHub().addListener(listener);
    Link returnedLink = source.createComponentEventLink(primaryPage, nestedId, eventType, forForm, context);
    // Make sure the same link is returned.
    assertSame(returnedLink, link);
    verify();
}
Also used : ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) Page(org.apache.tapestry5.internal.structure.Page) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) Link(org.apache.tapestry5.http.Link)

Example 29 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class LinkSourceImplTest method create_page_render_link_by_name.

@Test
public void create_page_render_link_by_name() {
    String pageName = "order/Edit";
    PageActivationContextCollector collector = mockPageActivationContextCollector();
    ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
    Link link = mockLink();
    ComponentClassResolver resolver = mockComponentClassResolver();
    RequestGlobals globals = mockRequestGlobals();
    expect(globals.getActivePageName()).andReturn("someOtherPage");
    train_canonicalizePageName(resolver, pageName, pageName);
    train_collectPageActivationContext(collector, pageName, 3);
    EventContext pageActivationContext = new ArrayEventContext(typeCoercer, 3);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters(pageName, pageActivationContext, false);
    expect(linkEncoder.createPageRenderLink(parameters)).andReturn(link);
    replay();
    LinkSource source = new LinkSourceImpl(null, collector, typeCoercer, resolver, linkEncoder, globals, null, emptyConfiguration);
    Link actual = source.createPageRenderLink(pageName, false);
    // Make sure the same link is returned.
    assertEquals(actual, link);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 30 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class LinkSourceImplTest method component_event_from_other_page.

@Test
public void component_event_from_other_page() {
    String primaryPageName = "blocks/AppDisplay";
    Page primaryPage = mockPage();
    Page activePage = mockPage();
    PageRenderQueue queue = mockPageRenderQueue();
    PageActivationContextCollector collector = mockPageActivationContextCollector();
    ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
    Link link = mockLink();
    train_getRenderingPage(queue, activePage);
    train_getName(activePage, "order/View");
    train_getName(primaryPage, primaryPageName);
    train_collectPageActivationContext(collector, "order/View", "x", "y");
    EventContext pageActivationContext = new ArrayEventContext(typeCoercer, "x", "y");
    EventContext eventContext = new ArrayEventContext(typeCoercer, 3, 5, 9);
    ComponentEventRequestParameters parameters = new ComponentEventRequestParameters("order/View", primaryPageName, "gnip.gnop", "myevent", pageActivationContext, eventContext);
    expect(linkEncoder.createComponentEventLink(parameters, true)).andReturn(link);
    replay();
    LinkSource source = new LinkSourceImpl(queue, collector, typeCoercer, null, linkEncoder, null, null, emptyConfiguration);
    assertSame(source.createComponentEventLink(primaryPage, "gnip.gnop", "myevent", true, 3, 5, 9), link);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) Page(org.apache.tapestry5.internal.structure.Page) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)43 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)27 ComponentResources (org.apache.tapestry5.ComponentResources)19 Messages (org.apache.tapestry5.commons.Messages)13 FieldValidator (org.apache.tapestry5.FieldValidator)11 Validator (org.apache.tapestry5.Validator)11 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)11 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)11 ValidatorMacro (org.apache.tapestry5.validator.ValidatorMacro)11 Link (org.apache.tapestry5.http.Link)10 ComponentModel (org.apache.tapestry5.model.ComponentModel)10 FormSupport (org.apache.tapestry5.services.FormSupport)10 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)9 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)9 EventContext (org.apache.tapestry5.EventContext)7 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)7 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)7 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)6 MarkupWriter (org.apache.tapestry5.MarkupWriter)5 HibernateEntityValueEncoder (org.apache.tapestry5.hibernate.web.internal.HibernateEntityValueEncoder)4