org.apache.james.util.date.ZonedDateTimeProvider类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(13.6k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.apache.james.util.date.ZonedDateTimeProvider类的一些代码示例,展示了ZonedDateTimeProvider类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTimeProvider类的具体详情如下:
包路径:org.apache.james.util.date.ZonedDateTimeProvider
类名称:ZonedDateTimeProvider

ZonedDateTimeProvider介绍

暂无

代码示例

代码示例来源:origin: org.apache.james/james-server-data-jmap

@Override
public CompletableFuture<Boolean> isRegistered(AccountId accountId, RecipientId recipientId) {
  ZonedDateTime currentTime = zonedDateTimeProvider.get();
  return CompletableFuture.completedFuture(
    registrations.get(accountId)
      .stream()
      .filter(entry -> entry.getRecipientId().equals(recipientId))
      .map(Entry::getExpiryDate)
      .findAny()
      .filter(optional -> optional.map(registrationEnd -> isStrictlyBefore(currentTime, registrationEnd)).orElse(true))
      .isPresent());
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Override
public ContinuationToken generateContinuationToken(String username) {
  Preconditions.checkNotNull(username);
  ZonedDateTime expirationTime = zonedDateTimeProvider.get().plusMinutes(15);
  return new ContinuationToken(username,
    expirationTime,
    signatureHandler.sign(
        Joiner.on(ContinuationToken.SEPARATOR)
          .join(username,
            DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(expirationTime))));
}

代码示例来源:origin: org.apache.james/james-server-jmap

private boolean isExpired(SignedExpiringToken token) {
    return token.getExpirationDate().isBefore(zonedDateTimeProvider.get());
  }
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Override
public void service(Mail mail) {
  try {
    if (!mail.hasSender()) {
      return;
    }
    if (! automaticallySentMailDetector.isAutomaticallySent(mail)) {
      ZonedDateTime processingDate = zonedDateTimeProvider.get();
      mail.getRecipients()
        .stream()
        .map(mailAddress -> manageVacation(mailAddress, mail, processingDate))
        .forEach(CompletableFuture::join);
    }
  } catch (Throwable e) {
    LOGGER.warn("Can not process vacation for one or more recipients in {}", mail.getRecipients(), e);
  }
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Override
  public AttachmentAccessToken generateAttachmentAccessToken(String username, String blobId) {
    Preconditions.checkArgument(! Strings.isNullOrEmpty(blobId));
    ZonedDateTime expirationTime = zonedDateTimeProvider.get().plusMinutes(5);
    return AttachmentAccessToken.builder()
        .username(username)
        .blobId(blobId)
        .expirationDate(expirationTime)
        .signature(signatureHandler.sign(Joiner.on(AttachmentAccessToken.SEPARATOR)
                          .join(blobId,
                              username, 
                              DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(expirationTime))))
        .build();
  }
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void serviceShouldNotSendNotificationUponErrorsRetrievingVacationObject() throws Exception {
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
    .thenReturn(CompletableFuture.supplyAsync(() -> {
      throw new RuntimeException();
    }));
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  when(automaticallySentMailDetector.isAutomaticallySent(mail)).thenReturn(false);
  testee.service(mail);
  verifyNoMoreInteractions(mailetContext);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void activateVacationShouldNotSendNotificationIfAlreadySent() throws Exception {
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
    .thenReturn(CompletableFuture.completedFuture(VACATION));
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  when(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId))
    .thenReturn(CompletableFuture.completedFuture(true));
  testee.service(mail);
  verifyNoMoreInteractions(mailetContext);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void activateVacationShouldNotSendNotificationToMailingList() throws Exception {
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  when(automaticallySentMailDetector.isAutomaticallySent(mail)).thenReturn(true);
  testee.service(mail);
  verifyNoMoreInteractions(mailetContext);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void activateVacationShouldSendNotificationIfErrorRetrievingNotificationRepository() throws Exception {
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
    .thenReturn(CompletableFuture.completedFuture(VACATION));
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  RecipientId recipientId = RecipientId.fromMailAddress(originalSender);
  when(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId))
    .thenThrow(new RuntimeException());
  testee.service(mail);
  verifyNoMoreInteractions(mailetContext);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void serviceShouldNotSendNotificationUponErrorsDetectingAutomaticallySentMails() throws Exception {
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
    .thenReturn(CompletableFuture.completedFuture(VACATION));
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  when(automaticallySentMailDetector.isAutomaticallySent(mail)).thenThrow(new MessagingException());
  testee.service(mail);
  verifyNoMoreInteractions(mailetContext);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Before
public void setUp() {
  zonedDateTimeProvider = mock(ZonedDateTimeProvider.class);
  vacationRepository = mock(VacationRepository.class);
  mailboxSession = mock(MailboxSession.class);
  user = mock(MailboxSession.User.class);
  testee = new GetVacationResponseMethod(vacationRepository, zonedDateTimeProvider, new DefaultMetricFactory());
  when(zonedDateTimeProvider.get()).thenReturn(DATE_2014);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void unactivatedVacationShouldNotSendNotification() throws Exception {
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
    .thenReturn(CompletableFuture.completedFuture(VacationRepository.DEFAULT_VACATION));
  when(automaticallySentMailDetector.isAutomaticallySent(mail)).thenReturn(false);
  testee.service(mail);
  verifyNoMoreInteractions(mailetContext);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void activateVacationShouldSendNotification() throws Exception {
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
    .thenReturn(CompletableFuture.completedFuture(VACATION));
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  when(automaticallySentMailDetector.isAutomaticallySent(mail)).thenReturn(false);
  when(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId))
    .thenReturn(CompletableFuture.completedFuture(false));
  testee.service(mail);
  verify(mailetContext).sendMail(eq(originalRecipient), eq(ImmutableList.of(originalSender)), any());
  verify(notificationRegistry).isRegistered(ACCOUNT_ID, recipientId);
  verify(notificationRegistry).register(ACCOUNT_ID, recipientId, Optional.of(DATE_TIME_2018));
  verifyNoMoreInteractions(mailetContext, notificationRegistry);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void activateVacationShouldSendNotificationIfErrorUpdatingNotificationRepository() throws Exception {
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
    .thenReturn(CompletableFuture.completedFuture(VACATION));
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  RecipientId recipientId = RecipientId.fromMailAddress(originalSender);
  when(notificationRegistry.isRegistered(ACCOUNT_ID, recipientId))
    .thenReturn(CompletableFuture.completedFuture(false));
  when(notificationRegistry.register(ACCOUNT_ID, recipientId, Optional.of(DATE_TIME_2018))).thenThrow(new RuntimeException());
  testee.service(mail);
  verify(mailetContext).sendMail(eq(originalRecipient), eq(ImmutableList.of(originalSender)), any());
  verifyNoMoreInteractions(mailetContext);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void serviceShouldNotPropagateExceptionIfSendFails() throws Exception {
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
    .thenReturn(CompletableFuture.completedFuture(VACATION));
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  when(automaticallySentMailDetector.isAutomaticallySent(mail)).thenReturn(false);
  when(notificationRegistry.isRegistered(ACCOUNT_ID, RecipientId.fromMailAddress(originalSender)))
    .thenReturn(CompletableFuture.completedFuture(false));
  doThrow(new MessagingException()).when(mailetContext).sendMail(eq(originalSender), eq(ImmutableList.of(originalRecipient)), any());
  testee.service(mail);
  verify(mailetContext).sendMail(eq(originalRecipient), eq(ImmutableList.of(originalSender)), any());
  verifyNoMoreInteractions(mailetContext);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void multipleRecipientShouldGenerateNotifications() throws MessagingException {
  String secondUserName = "default@any.com";
  MailAddress secondRecipient = new MailAddress(secondUserName);
  AccountId secondAccountId = AccountId.fromString(secondUserName);
  FakeMail mail = FakeMail.builder()
    .fileName("spamMail.eml")
    .recipients(originalRecipient, secondRecipient)
    .sender(originalSender)
    .build();
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME)))
    .thenReturn(CompletableFuture.completedFuture(VACATION));
  when(vacationRepository.retrieveVacation(secondAccountId))
    .thenReturn(CompletableFuture.completedFuture(VACATION));
  when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017);
  when(automaticallySentMailDetector.isAutomaticallySent(mail)).thenReturn(false);
  when(notificationRegistry.isRegistered(ACCOUNT_ID, RecipientId.fromMailAddress(originalSender)))
    .thenReturn(CompletableFuture.completedFuture(false));
  when(notificationRegistry.isRegistered(secondAccountId, RecipientId.fromMailAddress(originalSender)))
    .thenReturn(CompletableFuture.completedFuture(false));
  when(notificationRegistry.register(any(), any(), any()))
    .thenReturn(CompletableFuture.completedFuture(null));
  testee.service(mail);
  verify(mailetContext).sendMail(eq(originalRecipient), eq(ImmutableList.of(originalSender)), any());
  verify(mailetContext).sendMail(eq(secondRecipient), eq(ImmutableList.of(originalSender)), any());
  verifyNoMoreInteractions(mailetContext);
}

代码示例来源:origin: org.apache.james/james-server-jmap

private GetVacationResponse process(MailboxSession mailboxSession) {
    Vacation vacation = vacationRepository.retrieveVacation(AccountId.fromString(mailboxSession.getUser().getUserName())).join();
    return GetVacationResponse.builder()
      .accountId(mailboxSession.getUser().getUserName())
      .vacationResponse(VacationResponse.builder()
        .fromVacation(vacation)
        .activated(vacation.isActiveAtDate(zonedDateTimeProvider.get()))
        .build())
      .build();
  }
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void processShouldReturnUnActivatedVacationResponseWhenAfterDate() {
  ClientId clientId = mock(ClientId.class);
  Vacation vacation = Vacation.builder()
    .enabled(true)
    .textBody("I am in vacation")
    .subject(Optional.of("subject"))
    .fromDate(Optional.of(DATE_2014))
    .toDate(Optional.of(DATE_2015))
    .build();
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME))).thenReturn(CompletableFuture.completedFuture(vacation));
  when(mailboxSession.getUser()).thenReturn(user);
  when(user.getUserName()).thenReturn(USERNAME);
  when(zonedDateTimeProvider.get()).thenReturn(DATE_2016);
  GetVacationRequest getVacationRequest = GetVacationRequest.builder().build();
  Stream<JmapResponse> result = testee.process(getVacationRequest, clientId, mailboxSession);
  JmapResponse expected = JmapResponse.builder()
    .clientId(clientId)
    .responseName(GetVacationResponseMethod.RESPONSE_NAME)
    .response(GetVacationResponse.builder()
      .accountId(USERNAME)
      .vacationResponse(VacationResponse.builder()
        .fromVacation(vacation)
        .activated(false)
        .build())
      .build())
    .build();
  assertThat(result).containsExactly(expected);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void processShouldReturnTheAppropriateVacationResponse() {
  ClientId clientId = mock(ClientId.class);
  Vacation vacation = Vacation.builder()
    .enabled(true)
    .textBody("I am in vacation")
    .subject(Optional.of("subject"))
    .fromDate(Optional.of(DATE_2014))
    .toDate(Optional.of(DATE_2016))
    .build();
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME))).thenReturn(CompletableFuture.completedFuture(vacation));
  when(mailboxSession.getUser()).thenReturn(user);
  when(user.getUserName()).thenReturn(USERNAME);
  when(zonedDateTimeProvider.get()).thenReturn(DATE_2015);
  GetVacationRequest getVacationRequest = GetVacationRequest.builder().build();
  Stream<JmapResponse> result = testee.process(getVacationRequest, clientId, mailboxSession);
  JmapResponse expected = JmapResponse.builder()
    .clientId(clientId)
    .responseName(GetVacationResponseMethod.RESPONSE_NAME)
    .response(GetVacationResponse.builder()
      .accountId(USERNAME)
      .vacationResponse(VacationResponse.builder()
        .fromVacation(vacation)
        .activated(true)
        .build())
      .build())
    .build();
  assertThat(result).containsExactly(expected);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void processShouldReturnUnActivatedVacationResponseWhenBeforeDate() {
  ClientId clientId = mock(ClientId.class);
  Vacation vacation = Vacation.builder()
    .enabled(true)
    .textBody("I am in vacation")
    .subject(Optional.of("subject"))
    .fromDate(Optional.of(DATE_2015))
    .toDate(Optional.of(DATE_2016))
    .build();
  when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME))).thenReturn(CompletableFuture.completedFuture(vacation));
  when(mailboxSession.getUser()).thenReturn(user);
  when(user.getUserName()).thenReturn(USERNAME);
  when(zonedDateTimeProvider.get()).thenReturn(DATE_2014);
  GetVacationRequest getVacationRequest = GetVacationRequest.builder().build();
  Stream<JmapResponse> result = testee.process(getVacationRequest, clientId, mailboxSession);
  JmapResponse expected = JmapResponse.builder()
    .clientId(clientId)
    .responseName(GetVacationResponseMethod.RESPONSE_NAME)
    .response(GetVacationResponse.builder()
      .accountId(USERNAME)
      .vacationResponse(VacationResponse.builder()
        .fromVacation(vacation)
        .activated(false)
        .build())
      .build())
    .build();
  assertThat(result).containsExactly(expected);
}

相关文章

ZonedDateTimeProvider类方法