Search in sources :

Example 21 with Converter

use of com.canoo.platform.remoting.spi.converter.Converter in project dolphin-platform by canoo.

the class ConverterTest method testDateConversions.

@Test
public void testDateConversions() {
    Converters converters = new Converters(null);
    Converter converter = converters.getConverter(Date.class);
    Date testDate1 = new Date();
    checkConversion(converter, testDate1);
    Date testDate2 = new Date(0);
    checkConversion(converter, testDate2);
    Date testDate3 = new Date(Long.MAX_VALUE);
    checkConversion(converter, testDate3);
    Date testDate4 = null;
    checkConversion(converter, testDate4);
// TODO: Not working based on date formate (yyyy), max year is 9999
// Date testDate5 = new Date(Long.MIN_VALUE);
}
Also used : Converters(com.canoo.dp.impl.remoting.Converters) Converter(com.canoo.platform.remoting.spi.converter.Converter) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 22 with Converter

use of com.canoo.platform.remoting.spi.converter.Converter in project dolphin-platform by canoo.

the class ClassRepositoryImpl method createClassInfoForClass.

private ClassInfo createClassInfoForClass(final Class<?> beanClass) {
    final List<PropertyInfo> propertyInfos = new ArrayList<>();
    final List<PropertyInfo> observableListInfos = new ArrayList<>();
    for (Field field : ReflectionHelper.getInheritedDeclaredFields(beanClass)) {
        PropertyType type = null;
        if (Property.class.isAssignableFrom(field.getType())) {
            type = PropertyType.PROPERTY;
        } else if (ObservableList.class.isAssignableFrom(field.getType())) {
            type = PropertyType.OBSERVABLE_LIST;
        }
        final Class<?> parameterType = ReflectionHelper.getTypeParameter(field);
        if (type != null && parameterType != null) {
            final String attributeName = DolphinUtils.getDolphinAttributePropertyNameForField(field);
            final Converter converter = converters.getConverter(parameterType);
            final PropertyInfo propertyInfo = new ClassPropertyInfo(attributeName, converter, field);
            if (type == PropertyType.PROPERTY) {
                propertyInfos.add(propertyInfo);
            } else {
                observableListInfos.add(propertyInfo);
            }
        }
    }
    return new ClassInfo(beanClass, propertyInfos, observableListInfos);
}
Also used : Field(java.lang.reflect.Field) ObservableList(com.canoo.platform.remoting.ObservableList) ArrayList(java.util.ArrayList) Converter(com.canoo.platform.remoting.spi.converter.Converter) PropertyInfo(com.canoo.dp.impl.remoting.info.PropertyInfo) ClassInfo(com.canoo.dp.impl.remoting.info.ClassInfo)

Example 23 with Converter

use of com.canoo.platform.remoting.spi.converter.Converter in project dolphin-platform by canoo.

the class ConverterTest method testDoubleConversions.

@Test
public void testDoubleConversions() {
    Converters converters = new Converters(null);
    Converter converter = converters.getConverter(Double.class);
    checkConversion(converter, 2.9d);
    checkConversion(converter, null);
    checkConversion(converter, 0.0);
    checkConversion(converter, Double.MAX_VALUE);
    checkConversion(converter, Double.MIN_VALUE);
}
Also used : Converters(com.canoo.dp.impl.remoting.Converters) Converter(com.canoo.platform.remoting.spi.converter.Converter) Test(org.testng.annotations.Test)

Example 24 with Converter

use of com.canoo.platform.remoting.spi.converter.Converter in project dolphin-platform by canoo.

the class ConverterTest method testStringConversions.

@Test
public void testStringConversions() {
    Converters converters = new Converters(null);
    Converter converter = converters.getConverter(String.class);
    checkConversion(converter, "");
    checkConversion(converter, null);
    checkConversion(converter, "Hello");
}
Also used : Converters(com.canoo.dp.impl.remoting.Converters) Converter(com.canoo.platform.remoting.spi.converter.Converter) Test(org.testng.annotations.Test)

Example 25 with Converter

use of com.canoo.platform.remoting.spi.converter.Converter in project dolphin-platform by canoo.

the class CalenderConverterFactoryTest method testConverterCreation.

@Test
public void testConverterCreation() {
    CalendarConverterFactory factory = new CalendarConverterFactory();
    Converter converter = factory.getConverterForType(Calendar.class);
    Assert.assertNotNull(converter);
    converter = factory.getConverterForType(GregorianCalendar.class);
    Assert.assertNotNull(converter);
}
Also used : CalendarConverterFactory(com.canoo.dp.impl.remoting.converters.CalendarConverterFactory) GregorianCalendar(java.util.GregorianCalendar) Converter(com.canoo.platform.remoting.spi.converter.Converter) Test(org.testng.annotations.Test)

Aggregations

Converter (com.canoo.platform.remoting.spi.converter.Converter)38 Test (org.testng.annotations.Test)37 Converters (com.canoo.dp.impl.remoting.Converters)28 CalendarConverterFactory (com.canoo.dp.impl.remoting.converters.CalendarConverterFactory)7 GregorianCalendar (java.util.GregorianCalendar)7 Calendar (java.util.Calendar)6 ValueConverterException (com.canoo.platform.remoting.spi.converter.ValueConverterException)5 DateConverterFactory (com.canoo.dp.impl.remoting.converters.DateConverterFactory)2 Date (java.util.Date)2 ClassInfo (com.canoo.dp.impl.remoting.info.ClassInfo)1 PropertyInfo (com.canoo.dp.impl.remoting.info.PropertyInfo)1 ObservableList (com.canoo.platform.remoting.ObservableList)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1