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