Example usage for javax.xml.datatype XMLGregorianCalendar getEon

List of usage examples for javax.xml.datatype XMLGregorianCalendar getEon

Introduction

In this page you can find the example usage for javax.xml.datatype XMLGregorianCalendar getEon.

Prototype

public abstract BigInteger getEon();

Source Link

Document

Returns the high order component for XML Schema 1.0 dateTime datatype field for year .

Usage

From source file:com.microsoft.exchange.integration.TimeZoneIntegrationTest.java

@Test
public void createGetDeleteCalendarItem() throws DatatypeConfigurationException {

    TimeZone utcTimeZone = TimeZone.getTimeZone(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID);
    TimeZone.setDefault(utcTimeZone);

    ApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:test-contexts/exchangeContext.xml");
    RequestServerTimeZoneInterceptor timeZoneInterceptor = context
            .getBean(RequestServerTimeZoneInterceptor.class);
    ExchangeWebServices ews = context.getBean(ExchangeWebServices.class);
    BaseExchangeCalendarDataDao exchangeCalendarDao = context.getBean(BaseExchangeCalendarDataDao.class);
    exchangeCalendarDao.setWebServices(ews);

    assertEquals(TimeZone.getDefault(), utcTimeZone);

    //XMLGregorianCalendar is sortof backed by a gregorian calendar, date/times should reflect default jvm timezone
    XMLGregorianCalendar xmlStart = DateHelp.getXMLGregorianCalendarNow();

    CalendarItemType calendarItem = new CalendarItemType();
    calendarItem.setStart(xmlStart);//w ww  .j  a  va  2s.  c om

    ItemIdType itemId = exchangeCalendarDao.createCalendarItem(upn, calendarItem);
    assertNotNull(itemId);
    Set<ItemIdType> itemIds = Collections.singleton(itemId);
    Set<CalendarItemType> calendarItems = exchangeCalendarDao.getCalendarItems(upn, itemIds);
    assertNotNull(calendarItems);
    CalendarItemType createdCalendarItem = DataAccessUtils.singleResult(calendarItems);
    assertNotNull(createdCalendarItem);
    XMLGregorianCalendar createdCalendarItemStart = createdCalendarItem.getStart();

    assertNotNull(createdCalendarItemStart);
    assertEquals(xmlStart.getTimezone(), createdCalendarItemStart.getTimezone());

    //nope! tzDisplayName = createdCalendarItem.getTimeZone()
    //assertEquals(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID, createdCalendarItem.getTimeZone());

    assertEquals(xmlStart.getEon(), createdCalendarItemStart.getEon());
    assertEquals(xmlStart.getEonAndYear(), createdCalendarItemStart.getEonAndYear());
    assertEquals(xmlStart.getYear(), createdCalendarItemStart.getYear());
    assertEquals(xmlStart.getMonth(), createdCalendarItemStart.getMonth());
    assertEquals(xmlStart.getDay(), createdCalendarItemStart.getDay());
    assertEquals(xmlStart.getHour(), createdCalendarItemStart.getHour());
    assertEquals(xmlStart.getMinute(), createdCalendarItemStart.getMinute());
    assertEquals(xmlStart.getSecond(), createdCalendarItemStart.getSecond());

    //nope!  always seems to be a slight variation
    //assertEquals(xmlStart.toGregorianCalendar().getTimeInMillis(), createdCalendarItemStart.toGregorianCalendar().getTimeInMillis());
    //assertEquals(xmlStart.getMillisecond(), createdCalendarItemStart.getMillisecond());   
    //assertEquals(xmlStart.getFractionalSecond(), createdCalendarItemStart.getFractionalSecond());

    assertTrue(DateHelp.withinOneSecond(xmlStart, createdCalendarItemStart));

    assertTrue(exchangeCalendarDao.deleteCalendarItems(upn, itemIds));
}