Search in sources :

Example 1 with PageLifecycleListener

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

the class InternalComponentResourcesImplTest method add_page_lifecycle_listener.

@Test
public void add_page_lifecycle_listener() {
    Component component = mockComponent();
    Instantiator ins = mockInstantiator(component);
    ComponentModel model = mockComponentModel();
    ComponentPageElement element = mockComponentPageElement();
    Page page = mockPage();
    PageLifecycleListener listener = newMock(PageLifecycleListener.class);
    train_getModel(ins, model);
    page.addLifecycleListener(listener);
    replay();
    InternalComponentResources resources = new InternalComponentResourcesImpl(page, element, null, null, null, null, ins, false);
    resources.addPageLifecycleListener(listener);
    verify();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) ComponentModel(org.apache.tapestry5.model.ComponentModel) Instantiator(org.apache.tapestry5.internal.services.Instantiator) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 2 with PageLifecycleListener

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

the class PageImplTest method detach_notification.

@Test
public void detach_notification() {
    PageLifecycleListener listener1 = newPageLifecycle();
    PageLifecycleListener listener2 = newPageLifecycle();
    listener1.containingPageDidDetach();
    listener2.containingPageDidDetach();
    MetaDataLocator locator = newMetaDataLocator(LOGICAL_PAGE_NAME, true);
    replay();
    Page page = new PageImpl(LOGICAL_PAGE_NAME, selector, null, perThreadManager, locator);
    page.addLifecycleListener(listener1);
    page.addLifecycleListener(listener2);
    assertFalse(page.detached());
    verify();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 3 with PageLifecycleListener

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

the class PageImplTest method attach_notification.

@Test
public void attach_notification() {
    MetaDataLocator locator = newMetaDataLocator(LOGICAL_PAGE_NAME, true);
    PageLifecycleListener listener1 = newPageLifecycle();
    PageLifecycleListener listener2 = newPageLifecycle();
    listener1.containingPageDidAttach();
    listener2.containingPageDidAttach();
    replay();
    Page page = new PageImpl(LOGICAL_PAGE_NAME, selector, null, perThreadManager, locator);
    page.addLifecycleListener(listener1);
    page.addLifecycleListener(listener2);
    page.attached();
    verify();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 4 with PageLifecycleListener

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

the class PageImplTest method detach_dirty_if_listener_throws_exception.

/**
 * Also checks that all listeners are invoked, even if one of them throws an exception.
 */
@Test
public void detach_dirty_if_listener_throws_exception() {
    ComponentPageElement element = mockComponentPageElement();
    Logger logger = mockLogger();
    PageLifecycleListener listener1 = newPageLifecycle();
    PageLifecycleListener listener2 = newPageLifecycle();
    RuntimeException t = new RuntimeException("Listener detach exception.");
    MetaDataLocator locator = newMetaDataLocator(LOGICAL_PAGE_NAME, true);
    train_getLogger(element, logger);
    listener1.containingPageDidDetach();
    setThrowable(t);
    logger.error(contains("failed during page detach"), same(t));
    listener2.containingPageDidDetach();
    replay();
    Page page = new PageImpl(LOGICAL_PAGE_NAME, selector, null, perThreadManager, locator);
    page.setRootElement(element);
    page.addLifecycleListener(listener1);
    page.addLifecycleListener(listener2);
    assertTrue(page.detached());
    verify();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) Logger(org.slf4j.Logger) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 5 with PageLifecycleListener

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

the class PageImplTest method load_notification.

@Test
public void load_notification() {
    MetaDataLocator locator = newMetaDataLocator(LOGICAL_PAGE_NAME, true);
    PageLifecycleListener listener1 = newPageLifecycle();
    PageLifecycleListener listener2 = newPageLifecycle();
    listener1.containingPageDidLoad();
    listener2.containingPageDidLoad();
    replay();
    Page page = new PageImpl(LOGICAL_PAGE_NAME, selector, null, perThreadManager, locator);
    page.addLifecycleListener(listener1);
    page.addLifecycleListener(listener2);
    page.loaded();
    verify();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Aggregations

PageLifecycleListener (org.apache.tapestry5.runtime.PageLifecycleListener)5 Test (org.testng.annotations.Test)5 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)4 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)1 Instantiator (org.apache.tapestry5.internal.services.Instantiator)1 ComponentModel (org.apache.tapestry5.model.ComponentModel)1 Component (org.apache.tapestry5.runtime.Component)1 Logger (org.slf4j.Logger)1