use of org.apache.tapestry5.services.FieldTranslatorSource in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method default_translator.
@Test
public void default_translator() {
ComponentResources resources = mockComponentResources();
FieldTranslator translator = mockFieldTranslator();
FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
train_createDefaultTranslator(source, resources, "object", translator);
replay();
ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, source, null);
assertSame(provider.defaultTranslator("object", resources), translator);
verify();
}
use of org.apache.tapestry5.services.FieldTranslatorSource in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method create_default_translator_with_name_and_null_key.
@Test
public void create_default_translator_with_name_and_null_key() {
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);
Messages globalMessages = mockMessages();
MessageFormatter formatter = mockMessageFormatter();
MarkupWriter writer = mockMarkupWriter();
String label = "Field Label";
String message = "Woops, did it again.";
AnnotationProvider ap = mockAnnotationProvider(null);
train_findByType(ts, propertyType, translator);
train_getFormValidationId(fs, "myform");
train_contains(messages, "myform-myfield-maptrans-message", false);
train_contains(messages, "myfield-maptrans-message", false);
train_getMessageKey(translator, null);
train_getMessageFormatter(globalMessages, "maptrans-message", 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.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_default_translator_with_override_message.
@Test
public void create_default_translator_with_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", false);
train_contains(messages, "myfield-maptrans-message", true);
train_getMessageFormatter(messages, "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_default_property_type_null.
@Test
public void create_default_property_type_null() {
Field field = mockField();
Messages messages = mockMessages();
Locale locale = Locale.ENGLISH;
replay();
FieldTranslatorSource source = new FieldTranslatorSourceImpl(null, null, null);
assertNull(source.createDefaultTranslator(field, "override", messages, locale, null, null));
verify();
}
use of org.apache.tapestry5.services.FieldTranslatorSource in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method create_default_translator_with_name.
@Test
public void create_default_translator_with_name() {
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);
Messages globalMessages = mockMessages();
MessageFormatter formatter = mockMessageFormatter();
MarkupWriter writer = mockMarkupWriter();
String label = "Field Label";
String message = "Woops, did it again.";
AnnotationProvider ap = mockAnnotationProvider(null);
train_findByType(ts, propertyType, translator);
train_getFormValidationId(fs, "myform");
train_contains(messages, "myform-myfield-maptrans-message", false);
train_contains(messages, "myfield-maptrans-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.createDefaultTranslator(field, "myfield", messages, locale, propertyType, ap);
assertEquals(ft.getType(), Map.class);
ft.render(writer);
verify();
}
Aggregations