Search in sources :

Example 6 with AnnotationProvider

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();
}
Also used : Locale(java.util.Locale) Messages(org.apache.tapestry5.commons.Messages) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) FieldTranslator(org.apache.tapestry5.FieldTranslator) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) MarkupWriter(org.apache.tapestry5.MarkupWriter) FormSupport(org.apache.tapestry5.services.FormSupport) TranslatorSource(org.apache.tapestry5.services.TranslatorSource) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) Field(org.apache.tapestry5.Field) FieldTranslator(org.apache.tapestry5.FieldTranslator) Translator(org.apache.tapestry5.Translator) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 7 with AnnotationProvider

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();
}
Also used : Locale(java.util.Locale) Messages(org.apache.tapestry5.commons.Messages) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) FieldTranslator(org.apache.tapestry5.FieldTranslator) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) MarkupWriter(org.apache.tapestry5.MarkupWriter) FormSupport(org.apache.tapestry5.services.FormSupport) TranslatorSource(org.apache.tapestry5.services.TranslatorSource) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) Field(org.apache.tapestry5.Field) FieldTranslator(org.apache.tapestry5.FieldTranslator) Translator(org.apache.tapestry5.Translator) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 8 with AnnotationProvider

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();
}
Also used : ValidationConstraintGenerator(org.apache.tapestry5.services.ValidationConstraintGenerator) Locale(java.util.Locale) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) Field(org.apache.tapestry5.Field) Messages(org.apache.tapestry5.commons.Messages) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) FieldValidator(org.apache.tapestry5.FieldValidator) FieldValidatorDefaultSource(org.apache.tapestry5.services.FieldValidatorDefaultSource) Test(org.testng.annotations.Test)

Example 9 with AnnotationProvider

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();
}
Also used : ValidationConstraintGenerator(org.apache.tapestry5.services.ValidationConstraintGenerator) Locale(java.util.Locale) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) Field(org.apache.tapestry5.Field) Messages(org.apache.tapestry5.commons.Messages) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) FieldValidator(org.apache.tapestry5.FieldValidator) FieldValidatorDefaultSource(org.apache.tapestry5.services.FieldValidatorDefaultSource) Test(org.testng.annotations.Test)

Example 10 with AnnotationProvider

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();
}
Also used : Locale(java.util.Locale) TranslatorSource(org.apache.tapestry5.services.TranslatorSource) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) Field(org.apache.tapestry5.Field) Messages(org.apache.tapestry5.commons.Messages) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)17 Test (org.testng.annotations.Test)13 Messages (org.apache.tapestry5.commons.Messages)10 Locale (java.util.Locale)9 Field (org.apache.tapestry5.Field)9 Map (java.util.Map)7 FieldValidator (org.apache.tapestry5.FieldValidator)6 FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)6 TranslatorSource (org.apache.tapestry5.services.TranslatorSource)6 FieldTranslator (org.apache.tapestry5.FieldTranslator)5 Translator (org.apache.tapestry5.Translator)5 MarkupWriter (org.apache.tapestry5.MarkupWriter)4 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)4 ObjectLocator (org.apache.tapestry5.commons.ObjectLocator)4 ObjectProvider (org.apache.tapestry5.commons.ObjectProvider)4 FieldValidatorDefaultSource (org.apache.tapestry5.services.FieldValidatorDefaultSource)4 Asset (org.apache.tapestry5.Asset)3 NullAnnotationProvider (org.apache.tapestry5.commons.internal.NullAnnotationProvider)3 MasterObjectProvider (org.apache.tapestry5.ioc.services.MasterObjectProvider)3 FormSupport (org.apache.tapestry5.services.FormSupport)3