Search in sources :

Example 1 with ComponentSource

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

the class ComponentSourceImplTest method get_active_page.

@Test
public void get_active_page() {
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    Component component = mockComponent();
    ComponentClassResolver resolver = mockComponentClassResolver();
    RequestGlobals globals = mockRequestGlobals();
    String pageName = "Active";
    expect(globals.getActivePageName()).andReturn(pageName);
    train_get(cache, pageName, page);
    train_getRootComponent(page, component);
    replay();
    ComponentSource source = new ComponentSourceImpl(cache, resolver, globals);
    assertSame(source.getActivePage(), component);
    verify();
}
Also used : ComponentSource(org.apache.tapestry5.services.ComponentSource) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Page(org.apache.tapestry5.internal.structure.Page) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 2 with ComponentSource

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

the class ComponentSourceImplTest method nested_element_within_page.

@Test
public void nested_element_within_page() {
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    ComponentPageElement element = mockComponentPageElement();
    Component component = mockComponent();
    ComponentClassResolver resolver = mockComponentClassResolver();
    train_get(cache, PAGE_NAME, page);
    train_getComponentElementByNestedId(page, NESTED_ELEMENT_ID, element);
    train_getComponent(element, component);
    replay();
    ComponentSource source = new ComponentSourceImpl(cache, resolver, null);
    assertSame(source.getComponent(PAGE_NAME + ":" + NESTED_ELEMENT_ID), component);
    verify();
}
Also used : ComponentSource(org.apache.tapestry5.services.ComponentSource) ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Page(org.apache.tapestry5.internal.structure.Page) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 3 with ComponentSource

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

the class ComponentSourceImplTest method get_page_by_class.

@Test
public void get_page_by_class() {
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    Component component = mockComponent();
    ComponentClassResolver resolver = mockComponentClassResolver();
    train_resolvePageClassNameToPageName(resolver, ComponentSourceImplTest.class.getName(), PAGE_NAME);
    train_get(cache, PAGE_NAME, page);
    train_getRootComponent(page, component);
    replay();
    ComponentSource source = new ComponentSourceImpl(cache, resolver, null);
    assertSame(source.getPage(ComponentSourceImplTest.class), component);
    verify();
}
Also used : ComponentSource(org.apache.tapestry5.services.ComponentSource) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Page(org.apache.tapestry5.internal.structure.Page) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 4 with ComponentSource

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

the class ComponentSourceImplTest method root_element_of_page.

@Test
public void root_element_of_page() {
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    Component component = mockComponent();
    ComponentClassResolver resolver = mockComponentClassResolver();
    train_get(cache, PAGE_NAME, page);
    train_getRootComponent(page, component);
    replay();
    ComponentSource source = new ComponentSourceImpl(cache, resolver, null);
    assertSame(source.getComponent(PAGE_NAME), component);
    verify();
}
Also used : ComponentSource(org.apache.tapestry5.services.ComponentSource) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Page(org.apache.tapestry5.internal.structure.Page) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 5 with ComponentSource

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

the class ComponentSourceImplTest method get_active_page_before_known.

@Test
public void get_active_page_before_known() {
    RequestGlobals globals = mockRequestGlobals();
    expect(globals.getActivePageName()).andReturn(null);
    replay();
    ComponentSource source = new ComponentSourceImpl(null, null, globals);
    assertNull(source.getActivePage());
    verify();
}
Also used : ComponentSource(org.apache.tapestry5.services.ComponentSource) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Test(org.testng.annotations.Test)

Aggregations

ComponentSource (org.apache.tapestry5.services.ComponentSource)6 Test (org.testng.annotations.Test)6 Page (org.apache.tapestry5.internal.structure.Page)5 Component (org.apache.tapestry5.runtime.Component)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)5 RequestGlobals (org.apache.tapestry5.http.services.RequestGlobals)2 ComponentPageElement (org.apache.tapestry5.internal.structure.ComponentPageElement)1