Search in sources :

Example 26 with Converter

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

the class CalenderConverterFactoryTest method testConversionFixDate.

@Test
public void testConversionFixDate() throws ValueConverterException {
    CalendarConverterFactory factory = new CalendarConverterFactory();
    Converter converter = factory.getConverterForType(Calendar.class);
    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.set(2017, 2, 3, 4, 5, 6);
    Object converted = converter.convertToDolphin(calendar);
    Assert.assertNotNull(converted);
    Assert.assertEquals(((Calendar) converter.convertFromDolphin(converted)).getTime(), calendar.getTime());
}
Also used : CalendarConverterFactory(com.canoo.dp.impl.remoting.converters.CalendarConverterFactory) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Converter(com.canoo.platform.remoting.spi.converter.Converter) Test(org.testng.annotations.Test)

Example 27 with Converter

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

the class CalenderConverterFactoryTest method testConversionCurrentDate.

@Test
public void testConversionCurrentDate() throws ValueConverterException {
    CalendarConverterFactory factory = new CalendarConverterFactory();
    Converter converter = factory.getConverterForType(Calendar.class);
    Calendar calendar = GregorianCalendar.getInstance();
    Object converted = converter.convertToDolphin(calendar);
    Assert.assertNotNull(converted);
    Assert.assertEquals(((Calendar) converter.convertFromDolphin(converted)).getTime(), calendar.getTime());
}
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 28 with Converter

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

the class CalenderConverterFactoryTest method testFromDolphinConversionFixDate.

@Test
public void testFromDolphinConversionFixDate() 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;
    Assert.assertEquals(calendar.getTimeZone(), TimeZone.getTimeZone("UTC"));
    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), 3);
    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 29 with Converter

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

the class CalenderConverterFactoryTest method testToDolphinConversionFixDate.

@Test
public void testToDolphinConversionFixDate() throws ValueConverterException {
    CalendarConverterFactory factory = new CalendarConverterFactory();
    Converter converter = factory.getConverterForType(Calendar.class);
    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.set(2017, 2, 3, 4, 5, 6);
    calendar.set(Calendar.MILLISECOND, 0);
    Object converted = converter.convertToDolphin(calendar);
    Assert.assertNotNull(converted);
    Assert.assertTrue(converted instanceof String);
    Assert.assertEquals(converted, "2017-03-03T04:05:06.000Z");
}
Also used : CalendarConverterFactory(com.canoo.dp.impl.remoting.converters.CalendarConverterFactory) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Converter(com.canoo.platform.remoting.spi.converter.Converter) Test(org.testng.annotations.Test)

Example 30 with Converter

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

the class CalenderConverterFactoryTest method testToDolphinConversionFixDateInGmt.

@Test
public void testToDolphinConversionFixDateInGmt() throws ValueConverterException {
    CalendarConverterFactory factory = new CalendarConverterFactory();
    Converter converter = factory.getConverterForType(Calendar.class);
    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT+1"));
    calendar.set(2017, 2, 3, 4, 5, 6);
    calendar.set(Calendar.MILLISECOND, 0);
    Object converted = converter.convertToDolphin(calendar);
    Assert.assertNotNull(converted);
    Assert.assertTrue(converted instanceof String);
    Assert.assertEquals(converted, "2017-03-03T03:05:06.000Z");
}
Also used : CalendarConverterFactory(com.canoo.dp.impl.remoting.converters.CalendarConverterFactory) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) 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