Search in sources :

Example 6 with LocalizationSetter

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

the class ComponentEventLinkEncoderImplTest method page_requires_whitelist_and_client_on_whitelist.

@Test
public void page_requires_whitelist_and_client_on_whitelist() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest(false);
    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(true);
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, whitelist);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertEquals(parameters.getLogicalPageName(), "foo/bar");
    assertEquals(parameters.getActivationContext().getCount(), 0);
    assertFalse(parameters.isLoopback());
    verify();
}
Also used : ClientWhitelist(org.apache.tapestry5.services.security.ClientWhitelist) 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) Test(org.testng.annotations.Test)

Example 7 with LocalizationSetter

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

the class ComponentEventLinkEncoderImplTest method illegal_activation_context_leads_to_http_404.

@Test
public // TAP5-2436
void illegal_activation_context_leads_to_http_404() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    train_getPath(request, "/foo/pageid=123");
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/pageid=123", false);
    train_isPageName(resolver, "foo", false);
    train_isPageName(resolver, "", true);
    train_canonicalizePageName(resolver, "", "Index");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", metaDataLocator, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertNull(parameters);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) 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) Test(org.testng.annotations.Test)

Example 8 with LocalizationSetter

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

the class ComponentEventLinkEncoderImplTest method page_activation_context_for_root_index_page.

/**
 * TAPESTRY-2226
 */
@Test
public void page_activation_context_for_root_index_page() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest(false);
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    train_getPath(request, "/foo/bar");
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/bar", false);
    train_isPageName(resolver, "foo", false);
    train_isPageName(resolver, "", true);
    train_canonicalizePageName(resolver, "", "index");
    train_getLocale(request, Locale.ITALIAN);
    ls.setNonPersistentLocaleFromLocaleName("it");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertEquals(parameters.getLogicalPageName(), "index");
    assertArraysEqual(parameters.getActivationContext().toStrings(), "foo", "bar");
    assertFalse(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) Test(org.testng.annotations.Test)

Example 9 with LocalizationSetter

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

the class ComponentEventLinkEncoderImplTest method not_a_page_request.

@Test
public void not_a_page_request() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    stub_isPageName(resolver, false);
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_getPath(request, "/foo/Bar.baz");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", null, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertNull(parameters);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) 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) Test(org.testng.annotations.Test)

Example 10 with LocalizationSetter

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

the class ComponentEventLinkEncoderImplTest method empty_path.

@Test
public void empty_path() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    train_getPath(request, "");
    train_setLocaleFromLocaleName(ls, "", false);
    train_isPageName(resolver, "", false);
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", null, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertNull(parameters);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) 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) 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