Example usage for javax.xml.datatype XMLGregorianCalendar getEonAndYear

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

Introduction

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

Prototype

public abstract BigInteger getEonAndYear();

Source Link

Document

Returns the 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);//from ww  w  . j  a v a 2 s . com

    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));
}