Search in sources :

Example 26 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class ComponentTemplateSourceImplTest method child_component_inherits_parent_template.

@Test
public void child_component_inherits_parent_template() {
    TemplateParser parser = mockTemplateParser();
    ComponentTemplate template = mockComponentTemplate();
    ComponentModel model = mockComponentModel();
    ComponentModel parentModel = mockComponentModel();
    Resource resource = mockResource();
    ComponentResourceLocator locator = mockLocator(model, english, null);
    train_getComponentClassName(model, "foo.Bar");
    train_getParentModel(model, parentModel);
    expect(locator.locateTemplate(parentModel, english)).andReturn(resource).once();
    expect(resource.exists()).andReturn(true);
    expect(resource.toURL()).andReturn(null);
    train_parseTemplate(parser, resource, template);
    replay();
    ComponentTemplateSource source = new ComponentTemplateSourceImpl(true, parser, locator, converter, componentRequestSelectorAnalyzer, threadLocale);
    assertSame(source.getTemplate(model, english), template);
    verify();
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) ComponentResourceLocator(org.apache.tapestry5.services.pageload.ComponentResourceLocator) ComponentTemplate(org.apache.tapestry5.internal.parser.ComponentTemplate) Test(org.testng.annotations.Test)

Example 27 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel 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 28 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel 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 29 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel 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 30 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class ComponentAssemblerImpl method addRootComponentMixins.

private void addRootComponentMixins(PageAssembly assembly, ComponentPageElement element) {
    for (String className : instantiator.getModel().getMixinClassNames()) {
        assembly.weight++;
        Instantiator mixinInstantiator = instantiatorSource.getInstantiator(className);
        ComponentModel model = instantiator.getModel();
        element.addMixin(InternalUtils.lastTerm(className), mixinInstantiator, model.getOrderForMixin(className));
    }
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) EmbeddedComponentModel(org.apache.tapestry5.model.EmbeddedComponentModel) Instantiator(org.apache.tapestry5.internal.services.Instantiator)

Aggregations

ComponentModel (org.apache.tapestry5.model.ComponentModel)64 Test (org.testng.annotations.Test)48 ComponentResources (org.apache.tapestry5.ComponentResources)16 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)15 Logger (org.slf4j.Logger)14 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)12 Instantiator (org.apache.tapestry5.internal.services.Instantiator)11 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)11 Resource (org.apache.tapestry5.commons.Resource)10 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)10 Component (org.apache.tapestry5.runtime.Component)10 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)9 EventContext (org.apache.tapestry5.EventContext)8 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)7 EmbeddedComponentModel (org.apache.tapestry5.model.EmbeddedComponentModel)7 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)6 ComponentPageElementResources (org.apache.tapestry5.internal.structure.ComponentPageElementResources)6 ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)6 Messages (org.apache.tapestry5.commons.Messages)5 PersistentFieldStrategy (org.apache.tapestry5.services.PersistentFieldStrategy)5