use of org.apache.tapestry5.commons.AnnotationProvider 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.commons.AnnotationProvider 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();
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class FieldValidatorDefaultSourceImplTest method invokes_all_constraint_generators.
@SuppressWarnings("unchecked")
@Test
public void invokes_all_constraint_generators() throws Exception {
getMocksControl().checkOrder(true);
ValidationConstraintGenerator gen = mockValidationConstraintGenerator();
FieldValidator fv1 = mockFieldValidator();
FieldValidator fv2 = mockFieldValidator();
FieldValidatorSource source = mockFieldValidatorSource();
Class propertyType = Integer.class;
AnnotationProvider provider = mockAnnotationProvider();
String overrideId = "overrideId";
Messages overrideMessages = mockMessages();
Field field = mockField();
Locale locale = Locale.ENGLISH;
String value = "*VALUE*";
train_buildConstraints(gen, propertyType, provider, "cons1", "cons2");
train_createValidator(source, field, "cons1", null, overrideId, overrideMessages, locale, fv1);
train_createValidator(source, field, "cons2", null, overrideId, overrideMessages, locale, fv2);
fv1.validate(value);
fv2.validate(value);
replay();
FieldValidatorDefaultSource fieldValidatorSource = new FieldValidatorDefaultSourceImpl(gen, source);
FieldValidator composite = fieldValidatorSource.createDefaultValidator(field, overrideId, overrideMessages, locale, propertyType, provider);
composite.validate(value);
verify();
}
use of org.apache.tapestry5.commons.AnnotationProvider in project tapestry-5 by apache.
the class FieldValidatorDefaultSourceImplTest method validator_with_constraint.
@SuppressWarnings("unchecked")
@Test
public void validator_with_constraint() throws Exception {
ValidationConstraintGenerator gen = mockValidationConstraintGenerator();
FieldValidator fv = mockFieldValidator();
FieldValidatorSource source = mockFieldValidatorSource();
Class propertyType = Integer.class;
AnnotationProvider provider = mockAnnotationProvider();
String overrideId = "overrideId";
Messages overrideMessages = mockMessages();
Field field = mockField();
Locale locale = Locale.ENGLISH;
train_buildConstraints(gen, propertyType, provider, "foo=bar");
train_createValidator(source, field, "foo", "bar", overrideId, overrideMessages, locale, fv);
replay();
FieldValidatorDefaultSource fieldValidatorSource = new FieldValidatorDefaultSourceImpl(gen, source);
FieldValidator composite = fieldValidatorSource.createDefaultValidator(field, overrideId, overrideMessages, locale, propertyType, provider);
assertSame(composite, fv);
verify();
}
use of org.apache.tapestry5.commons.AnnotationProvider 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();
}
Aggregations