use of io.gravitee.rest.api.model.key.ApiKeyQuery in project gravitee-management-rest-api by gravitee-io.
the class ScheduledSubscriptionPreExpirationNotificationServiceTest method shouldFindApiKeyExpirationsToNotify.
@Test
public void shouldFindApiKeyExpirationsToNotify() {
Instant now = Instant.ofEpochMilli(1469022010000L);
Integer daysBeforeNotification = 10;
ApiKeyEntity apiKey = mock(ApiKeyEntity.class);
when(apiKeyService.search(any(ApiKeyQuery.class))).thenReturn(Collections.singletonList(apiKey));
Collection<ApiKeyEntity> apiKeysToNotify = service.findApiKeyExpirationsToNotify(now, daysBeforeNotification);
assertEquals(Collections.singletonList(apiKey), apiKeysToNotify);
verify(apiKeyService, times(1)).search(argThat(apiKeyQuery -> !apiKeyQuery.isIncludeRevoked() && // 1469886010000 -> now + 10 days
apiKeyQuery.getExpireAfter() == 1469886010000L && // 1469889610000 -> now + 10 days + 1h (cron period)
apiKeyQuery.getExpireBefore() == 1469889610000L));
}
use of io.gravitee.rest.api.model.key.ApiKeyQuery in project gravitee-management-rest-api by gravitee-io.
the class ScheduledSubscriptionPreExpirationNotificationService method findApiKeyExpirationsToNotify.
@VisibleForTesting
Collection<ApiKeyEntity> findApiKeyExpirationsToNotify(Instant now, Integer daysToExpiration) {
long expirationStartingTime = now.plus(Duration.ofDays((long) daysToExpiration)).getEpochSecond() * 1000;
ApiKeyQuery query = new ApiKeyQuery();
query.setIncludeRevoked(false);
query.setExpireAfter(expirationStartingTime);
query.setExpireBefore(expirationStartingTime + cronPeriodInMs);
return apiKeyService.search(query);
}
Aggregations