Search in sources :

Example 1 with Converter

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

the class CalenderConverterFactoryTest method testFromDolphinConversionFixDateWithTimeZoneConversion.

@Test
public void testFromDolphinConversionFixDateWithTimeZoneConversion() throws ValueConverterException {
    CalendarConverterFactory factory = new CalendarConverterFactory();
    Converter converter = factory.getConverterForType(Calendar.class);
    String input = "2017-03-03T03:05:06.000Z";
    Object converted = converter.convertFromDolphin(input);
    Assert.assertNotNull(converted);
    Assert.assertTrue(converted instanceof Calendar);
    Calendar calendar = (Calendar) converted;
    calendar.setTimeZone(TimeZone.getTimeZone("GMT+1"));
    Assert.assertEquals(calendar.getTimeZone(), TimeZone.getTimeZone("GMT+1"));
    Assert.assertEquals(calendar.get(Calendar.YEAR), 2017);
    Assert.assertEquals(calendar.get(Calendar.MONTH), 2);
    Assert.assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 3);
    Assert.assertEquals(calendar.get(Calendar.HOUR), 4);
    Assert.assertEquals(calendar.get(Calendar.MINUTE), 5);
    Assert.assertEquals(calendar.get(Calendar.SECOND), 6);
    Assert.assertEquals(calendar.get(Calendar.MILLISECOND), 0);
}
Also used : CalendarConverterFactory(com.canoo.dp.impl.remoting.converters.CalendarConverterFactory) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Converter(com.canoo.platform.remoting.spi.converter.Converter) Test(org.testng.annotations.Test)

Example 2 with Converter

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

the class DateConverterFactoryTest method testConverterCreation.

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

Example 3 with Converter

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

the class DurationConverterFactoryTest method testWrongDolphinValues.

@Test(expectedExceptions = ClassCastException.class)
public void testWrongDolphinValues(@Mocked BeanRepository beanRepository) throws ValueConverterException {
    // Given
    Converters converters = new Converters(beanRepository);
    // When
    Converter converter = converters.getConverter(Duration.class);
    // Then
    converter.convertFromDolphin(7);
}
Also used : Converters(com.canoo.dp.impl.remoting.Converters) Converter(com.canoo.platform.remoting.spi.converter.Converter) Test(org.testng.annotations.Test)

Example 4 with Converter

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

the class DurationConverterFactoryTest method testWrongBeanValues.

@Test(expectedExceptions = ClassCastException.class)
public void testWrongBeanValues(@Mocked BeanRepository beanRepository) throws ValueConverterException {
    // Given
    Converters converters = new Converters(beanRepository);
    // When
    Converter converter = converters.getConverter(Duration.class);
    // Then
    converter.convertToDolphin(7);
}
Also used : Converters(com.canoo.dp.impl.remoting.Converters) Converter(com.canoo.platform.remoting.spi.converter.Converter) Test(org.testng.annotations.Test)

Example 5 with Converter

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

the class DurationConverterFactoryTest method testNullValues.

@Test
public void testNullValues(@Mocked BeanRepository beanRepository) {
    // Given
    Converters converters = new Converters(beanRepository);
    // When
    Converter converter = converters.getConverter(Duration.class);
    // Then
    try {
        assertEquals(converter.convertFromDolphin(null), null);
        assertEquals(converter.convertToDolphin(null), null);
    } catch (ValueConverterException e) {
        fail("Error in conversion");
    }
}
Also used : Converters(com.canoo.dp.impl.remoting.Converters) Converter(com.canoo.platform.remoting.spi.converter.Converter) ValueConverterException(com.canoo.platform.remoting.spi.converter.ValueConverterException) 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