Search in sources :

Example 1 with MetaDataLocator

use of org.apache.tapestry5.services.MetaDataLocator 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 MetaDataLocator

use of org.apache.tapestry5.services.MetaDataLocator 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 3 with MetaDataLocator

use of org.apache.tapestry5.services.MetaDataLocator 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 4 with MetaDataLocator

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

the class PersistentFieldManagerImplTest method post_change_strategy_by_meta_data.

@Test
public void post_change_strategy_by_meta_data() {
    String pageName = "foo.Bar";
    String nestedId = "nested";
    String fieldName = "field";
    String strategyName = "foo";
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    PersistentFieldStrategy strat = newPersistentFieldStrategy();
    MetaDataLocator locator = mockMetaDataLocator();
    Object value = new Object();
    Map<String, PersistentFieldStrategy> strategies = newMap();
    strategies.put(strategyName, strat);
    train_getComponentModel(resources, model);
    train_getFieldPersistenceStrategy(model, fieldName, "");
    train_findMeta(locator, SymbolConstants.PERSISTENCE_STRATEGY, resources, String.class, strategyName);
    train_getNestedId(resources, nestedId);
    strat.postChange(pageName, nestedId, fieldName, value);
    replay();
    PersistentFieldManager manager = new PersistentFieldManagerImpl(locator, strategies);
    manager.postChange(pageName, resources, fieldName, value);
    verify();
}
Also used : PersistentFieldStrategy(org.apache.tapestry5.services.PersistentFieldStrategy) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 5 with MetaDataLocator

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

the class PersistentFieldManagerImplTest method post_change_with_ultimate_default_strategy.

@Test
public void post_change_with_ultimate_default_strategy() {
    String pageName = "foo.Bar";
    String nestedId = "nested";
    String fieldName = "field";
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    MetaDataLocator locator = mockMetaDataLocator();
    PersistentFieldStrategy strat = newPersistentFieldStrategy();
    Object value = new Object();
    Map<String, PersistentFieldStrategy> strategies = newMap();
    strategies.put(PersistenceConstants.SESSION, strat);
    train_getComponentModel(resources, model);
    train_getFieldPersistenceStrategy(model, fieldName, "");
    train_findMeta(locator, SymbolConstants.PERSISTENCE_STRATEGY, resources, String.class, PersistenceConstants.SESSION);
    train_getNestedId(resources, nestedId);
    strat.postChange(pageName, nestedId, fieldName, value);
    replay();
    PersistentFieldManager manager = new PersistentFieldManagerImpl(locator, strategies);
    manager.postChange(pageName, resources, fieldName, value);
    verify();
}
Also used : PersistentFieldStrategy(org.apache.tapestry5.services.PersistentFieldStrategy) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Aggregations

MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)37 Test (org.testng.annotations.Test)32 Request (org.apache.tapestry5.http.services.Request)18 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)13 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)13 Response (org.apache.tapestry5.http.services.Response)12 ComponentModel (org.apache.tapestry5.model.ComponentModel)11 ComponentResources (org.apache.tapestry5.ComponentResources)9 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)9 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)8 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)7 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)6 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)5 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)5 PageLifecycleListener (org.apache.tapestry5.runtime.PageLifecycleListener)4 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)4 ClientWhitelist (org.apache.tapestry5.services.security.ClientWhitelist)4 URLEventContext (org.apache.tapestry5.internal.URLEventContext)2 PersistentFieldStrategy (org.apache.tapestry5.services.PersistentFieldStrategy)2 Link (org.apache.tapestry5.http.Link)1