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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations