Search in sources :

Example 1 with ComponentClassResolver

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

the class ComponentEventDispatcherTest method request_for_whitelist_only_page_from_client_not_on_whitelist.

@Test
public void request_for_whitelist_only_page_from_client_not_on_whitelist() throws IOException {
    String requestPath = "/foo/MyPage:anevent";
    String localeName = "foo";
    String containerPageName = "foo/MyPage";
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter localizationSetter = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = newMock(MetaDataLocator.class);
    ClientWhitelist whitelist = newMock(ClientWhitelist.class);
    train_getPath(request, requestPath);
    expect(localizationSetter.isSupportedLocaleName("foo")).andReturn(false);
    train_isPageName(resolver, containerPageName, true);
    train_canonicalizePageName(resolver, containerPageName, containerPageName);
    expect(metaDataLocator.findMeta(MetaDataConstants.WHITELIST_ONLY_PAGE, containerPageName, boolean.class)).andReturn(true);
    expect(whitelist.isClientRequestOnWhitelist()).andReturn(false);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, localizationSetter, response, null, null, null, true, null, "", metaDataLocator, whitelist));
    assertFalse(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) ClientWhitelist(org.apache.tapestry5.services.security.ClientWhitelist) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 2 with ComponentClassResolver

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

the class ComponentEventDispatcherTest method request_path_reference_non_existent_page.

@Test
public void request_path_reference_non_existent_page() throws Exception {
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter ls = mockLocalizationSetter();
    expect(ls.isSupportedLocaleName("en")).andReturn(true);
    train_getPath(request, "/en/mypage.foo");
    train_isPageName(resolver, "mypage", false);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(null, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", null, null));
    assertFalse(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) Test(org.testng.annotations.Test)

Example 3 with ComponentClassResolver

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

the class ComponentEventDispatcherTest method test.

private void test(String requestPath, String localeName, String containerPageName, String nestedComponentId, String eventType, String... eventContext) throws IOException {
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter localizationSetter = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters(containerPageName, containerPageName, nestedComponentId, eventType, new EmptyEventContext(), new URLEventContext(contextValueEncoder, eventContext));
    train_getPath(request, requestPath);
    expect(localizationSetter.isSupportedLocaleName(localeName)).andReturn(false);
    train_isPageName(resolver, containerPageName, true);
    train_canonicalizePageName(resolver, containerPageName, containerPageName);
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    handler.handleComponentEvent(expectedParameters);
    train_for_request_locale(request, localizationSetter);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, localizationSetter, response, null, null, null, true, null, "", metaDataLocator, null));
    assertTrue(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) URLEventContext(org.apache.tapestry5.internal.URLEventContext) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator)

Example 4 with ComponentClassResolver

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

the class ComponentEventDispatcherTest method different_active_and_containing_pages.

@Test
public void different_active_and_containing_pages() throws Exception {
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters("activepage", "mypage", "", "eventname", new EmptyEventContext(), new EmptyEventContext());
    train_getPath(request, "/activepage:eventname");
    expect(ls.isSupportedLocaleName("activepage:eventname")).andReturn(false);
    train_isPageName(resolver, "activepage", true);
    train_canonicalizePageName(resolver, "activepage", "activepage");
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, "mypage");
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    train_canonicalizePageName(resolver, "mypage", "mypage");
    train_for_request_locale(request, ls);
    handler.handleComponentEvent(expectedParameters);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", metaDataLocator, null));
    assertTrue(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 5 with ComponentClassResolver

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

the class PageRenderLinkSourceImplTest method override_passivate_context.

@Test
public void override_passivate_context() {
    ComponentClassResolver resolver = mockComponentClassResolver();
    LinkSource source = mockLinkSource();
    Link link = mockLink();
    EventContext eventContext = mockEventContext();
    train_resolvePageClassNameToPageName(resolver, PAGE_CLASS.getName(), PAGE_NAME);
    expect(source.createPageRenderLink(PAGE_NAME, true, "fred", "barney")).andReturn(link);
    train_resolvePageClassNameToPageName(resolver, PAGE_CLASS.getName(), PAGE_NAME);
    train_getCount(eventContext, 2);
    train_get(eventContext, Object.class, 0, "ted");
    train_get(eventContext, Object.class, 1, "barney");
    expect(source.createPageRenderLink(PAGE_NAME, true, "ted", "barney")).andReturn(link);
    replay();
    PageRenderLinkSource service = new PageRenderLinkSourceImpl(source, resolver);
    assertSame(service.createPageRenderLinkWithContext(PAGE_CLASS, "fred", "barney"), link);
    assertSame(service.createPageRenderLinkWithContext(PAGE_CLASS, eventContext), link);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) PageRenderLinkSource(org.apache.tapestry5.services.PageRenderLinkSource) PageRenderLinkSource(org.apache.tapestry5.services.PageRenderLinkSource) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Aggregations

ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)27 Test (org.testng.annotations.Test)23 Request (org.apache.tapestry5.http.services.Request)17 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)17 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)13 Response (org.apache.tapestry5.http.services.Response)11 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)11 Link (org.apache.tapestry5.http.Link)6 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)6 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)6 Page (org.apache.tapestry5.internal.structure.Page)5 Component (org.apache.tapestry5.runtime.Component)5 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)5 ComponentSource (org.apache.tapestry5.services.ComponentSource)5 RequestGlobals (org.apache.tapestry5.http.services.RequestGlobals)4 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ClientWhitelist (org.apache.tapestry5.services.security.ClientWhitelist)4 EventContext (org.apache.tapestry5.EventContext)3 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)3 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2