Search in sources :

Example 1 with DateTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutSecondsAndTimeZoneToDateTimeWithDefaultTimeZone.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldMapXmlGregorianCalendarWithoutSecondsAndTimeZoneToDateTimeWithDefaultTimeZone() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    xcal.setYear(1999);
    xcal.setMonth(5);
    xcal.setDay(25);
    xcal.setHour(23);
    xcal.setMinute(34);
    in.setxMLGregorianCalendar(xcal);
    DateTimeBean res = XmlGregorianCalendarToDateTime.INSTANCE.toDateTimeBean(in);
    assertThat(res.getDateTime().getYear()).isEqualTo(1999);
    assertThat(res.getDateTime().getMonthOfYear()).isEqualTo(5);
    assertThat(res.getDateTime().getDayOfMonth()).isEqualTo(25);
    assertThat(res.getDateTime().getHourOfDay()).isEqualTo(23);
    assertThat(res.getDateTime().getMinuteOfHour()).isEqualTo(34);
    assertThat(res.getDateTime().getSecondOfMinute()).isEqualTo(0);
    assertThat(res.getDateTime().getMillisOfSecond()).isEqualTo(0);
    assertThat(res.getDateTime().getZone().getOffset(0)).isEqualTo(DateTimeZone.getDefault().getOffset(0));
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean) DateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 2 with DateTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapIncompleteDateTimeToXmlGregorianCalendar.

@ProcessorTest
@WithClasses(DateTimeToXmlGregorianCalendar.class)
public void shouldMapIncompleteDateTimeToXmlGregorianCalendar() {
    DateTimeBean in = new DateTimeBean();
    DateTime dt = new DateTime(2010, 1, 15, 1, 1);
    in.setDateTime(dt);
    XmlGregorianCalendarBean res = DateTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(in);
    assertThat(res.getxMLGregorianCalendar().getYear()).isEqualTo(2010);
    assertThat(res.getxMLGregorianCalendar().getMonth()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getDay()).isEqualTo(15);
    assertThat(res.getxMLGregorianCalendar().getHour()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getMinute()).isEqualTo(1);
}
Also used : XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean) DateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean) XmlGregorianCalendarToDateTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToDateTime) XmlGregorianCalendarToLocalDateTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 3 with DateTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapDateTimeToXmlGregorianCalendar.

@ProcessorTest
@WithClasses(DateTimeToXmlGregorianCalendar.class)
public void shouldMapDateTimeToXmlGregorianCalendar() {
    DateTimeBean in = new DateTimeBean();
    DateTime dt = new DateTime(2010, 1, 15, 1, 1, 1, 100, DateTimeZone.forOffsetHours(-1));
    in.setDateTime(dt);
    XmlGregorianCalendarBean res = DateTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(in);
    assertThat(res.getxMLGregorianCalendar().getYear()).isEqualTo(2010);
    assertThat(res.getxMLGregorianCalendar().getMonth()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getDay()).isEqualTo(15);
    assertThat(res.getxMLGregorianCalendar().getHour()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getMinute()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getSecond()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getMillisecond()).isEqualTo(100);
    assertThat(res.getxMLGregorianCalendar().getTimezone()).isEqualTo(-60);
}
Also used : XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean) DateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean) XmlGregorianCalendarToDateTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToDateTime) XmlGregorianCalendarToLocalDateTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 4 with DateTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutSecondsToDateTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldMapXmlGregorianCalendarWithoutSecondsToDateTime() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    xcal.setYear(1999);
    xcal.setMonth(5);
    xcal.setDay(25);
    xcal.setHour(23);
    xcal.setMinute(34);
    xcal.setTimezone(60);
    in.setxMLGregorianCalendar(xcal);
    DateTimeBean res = XmlGregorianCalendarToDateTime.INSTANCE.toDateTimeBean(in);
    assertThat(res.getDateTime().getYear()).isEqualTo(1999);
    assertThat(res.getDateTime().getMonthOfYear()).isEqualTo(5);
    assertThat(res.getDateTime().getDayOfMonth()).isEqualTo(25);
    assertThat(res.getDateTime().getHourOfDay()).isEqualTo(23);
    assertThat(res.getDateTime().getMinuteOfHour()).isEqualTo(34);
    assertThat(res.getDateTime().getSecondOfMinute()).isEqualTo(0);
    assertThat(res.getDateTime().getMillisOfSecond()).isEqualTo(0);
    assertThat(res.getDateTime().getZone().getOffset(null)).isEqualTo(3600000);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean) DateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 5 with DateTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapRoundTrip.

@ProcessorTest
@WithClasses({ DateTimeToXmlGregorianCalendar.class, XmlGregorianCalendarToDateTime.class })
public void shouldMapRoundTrip() {
    DateTimeBean dtb1 = new DateTimeBean();
    DateTime dt = new DateTime(2010, 1, 15, 1, 1, 1, 100, DateTimeZone.forOffsetHours(-1));
    dtb1.setDateTime(dt);
    XmlGregorianCalendarBean xcb1 = DateTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(dtb1);
    DateTimeBean dtb2 = XmlGregorianCalendarToDateTime.INSTANCE.toDateTimeBean(xcb1);
    XmlGregorianCalendarBean xcb2 = DateTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(dtb2);
    assertThat(dtb1.getDateTime()).isEqualTo(dtb2.getDateTime());
    assertThat(xcb1.getxMLGregorianCalendar()).isEqualTo(xcb2.getxMLGregorianCalendar());
}
Also used : XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean) DateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean) XmlGregorianCalendarToDateTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToDateTime) XmlGregorianCalendarToLocalDateTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

DateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean)10 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)10 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)10 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)10 WithClasses (org.mapstruct.ap.testutil.WithClasses)10 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)7 DateTime (org.joda.time.DateTime)3 LocalDateTime (org.joda.time.LocalDateTime)3 XmlGregorianCalendarToDateTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToDateTime)3 XmlGregorianCalendarToLocalDateTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime)3