Search in sources :

Example 21 with EventContext

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

the class ComponentEventImplTest method coerce_when_not_enough_context.

@Test
public void coerce_when_not_enough_context() {
    ComponentEventCallback handler = mockComponentEventHandler();
    EventContext context = mockEventContext();
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, true);
    logger.debug(eq(TapestryMarkers.EVENT_HANDLER_METHOD), isA(String.class));
    train_getCount(context, 0);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, null, false, model, logger);
    event.setMethodDescription("foo.Bar.baz()");
    try {
        event.coerceContext(1, "java.lang.Integer");
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "Method foo.Bar.baz() has more parameters than there are context values for this component event.");
    }
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 22 with EventContext

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

the class ComponentEventImplTest method component_id_matches_are_case_insensitive.

@Test
public void component_id_matches_are_case_insensitive() {
    ComponentEventCallback handler = mockComponentEventHandler();
    EventContext context = mockEventContext();
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_getCount(context, 0);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, null, false, model, logger);
    assertTrue(event.matches("eventtype", "SOMEID", 0));
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 23 with EventContext

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

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

use of org.apache.tapestry5.EventContext 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

EventContext (org.apache.tapestry5.EventContext)16 Test (org.testng.annotations.Test)15 Logger (org.slf4j.Logger)9 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)8 Link (org.apache.tapestry5.http.Link)8 ComponentModel (org.apache.tapestry5.model.ComponentModel)8 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)8 Page (org.apache.tapestry5.internal.structure.Page)5 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)5 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)4 AbstractEventContext (org.apache.tapestry5.internal.AbstractEventContext)3 ComponentPageElementResources (org.apache.tapestry5.internal.structure.ComponentPageElementResources)3 JSONObject (org.apache.tapestry5.json.JSONObject)3 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)3 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)3 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)3 Request (org.apache.tapestry5.http.services.Request)2 PageRenderLinkSource (org.apache.tapestry5.services.PageRenderLinkSource)2 IOException (java.io.IOException)1