@Test
  public void testListCalendarNames() {
    initializeCredentials();
    FindFolder request = constructFindFolderRequest();
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    FindFolderResponse response = ewsClient.findFolder(request);
    String captured = capture(response);
    log.info("testListCalendarNames response: " + captured);
    stopWatch.stop();
    log.debug("FindFolder request completed in " + stopWatch);
    Assert.assertNotNull(response);

    // now generate a Map?
    Map<String, String> msolCalendars = new LinkedHashMap<String, String>();
    ArrayOfResponseMessagesType responses = response.getResponseMessages();
    List<JAXBElement<? extends ResponseMessageType>> responseList =
        responses
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
    // iterate over responses
    for (JAXBElement<? extends ResponseMessageType> rm : responseList) {
      FindFolderResponseMessageType itemType = (FindFolderResponseMessageType) rm.getValue();
      FindFolderParentType rootFolder = itemType.getRootFolder();
      ArrayOfFoldersType folders = rootFolder.getFolders();
      List<BaseFolderType> folderList = folders.getFoldersAndCalendarFoldersAndContactsFolders();
      for (BaseFolderType baseFolder : folderList) {
        String displayName = baseFolder.getDisplayName();
        String folderId = baseFolder.getFolderId().getId();
        String changeKey = baseFolder.getFolderId().getChangeKey();
        log.debug(displayName + "(id=" + folderId + " : changeKey=" + changeKey + " )");
      }
    }
  }
  @Test
  public void getTimeZonesTest() {
    String tzId = "UTC";
    GetServerTimeZones request = new GetServerTimeZones();
    request.setReturnFullTimeZoneData(false);

    NonEmptyArrayOfTimeZoneIdType tzIds = new NonEmptyArrayOfTimeZoneIdType();
    tzIds.getIds().add(tzId);
    request.setIds(tzIds);
    GetServerTimeZonesResponse response = ewsClient.getServerTimeZones(request);

    ArrayOfResponseMessagesType responseMessages = response.getResponseMessages();
    List<JAXBElement<? extends ResponseMessageType>> tzResponseMessages =
        responseMessages
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
    for (JAXBElement<? extends ResponseMessageType> message : tzResponseMessages) {
      ResponseMessageType r = message.getValue();
      GetServerTimeZonesResponseMessageType itemInfo = (GetServerTimeZonesResponseMessageType) r;
      ArrayOfTimeZoneDefinitionType timeZoneDefinitions = itemInfo.getTimeZoneDefinitions();
      List<TimeZoneDefinitionType> timeZoneDefinitionsList =
          timeZoneDefinitions.getTimeZoneDefinitions();
      for (TimeZoneDefinitionType timeZoneDef : timeZoneDefinitionsList) {
        if (tzId.equals(timeZoneDef.getName()) || tzId.equals(timeZoneDef.getId())) {
          assertNotNull(timeZoneDef);
        }
      }
    }
  }
  @Test
  public void testResolveNames() {
    Set<String> addresses = new HashSet<String>();
    initializeCredentials();
    ResolveNames request = new ResolveNames();
    request.setContactDataShape(DefaultShapeNamesType.ALL_PROPERTIES);
    request.setReturnFullContactData(true);
    request.setSearchScope(ResolveNamesSearchScopeType.ACTIVE_DIRECTORY_CONTACTS);
    request.setUnresolvedEntry("ctcudd");

    ResolveNamesResponse response = ewsClient.resolveNames(request);
    ArrayOfResponseMessagesType arrayOfResponseMessages = response.getResponseMessages();
    List<JAXBElement<? extends ResponseMessageType>> responseMessages =
        arrayOfResponseMessages
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
    for (JAXBElement<? extends ResponseMessageType> element : responseMessages) {
      ResolveNamesResponseMessageType rnrmt = (ResolveNamesResponseMessageType) element.getValue();
      ArrayOfResolutionType arrayOfResolutionType = rnrmt.getResolutionSet();
      List<ResolutionType> resolutions = arrayOfResolutionType.getResolutions();
      for (ResolutionType resolution : resolutions) {
        ContactItemType contact = resolution.getContact();
        EmailAddressDictionaryType emailAddresses = contact.getEmailAddresses();
        List<EmailAddressDictionaryEntryType> entries = emailAddresses.getEntries();
        for (EmailAddressDictionaryEntryType entry : entries) {
          String value = entry.getValue();
          if (StringUtils.isNotBlank(value)) {
            value = value.toLowerCase();
            value = StringUtils.removeStartIgnoreCase(value, "smtp:");
            addresses.add(value);
          }
        }
      }
    }
    for (String s : addresses) {
      log.info(s);
    }
  }