use of org.apache.tapestry5.services.FieldTranslatorSource in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method create_default_translator_not_found_for_type.
@Test
public void create_default_translator_not_found_for_type() {
Field field = mockField();
Messages messages = mockMessages();
Locale locale = Locale.ENGLISH;
Class propertyType = Map.class;
TranslatorSource ts = mockTranslatorSource();
AnnotationProvider ap = mockAnnotationProvider(null);
train_findByType(ts, propertyType, null);
replay();
FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, null, null);
assertNull(source.createDefaultTranslator(field, "override", messages, locale, propertyType, ap));
verify();
}
use of org.apache.tapestry5.services.FieldTranslatorSource in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method default_translator_property_type_is_null.
@Test
public void default_translator_property_type_is_null() {
ComponentResources resources = mockComponentResources();
FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
train_createDefaultTranslator(source, resources, "object", null);
replay();
ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, source, null);
assertNull(provider.defaultTranslator("object", resources));
verify();
}
use of org.apache.tapestry5.services.FieldTranslatorSource in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method create_default_translator_with_per_form_override_message.
@Test
public void create_default_translator_with_per_form_override_message() {
Field field = mockField();
Messages messages = mockMessages();
Locale locale = Locale.ENGLISH;
Class propertyType = Map.class;
TranslatorSource ts = mockTranslatorSource();
FormSupport fs = mockFormSupport();
Translator translator = mockTranslator("maptrans", Map.class);
MessageFormatter formatter = mockMessageFormatter();
MarkupWriter writer = mockMarkupWriter();
String label = "My Label";
String message = "Formatted Message";
AnnotationProvider ap = mockAnnotationProvider(null);
train_findByType(ts, propertyType, translator);
train_getFormValidationId(fs, "myform");
train_contains(messages, "myform-myfield-maptrans-message", true);
train_getMessageFormatter(messages, "myform-myfield-maptrans-message", formatter);
train_getLabel(field, label);
train_format(formatter, message, label);
translator.render(field, message, writer, fs);
replay();
FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, null, fs);
FieldTranslator ft = source.createDefaultTranslator(field, "myfield", messages, locale, propertyType, ap);
assertEquals(ft.getType(), Map.class);
ft.render(writer);
verify();
}
use of org.apache.tapestry5.services.FieldTranslatorSource in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method create_translator_from_translator_name.
@Test
public void create_translator_from_translator_name() {
ComponentResources resources = mockComponentResources();
FieldComponent field = mockFieldComponent();
Messages messages = mockMessages();
TranslatorSource ts = mockTranslatorSource();
FormSupport fs = mockFormSupport();
Translator translator = mockTranslator("map", Map.class);
Messages globalMessages = mockMessages();
MessageFormatter formatter = mockMessageFormatter();
MarkupWriter writer = mockMarkupWriter();
String label = "My Label";
String message = "Formatted Message";
train_getComponent(resources, field);
train_getId(resources, "myfield");
train_getContainerMessages(resources, messages);
train_get(ts, "map", translator);
train_getFormValidationId(fs, "myform");
train_contains(messages, "myform-myfield-map-message", false);
train_contains(messages, "myfield-map-message", false);
train_getMessageKey(translator, "mykey");
train_getMessageFormatter(globalMessages, "mykey", formatter);
train_getLabel(field, label);
train_format(formatter, message, label);
translator.render(field, message, writer, fs);
replay();
FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, globalMessages, fs);
FieldTranslator ft = source.createTranslator(resources, "map");
assertEquals(ft.getType(), Map.class);
ft.render(writer);
verify();
}
use of org.apache.tapestry5.services.FieldTranslatorSource in project tapestry-5 by apache.
the class BindingFactoryTest method translate_binding.
@Test
public void translate_binding() {
FieldTranslator translator = mockFieldTranslator();
FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
ComponentResources resources = mockComponentResources();
Location l = mockLocation();
String description = "foo bar";
String expression = "mock";
expect(source.createTranslator(resources, expression)).andReturn(translator);
replay();
BindingFactory factory = new TranslateBindingFactory(source, new StringInternerImpl());
Binding binding = factory.newBinding(description, resources, resources, expression, l);
assertSame(binding.get(), translator);
assertSame(InternalUtils.locationOf(binding), l);
verify();
}
Aggregations