Search in sources :

Example 1 with PersistentFieldStrategy

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

the class PersistentFieldManagerImpl method postChange.

public void postChange(String pageName, ComponentResources resources, String fieldName, Object newValue) {
    String strategyName = findStrategy(resources, fieldName);
    PersistentFieldStrategy strategy = getStrategy(strategyName);
    strategy.postChange(pageName, resources.getNestedId(), fieldName, newValue);
}
Also used : PersistentFieldStrategy(org.apache.tapestry5.services.PersistentFieldStrategy)

Example 2 with PersistentFieldStrategy

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

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

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

Example 5 with PersistentFieldStrategy

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

the class PersistentFieldManagerImplTest method strategy_name_is_case_insensitive.

public void strategy_name_is_case_insensitive() {
    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("foo", 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)

Aggregations

PersistentFieldStrategy (org.apache.tapestry5.services.PersistentFieldStrategy)10 Test (org.testng.annotations.Test)8 ComponentResources (org.apache.tapestry5.ComponentResources)5 ComponentModel (org.apache.tapestry5.model.ComponentModel)5 Request (org.apache.tapestry5.http.services.Request)2 Session (org.apache.tapestry5.http.services.Session)2 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)2 PersistentFieldChange (org.apache.tapestry5.services.PersistentFieldChange)2 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)1 PersistentFieldBundle (org.apache.tapestry5.services.PersistentFieldBundle)1