Search in sources :

Example 16 with LocalizationSetter

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

the class ComponentEventLinkEncoderImplTest method context_passed_in_path.

private void context_passed_in_path(boolean finalSlash) throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest(true);
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    String path = "/foo/Bar/zip/zoom" + (finalSlash ? "/" : "");
    train_getPath(request, path);
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/Bar/zip/zoom", false);
    train_isPageName(resolver, "foo/Bar/zip", false);
    train_isPageName(resolver, "foo/Bar", true);
    train_canonicalizePageName(resolver, "foo/Bar", "foo/bar");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertEquals(parameters.getLogicalPageName(), "foo/bar");
    assertArraysEqual(parameters.getActivationContext().toStrings(), "zip", "zoom");
    assertTrue(parameters.isLoopback());
    verify();
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator)

Example 17 with LocalizationSetter

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

the class ComponentEventLinkEncoderImplTest method decode_compoent_event_request_with_slash_in_context_path.

@Test
public void decode_compoent_event_request_with_slash_in_context_path() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    expect(ls.isSupportedLocaleName("page.component:event")).andReturn(false);
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
    train_getLocale(request, Locale.ENGLISH);
    ls.setNonPersistentLocaleFromLocaleName("en");
    train_getPath(request, "/foo/bar/page.component:event");
    train_isPageName(resolver, "page", true);
    train_canonicalizePageName(resolver, "page", "Page");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "foo/bar", metaDataLocator, null);
    ComponentEventRequestParameters parameters = linkEncoder.decodeComponentEventRequest(request);
    assertNotNull(parameters);
    assertEquals(parameters.getActivePageName(), "Page");
    assertEquals(parameters.getEventType(), "event");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 18 with LocalizationSetter

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

the class ComponentEventLinkEncoderImplTest method page_name_includes_dash_in_component_event_request.

@Test
public void page_name_includes_dash_in_component_event_request() {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    expect(ls.isSupportedLocaleName("foo-bar")).andReturn(false);
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
    train_getLocale(request, Locale.ENGLISH);
    ls.setNonPersistentLocaleFromLocaleName("en");
    String path = "/foo-bar/baz.biff";
    train_getPath(request, path);
    train_isPageName(resolver, "foo-bar/baz", true);
    train_canonicalizePageName(resolver, "foo-bar/baz", "foo-bar/Baz");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, null);
    ComponentEventRequestParameters parameters = linkEncoder.decodeComponentEventRequest(request);
    assertEquals(parameters.getActivePageName(), "foo-bar/Baz");
    assertEquals(parameters.getNestedComponentId(), "biff");
    verify();
}
Also used : ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 19 with LocalizationSetter

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

the class ComponentEventLinkEncoderImplTest method page_requires_whitelist_and_client_not_on_whitelist.

@Test
public void page_requires_whitelist_and_client_not_on_whitelist() {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = mockMetaDataLocator();
    ClientWhitelist whitelist = newMock(ClientWhitelist.class);
    String path = "/foo/Bar";
    train_getPath(request, path);
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/Bar", true);
    train_canonicalizePageName(resolver, "foo/Bar", "foo/bar");
    expect(metaDataLocator.findMeta(MetaDataConstants.WHITELIST_ONLY_PAGE, "foo/bar", boolean.class)).andReturn(true);
    expect(whitelist.isClientRequestOnWhitelist()).andReturn(false);
    train_isPageName(resolver, "foo", false);
    train_isPageName(resolver, "", false);
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, whitelist);
    assertNull(linkEncoder.decodePageRenderRequest(request));
    verify();
}
Also used : ClientWhitelist(org.apache.tapestry5.services.security.ClientWhitelist) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 20 with LocalizationSetter

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

the class ComponentEventDispatcherTest method request_for_whitelist_only_page_from_valid_client.

@Test
public void request_for_whitelist_only_page_from_valid_client() throws IOException {
    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);
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters(containerPageName, containerPageName, "", "anevent", new EmptyEventContext(), new EmptyEventContext());
    train_getPath(request, "/foo/MyPage:anevent");
    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(true);
    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);
    train_for_request_locale(request, localizationSetter);
    handler.handleComponentEvent(expectedParameters);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, localizationSetter, response, null, null, null, true, null, "", metaDataLocator, whitelist));
    assertTrue(dispatcher.dispatch(request, response));
    verify();
}
Also used : ClientWhitelist(org.apache.tapestry5.services.security.ClientWhitelist) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) Response(org.apache.tapestry5.http.services.Response) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Aggregations

LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)24 Test (org.testng.annotations.Test)21 Request (org.apache.tapestry5.http.services.Request)19 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)17 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)13 Response (org.apache.tapestry5.http.services.Response)12 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)8 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)7 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)6 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)5 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ClientWhitelist (org.apache.tapestry5.services.security.ClientWhitelist)4 Locale (java.util.Locale)2 URLEventContext (org.apache.tapestry5.internal.URLEventContext)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)2 PersistentLocale (org.apache.tapestry5.services.PersistentLocale)2 OptionModel (org.apache.tapestry5.OptionModel)1 SelectModel (org.apache.tapestry5.SelectModel)1 ModuleDispatcher (org.apache.tapestry5.internal.services.javascript.ModuleDispatcher)1