use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.
the class SelectTest method context_that_needs_to_be_encoded.
@Test
public void context_that_needs_to_be_encoded() throws Exception {
ValueEncoderSource valueEncoderSource = mockValueEncoderSource();
TypeCoercer typeCoercer = getService(TypeCoercer.class);
ContextValueEncoder contextValueEncoder = new ContextValueEncoderImpl(valueEncoderSource);
ValueEncoder<Platform> platformEncoder = new ValueEncoder<SelectTest.Platform>() {
@Override
public Platform toValue(String clientValue) {
return Platform.valueOf(clientValue.substring(10));
}
@Override
public String toClient(Platform value) {
return "Platform: " + value.name();
}
};
InternalComponentResources resources = mockInternalComponentResources();
expect(valueEncoderSource.getValueEncoder(Platform.class)).andReturn(platformEncoder).anyTimes();
expect(valueEncoderSource.getValueEncoder(String.class)).andReturn(new StringValueEncoder()).anyTimes();
expect(resources.triggerContextEvent(EasyMock.eq(EventConstants.VALUE_CHANGED), eqEventContext(null, Platform.LINUX), EasyMock.isA(ComponentEventCallback.class))).andReturn(true);
Select select = new Select();
set(select, "resources", resources);
set(select, "encoder", new StringValueEncoder());
set(select, "typeCoercer", typeCoercer);
replay();
select.onChange(new URLEventContext(contextValueEncoder, new String[] { platformEncoder.toClient(Platform.LINUX) }), null);
verify();
}
use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.
the class EmptyGrid method getModel.
public BeanModel getModel() {
BeanModel<Object> model = beanModelSource.createDisplayModel(Object.class, messages);
model.add("random", new PropertyConduit() {
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return null;
}
public void set(Object instance, Object value) {
throw new UnsupportedOperationException();
}
public Class getPropertyType() {
return Long.class;
}
public Type getPropertyGenericType() {
return Long.class;
}
public Object get(Object instance) {
return random.nextLong();
}
});
return model;
}
use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.
the class PersistentFieldBundleImplTest method get_nested_component_value.
@Test
public void get_nested_component_value() {
String value = "FIELD-VALUE";
PersistentFieldChange change = new PersistentFieldChangeImpl("foo.bar", "field", value);
Collection<PersistentFieldChange> changes = Arrays.asList(change);
PersistentFieldBundle bundle = new PersistentFieldBundleImpl(changes);
assertTrue(bundle.containsValue("foo.bar", "field"));
assertSame(bundle.getValue("foo.bar", "field"), value);
assertFalse(bundle.containsValue("foo.bar", "other"));
}
use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.
the class PersistentFieldBundleImplTest method get_root_component_value.
@Test
public void get_root_component_value() {
String value = "FIELD-VALUE";
PersistentFieldChange change = new PersistentFieldChangeImpl("", "field", value);
Collection<PersistentFieldChange> changes = Arrays.asList(change);
PersistentFieldBundle bundle = new PersistentFieldBundleImpl(changes);
assertTrue(bundle.containsValue("", "field"));
assertTrue(bundle.containsValue(null, "field"));
assertSame(bundle.getValue("", "field"), value);
assertSame(bundle.getValue(null, "field"), value);
assertFalse(bundle.containsValue("", "other"));
assertFalse(bundle.containsValue(null, "other"));
}
use of org.apache.tapestry5.ioc.annotations.Value 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();
}
Aggregations