Search in sources :

Example 21 with LocalizationSetter

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

the class ComponentEventDispatcherTest method page_activation_context_in_request.

@Test
public void page_activation_context_in_request() throws Exception {
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters("mypage", "mypage", "", "eventname", new URLEventContext(contextValueEncoder, new String[] { "alpha", "beta" }), new EmptyEventContext());
    train_getPath(request, "/mypage:eventname");
    expect(ls.isSupportedLocaleName("mypage:eventname")).andReturn(false);
    train_isPageName(resolver, "mypage", true);
    train_canonicalizePageName(resolver, "mypage", "mypage");
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, "alpha/beta");
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    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 : 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) URLEventContext(org.apache.tapestry5.internal.URLEventContext) 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)

Example 22 with LocalizationSetter

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

the class LocalizationSetterImplTest method get_selected_locale_names.

@Test
public void get_selected_locale_names() {
    LocalizationSetter setter = new LocalizationSetterImpl(null, null, null, "en,fr");
    Object localeNames = TestBase.get(setter, "supportedLocaleNames");
    assertTrue(newSet("en", "fr").equals(localeNames));
}
Also used : LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Test(org.testng.annotations.Test)

Example 23 with LocalizationSetter

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

the class LocalizationSetterImplTest method known_locale.

@Test
public void known_locale() {
    PersistentLocale pl = mockPersistentLocale();
    ThreadLocale tl = mockThreadLocale();
    Request request = mockRequest();
    tl.setLocale(Locale.FRENCH);
    pl.set(Locale.FRENCH);
    replay();
    LocalizationSetter setter = new LocalizationSetterImpl(request, pl, tl, "en,fr");
    assertTrue(setter.setLocaleFromLocaleName("fr"));
    verify();
}
Also used : PersistentLocale(org.apache.tapestry5.services.PersistentLocale) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Test(org.testng.annotations.Test)

Example 24 with LocalizationSetter

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

the class LocalizationSetterImplTest method to_locale_is_cached.

@Test
public void to_locale_is_cached() {
    LocalizationSetter setter = new LocalizationSetterImpl(null, null, null, "en");
    Locale l1 = setter.toLocale("en");
    assertEquals(l1.toString(), "en");
    checkLocale(l1, "en", "", "");
    assertSame(setter.toLocale("en"), l1);
}
Also used : ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) PersistentLocale(org.apache.tapestry5.services.PersistentLocale) Locale(java.util.Locale) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Test(org.testng.annotations.Test)

Example 25 with LocalizationSetter

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

the class LocalizationSetterImplTest method get_selected_locales.

@Test
public void get_selected_locales() {
    LocalizationSetter setter = new LocalizationSetterImpl(null, null, null, "en,fr");
    assertListsEquals(setter.getSupportedLocales(), Locale.ENGLISH, Locale.FRENCH);
}
Also used : LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) 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