Search in sources :

Example 1 with Translator

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

Example 2 with Translator

use of org.apache.tapestry5.Translator 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'.");
    }
}
Also used : TranslatorSource(org.apache.tapestry5.services.TranslatorSource) Translator(org.apache.tapestry5.Translator) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) BeforeClass(org.testng.annotations.BeforeClass) Test(org.testng.annotations.Test)

Example 3 with Translator

use of org.apache.tapestry5.Translator 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();
}
Also used : TranslatorSource(org.apache.tapestry5.services.TranslatorSource) Translator(org.apache.tapestry5.Translator) BeforeClass(org.testng.annotations.BeforeClass) Test(org.testng.annotations.Test)

Example 4 with Translator

use of org.apache.tapestry5.Translator 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();
}
Also used : Translator(org.apache.tapestry5.Translator) BeforeClass(org.testng.annotations.BeforeClass) Test(org.testng.annotations.Test)

Example 5 with Translator

use of org.apache.tapestry5.Translator 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();
}
Also used : TranslatorSource(org.apache.tapestry5.services.TranslatorSource) Translator(org.apache.tapestry5.Translator) BeforeClass(org.testng.annotations.BeforeClass) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)20 Translator (org.apache.tapestry5.Translator)19 TranslatorSource (org.apache.tapestry5.services.TranslatorSource)11 FieldTranslator (org.apache.tapestry5.FieldTranslator)9 FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)8 Field (org.apache.tapestry5.Field)6 Map (java.util.Map)5 MarkupWriter (org.apache.tapestry5.MarkupWriter)5 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)5 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)5 Messages (org.apache.tapestry5.commons.Messages)5 FormSupport (org.apache.tapestry5.services.FormSupport)5 BeforeClass (org.testng.annotations.BeforeClass)5 Locale (java.util.Locale)4 BigInteger (java.math.BigInteger)3 ComponentResources (org.apache.tapestry5.ComponentResources)3 BigDecimal (java.math.BigDecimal)1 Binding (org.apache.tapestry5.Binding)1 ValidationException (org.apache.tapestry5.ValidationException)1 Location (org.apache.tapestry5.commons.Location)1