Search in sources :

Example 6 with ComponentModel

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

the class MutableComponentModelImplTest method get_mixin_class_names_with_no_mixins.

@Test
public void get_mixin_class_names_with_no_mixins() {
    Resource r = mockResource();
    Logger logger = mockLogger();
    replay();
    ComponentModel model = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
    assertTrue(model.getMixinClassNames().isEmpty());
    verify();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableEmbeddedComponentModel(org.apache.tapestry5.model.MutableEmbeddedComponentModel) ComponentModel(org.apache.tapestry5.model.ComponentModel) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) Test(org.testng.annotations.Test)

Example 7 with ComponentModel

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

the class AssetInjectionProvider method provideInjection.

public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
    Path path = field.getAnnotation(Path.class);
    if (path == null) {
        return false;
    }
    final String assetPath = path.value();
    final String libraryName = componentModel.getLibraryName();
    ComputedValue<Asset> computedAsset = new ComputedValue<Asset>() {

        public Asset get(InstanceContext context) {
            ComponentResources resources = context.get(ComponentResources.class);
            // a different library name than the subclass).
            return assetSource.getComponentAsset(resources, assetPath, libraryName);
        }
    };
    field.injectComputed(computedAsset);
    return true;
}
Also used : Path(org.apache.tapestry5.annotations.Path) ComputedValue(org.apache.tapestry5.plastic.ComputedValue) InstanceContext(org.apache.tapestry5.plastic.InstanceContext) Asset(org.apache.tapestry5.Asset) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 8 with ComponentModel

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

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

Example 10 with ComponentModel

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

the class PersistentFieldManagerImplTest method post_change.

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

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