Search in sources :

Example 16 with MetaDataLocator

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

the class MetaDataLocatorImplTest method not_found_by_page_name_but_found_in_configuration.

@Test
public void not_found_by_page_name_but_found_in_configuration() {
    ComponentModel model = mockComponentModel();
    SymbolSource symbolSource = mockSymbolSource();
    ComponentModelSource modelSource = mockComponentModelSource();
    String key = "foo.bar";
    String value = "zaphod";
    String pageName = "gnip/Gnop";
    expect(modelSource.getPageModel(pageName)).andReturn(model);
    train_getMeta(model, key, null);
    train_expandSymbols(symbolSource, value, "*expanded*");
    replay();
    Map<String, String> configuration = CollectionFactory.newMap();
    configuration.put("gnip:foo.bar", value);
    MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
    assertSame(locator.findMeta(key, pageName, String.class), "*expanded*");
    verify();
}
Also used : SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 17 with MetaDataLocator

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

the class MetaDataLocatorImplTest method find_by_page_name.

@Test
public void find_by_page_name() {
    ComponentModel model = mockComponentModel();
    SymbolSource symbolSource = mockSymbolSource();
    ComponentModelSource modelSource = mockComponentModelSource();
    String key = "foo.bar";
    String value = "zaphod";
    String pageName = "foo/Bar";
    expect(modelSource.getPageModel(pageName)).andReturn(model);
    train_getMeta(model, key, value);
    train_expandSymbols(symbolSource, value, "*expanded*");
    replay();
    Map<String, String> configuration = Collections.emptyMap();
    MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
    assertSame(locator.findMeta(key, pageName, String.class), "*expanded*");
    verify();
}
Also used : SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 18 with MetaDataLocator

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

the class MetaDataLocatorImplTest method default_to_symbol_source.

@Test
public void default_to_symbol_source() {
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    SymbolSource symbolSource = mockSymbolSource();
    ComponentModelSource modelSource = mockComponentModelSource();
    String key = "foo.bar";
    String value = "zaphod";
    String completeId = "foo/Bar:baz";
    train_getCompleteId(resources, completeId);
    train_getComponentModel(resources, model);
    train_getMeta(model, key, null);
    train_getContainerResources(resources, null);
    train_getPageName(resources, "foo/Bar");
    train_valueForSymbol(symbolSource, key, value);
    replay();
    Map<String, String> configuration = Collections.emptyMap();
    MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
    // And check that it's cached:
    train_getCompleteId(resources, completeId);
    replay();
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
}
Also used : SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 19 with MetaDataLocator

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

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

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