Search in sources :

Example 16 with XmlGregorianCalendarBean

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

the class JodaTimeTest method shouldMapXmlGregorianCalendarToLocalDate.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToLocalDate.class)
public void shouldMapXmlGregorianCalendarToLocalDate() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(1999, 5, 25, DatatypeConstants.FIELD_UNDEFINED);
    in.setxMLGregorianCalendar(xcal);
    LocalDateBean res = XmlGregorianCalendarToLocalDate.INSTANCE.toLocalDateBean(in);
    assertThat(res.getLocalDate().getYear()).isEqualTo(1999);
    assertThat(res.getLocalDate().getMonthOfYear()).isEqualTo(5);
    assertThat(res.getLocalDate().getDayOfMonth()).isEqualTo(25);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDateBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 17 with XmlGregorianCalendarBean

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

the class JodaTimeTest method shouldMapXmlGregorianCalendarToDateTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldMapXmlGregorianCalendarToDateTime() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(2010, 1, 15, 1, 1, 1, 100, 60);
    in.setxMLGregorianCalendar(xcal);
    DateTimeBean res = XmlGregorianCalendarToDateTime.INSTANCE.toDateTimeBean(in);
    assertThat(res.getDateTime().getYear()).isEqualTo(2010);
    assertThat(res.getDateTime().getMonthOfYear()).isEqualTo(1);
    assertThat(res.getDateTime().getDayOfMonth()).isEqualTo(15);
    assertThat(res.getDateTime().getHourOfDay()).isEqualTo(1);
    assertThat(res.getDateTime().getMinuteOfHour()).isEqualTo(1);
    assertThat(res.getDateTime().getSecondOfMinute()).isEqualTo(1);
    assertThat(res.getDateTime().getMillisOfSecond()).isEqualTo(100);
    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 18 with XmlGregorianCalendarBean

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

the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutTimeZoneToDateTimeWithDefaultTimeZone.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldMapXmlGregorianCalendarWithoutTimeZoneToDateTimeWithDefaultTimeZone() 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.setSecond(45);
    xcal.setMillisecond(500);
    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(45);
    assertThat(res.getDateTime().getMillisOfSecond()).isEqualTo(500);
    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 19 with XmlGregorianCalendarBean

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

the class JodaTimeTest method shouldNotMapXmlGregorianCalendarWithoutMinutes.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldNotMapXmlGregorianCalendarWithoutMinutes() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    xcal.setYear(1999);
    xcal.setMonth(5);
    xcal.setDay(25);
    xcal.setHour(23);
    in.setxMLGregorianCalendar(xcal);
    DateTimeBean res = XmlGregorianCalendarToDateTime.INSTANCE.toDateTimeBean(in);
    assertThat(res.getDateTime()).isNull();
}
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 20 with XmlGregorianCalendarBean

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

the class JodaTimeTest method shouldMapIncompleteLocalTimeToXmlGregorianCalendar.

@ProcessorTest
@WithClasses(LocalTimeToXmlGregorianCalendar.class)
public void shouldMapIncompleteLocalTimeToXmlGregorianCalendar() {
    LocalTimeBean in = new LocalTimeBean();
    LocalTime dt = new LocalTime(1, 1, 0, 100);
    in.setLocalTime(dt);
    XmlGregorianCalendarBean res = LocalTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(in);
    assertThat(res.getxMLGregorianCalendar().getYear()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getMonth()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getDay()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getHour()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getMinute()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getSecond()).isEqualTo(0);
    assertThat(res.getxMLGregorianCalendar().getMillisecond()).isEqualTo(100);
    assertThat(res.getxMLGregorianCalendar().getTimezone()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
}
Also used : LocalTime(org.joda.time.LocalTime) XmlGregorianCalendarToLocalTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalTime) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)24 WithClasses (org.mapstruct.ap.testutil.WithClasses)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)17 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 DateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean)10 LocalDateTime (org.joda.time.LocalDateTime)5 LocalTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean)5 XmlGregorianCalendarToLocalDateTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime)5 DateTime (org.joda.time.DateTime)3 LocalDateBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateBean)3 XmlGregorianCalendarToDateTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToDateTime)3 LocalDate (org.joda.time.LocalDate)1 LocalTime (org.joda.time.LocalTime)1 XmlGregorianCalendarToLocalDate (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDate)1 XmlGregorianCalendarToLocalTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalTime)1