use of org.apache.tapestry5.services.TranslatorSource in project tapestry-5 by apache.
the class TranslatorSourceImplTest method unknown_translator_is_failure.
@Test
public void unknown_translator_is_failure() {
Translator fred = mockTranslator("fred", String.class);
Translator barney = mockTranslator("barney", Long.class);
Map<Class, Translator> configuration = CollectionFactory.newMap();
configuration.put(String.class, fred);
configuration.put(Long.class, barney);
replay();
TranslatorSource source = new TranslatorSourceImpl(configuration);
try {
source.get("wilma");
unreachable();
} catch (UnknownValueException ex) {
assertMessageContains(ex, "Unknown translator type 'wilma'.");
}
}
use of org.apache.tapestry5.services.TranslatorSource in project tapestry-5 by apache.
the class TranslatorSourceImplTest method get_by_type_not_found.
@Test
public void get_by_type_not_found() {
Translator string = mockTranslator("string", String.class);
Translator bool = mockTranslator("bool", Boolean.class);
Map<Class, Translator> configuration = CollectionFactory.newMap();
configuration.put(String.class, string);
configuration.put(Boolean.class, bool);
replay();
TranslatorSource source = new TranslatorSourceImpl(configuration);
try {
source.getByType(Integer.class);
unreachable();
} catch (IllegalArgumentException ex) {
assertEquals(ex.getMessage(), "No translator is defined for type java.lang.Integer. Registered types: java.lang.Boolean, java.lang.String.");
}
verify();
}
use of org.apache.tapestry5.services.TranslatorSource in project tapestry-5 by apache.
the class TranslatorSourceImplTest method name_collision_with_standard_translators.
@Test
public void name_collision_with_standard_translators() {
Translator t1 = mockTranslator("fred", Integer.class);
Translator t2 = mockTranslator("fred", Long.class);
Map<Class, Translator> configuration = CollectionFactory.newMap();
configuration.put(Integer.class, t1);
configuration.put(Long.class, t2);
replay();
try {
new TranslatorSourceImpl(configuration);
unreachable();
} catch (RuntimeException ex) {
assertMessageContains(ex, "Two different Translators contributed to the TranslatorSource service use the same translator name: 'fred'.", "Translator names must be unique.");
}
verify();
}
use of org.apache.tapestry5.services.TranslatorSource in project tapestry-5 by apache.
the class TranslatorSourceImplTest method get_alternate_translator_by_name.
@Test
public void get_alternate_translator_by_name() {
Translator t1 = mockTranslator("fred", Integer.class);
Translator t2 = mockTranslator();
Map<Class, Translator> configuration = newConfiguration(Integer.class, t1);
Map<String, Translator> alternates = CollectionFactory.newMap();
alternates.put("barney", t2);
replay();
TranslatorSource source = new TranslatorSourceImpl(configuration, alternates);
assertSame(source.get("barney"), t2);
verify();
}
use of org.apache.tapestry5.services.TranslatorSource 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();
}
Aggregations