Search in sources :

Example 6 with CalendarConverterFactory

use of com.canoo.dp.impl.remoting.converters.CalendarConverterFactory 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 7 with CalendarConverterFactory

use of com.canoo.dp.impl.remoting.converters.CalendarConverterFactory 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 8 with CalendarConverterFactory

use of com.canoo.dp.impl.remoting.converters.CalendarConverterFactory 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 9 with CalendarConverterFactory

use of com.canoo.dp.impl.remoting.converters.CalendarConverterFactory 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

CalendarConverterFactory (com.canoo.dp.impl.remoting.converters.CalendarConverterFactory)9 Test (org.testng.annotations.Test)9 GregorianCalendar (java.util.GregorianCalendar)8 Converter (com.canoo.platform.remoting.spi.converter.Converter)7 Calendar (java.util.Calendar)7