Search in sources :

Example 6 with FieldTranslatorSource

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();
}
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)

Example 7 with FieldTranslatorSource

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();
}
Also used : FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) ComponentResources(org.apache.tapestry5.ComponentResources) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 8 with FieldTranslatorSource

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();
}
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 9 with FieldTranslatorSource

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();
}
Also used : TranslatorSource(org.apache.tapestry5.services.TranslatorSource) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) Messages(org.apache.tapestry5.commons.Messages) FieldTranslator(org.apache.tapestry5.FieldTranslator) Translator(org.apache.tapestry5.Translator) FieldComponent(org.apache.tapestry5.root.FieldComponent) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) FieldTranslator(org.apache.tapestry5.FieldTranslator) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) MarkupWriter(org.apache.tapestry5.MarkupWriter) FormSupport(org.apache.tapestry5.services.FormSupport) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 10 with FieldTranslatorSource

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();
}
Also used : Binding(org.apache.tapestry5.Binding) StringInternerImpl(org.apache.tapestry5.commons.internal.services.StringInternerImpl) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) FieldTranslator(org.apache.tapestry5.FieldTranslator) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Aggregations

FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)10 Test (org.testng.annotations.Test)10 FieldTranslator (org.apache.tapestry5.FieldTranslator)7 Messages (org.apache.tapestry5.commons.Messages)7 Locale (java.util.Locale)6 Field (org.apache.tapestry5.Field)6 TranslatorSource (org.apache.tapestry5.services.TranslatorSource)6 Map (java.util.Map)5 MarkupWriter (org.apache.tapestry5.MarkupWriter)5 Translator (org.apache.tapestry5.Translator)5 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)5 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)5 FormSupport (org.apache.tapestry5.services.FormSupport)5 ComponentResources (org.apache.tapestry5.ComponentResources)4 ComponentDefaultProvider (org.apache.tapestry5.services.ComponentDefaultProvider)2 Binding (org.apache.tapestry5.Binding)1 Location (org.apache.tapestry5.commons.Location)1 StringInternerImpl (org.apache.tapestry5.commons.internal.services.StringInternerImpl)1 FieldComponent (org.apache.tapestry5.root.FieldComponent)1 BindingFactory (org.apache.tapestry5.services.BindingFactory)1