Search in sources :

Example 51 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest 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 52 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapLocalDateToXmlGregorianCalendar.

@ProcessorTest
@WithClasses(LocalDateToXmlGregorianCalendar.class)
public void shouldMapLocalDateToXmlGregorianCalendar() {
    LocalDateBean in = new LocalDateBean();
    LocalDate dt = new LocalDate(2010, 1, 15);
    in.setLocalDate(dt);
    XmlGregorianCalendarBean res = LocalDateToXmlGregorianCalendar.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(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getMinute()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getSecond()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getMillisecond()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getTimezone()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
}
Also used : LocalDateBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateBean) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDate(org.joda.time.LocalDate) XmlGregorianCalendarToLocalDate(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDate) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 53 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class JodaTimeTest method shouldNotMapXmlGregorianCalendarWithoutMinutesToLocalTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToLocalTime.class)
public void shouldNotMapXmlGregorianCalendarWithoutMinutesToLocalTime() 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);
    LocalTimeBean res = XmlGregorianCalendarToLocalTime.INSTANCE.toLocalTimeBean(in);
    assertThat(res.getLocalTime()).isNull();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) 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)

Example 54 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest 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 55 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class DatatypeFactoryTest method testNoConflictsWithOwnDatatypeFactory.

@ProcessorTest
public void testNoConflictsWithOwnDatatypeFactory() throws ParseException {
    DateProperty source1 = new DateProperty();
    source1.setProp(createDate("31-08-1982 10:20:56"));
    CalendarProperty source2 = new CalendarProperty();
    source2.setProp(createCalendar("02.03.1999"));
    XmlGregorianCalendarFactorizedProperty target1 = ToXmlGregCalMapper.INSTANCE.map(source1);
    assertThat(target1).isNotNull();
    assertThat(target1.getProp()).isNotNull();
    assertThat(target1.getProp().toString()).isEqualTo("1982-08-31T10:20:56.000+02:00");
    XmlGregorianCalendarFactorizedProperty target2 = ToXmlGregCalMapper.INSTANCE.map(source2);
    assertThat(target2).isNotNull();
    assertThat(target2.getProp()).isNotNull();
    assertThat(target2.getProp().toString()).isEqualTo("1999-03-02T00:00:00.000+01:00");
}
Also used : CalendarProperty(org.mapstruct.ap.test.builtin.bean.CalendarProperty) XmlGregorianCalendarFactorizedProperty(org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarFactorizedProperty) DateProperty(org.mapstruct.ap.test.builtin.bean.DateProperty) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)314 WithClasses (org.mapstruct.ap.testutil.WithClasses)118 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)51 IssueKey (org.mapstruct.ap.testutil.IssueKey)39 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)22 Date (java.util.Date)16 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 Calendar (java.util.Calendar)13 LocalDateTime (org.joda.time.LocalDateTime)13 CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 PersonDto (org.mapstruct.ap.test.constructor.PersonDto)13 GregorianCalendar (java.util.GregorianCalendar)12 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)12 BigDecimal (java.math.BigDecimal)11 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)11 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)11 DateTime (org.joda.time.DateTime)10