use of com.redhat.cloud.notifications.models.EmailAggregationKey in project notifications-backend by RedHatInsights.
the class EmailSubscriptionTypeProcessorTest method shouldSuccessfullySendEmail.
@Test
void shouldSuccessfullySendEmail() {
micrometerAssertionHelper.saveCounterValuesBeforeTest(AGGREGATION_COMMAND_REJECTED_COUNTER_NAME, AGGREGATION_COMMAND_PROCESSED_COUNTER_NAME, AGGREGATION_COMMAND_ERROR_COUNTER_NAME);
AggregationCommand aggregationCommand1 = new AggregationCommand(new EmailAggregationKey("account-1", "org-1", "bundle-1", "app-1"), LocalDateTime.now(), LocalDateTime.now().plusDays(1), DAILY);
AggregationCommand aggregationCommand2 = new AggregationCommand(new EmailAggregationKey("account-2", "org-2", "bundle-2", "app-2"), LocalDateTime.now(ZoneOffset.UTC).plusDays(1), LocalDateTime.now(ZoneOffset.UTC).plusDays(2), DAILY);
when(emailTemplateFactory.get(anyString(), anyString())).thenReturn(new Blank());
inMemoryConnector.source(AGGREGATION_CHANNEL).send(Json.encode(aggregationCommand1));
inMemoryConnector.source(AGGREGATION_CHANNEL).send(Json.encode(aggregationCommand2));
micrometerAssertionHelper.awaitAndAssertCounterIncrement(AGGREGATION_COMMAND_PROCESSED_COUNTER_NAME, 2);
micrometerAssertionHelper.assertCounterIncrement(AGGREGATION_COMMAND_REJECTED_COUNTER_NAME, 0);
micrometerAssertionHelper.assertCounterIncrement(AGGREGATION_COMMAND_ERROR_COUNTER_NAME, 0);
// Let's check that EndpointEmailSubscriptionResources#sendEmail was called for each aggregation.
verify(emailAggregationRepository, times(1)).getEmailAggregation(eq(aggregationCommand1.getAggregationKey()), eq(aggregationCommand1.getStart()), eq(aggregationCommand1.getEnd()));
verify(emailAggregationRepository, times(1)).purgeOldAggregation(eq(aggregationCommand1.getAggregationKey()), eq(aggregationCommand1.getEnd()));
verify(emailAggregationRepository, times(1)).getEmailAggregation(eq(aggregationCommand2.getAggregationKey()), eq(aggregationCommand2.getStart()), eq(aggregationCommand2.getEnd()));
verify(emailAggregationRepository, times(1)).purgeOldAggregation(eq(aggregationCommand2.getAggregationKey()), eq(aggregationCommand2.getEnd()));
verifyNoMoreInteractions(emailAggregationRepository);
micrometerAssertionHelper.clearSavedValues();
}
use of com.redhat.cloud.notifications.models.EmailAggregationKey in project notifications-backend by RedHatInsights.
the class EmailAggregationRepositoryTest method testAllMethodsWithOrgIdDisabled.
// TODO NOTIF-603 Remove when switching to orgId
@Test
void testAllMethodsWithOrgIdDisabled() {
LocalDateTime start = LocalDateTime.now(UTC).minusHours(1L);
LocalDateTime end = LocalDateTime.now(UTC).plusHours(1L);
EmailAggregationKey key = new EmailAggregationKey(ACCOUNT_ID, ORG_ID, BUNDLE_NAME, APP_NAME);
statelessSessionFactory.withSession(statelessSession -> {
clearEmailAggregations();
resourceHelpers.addEmailAggregation(ACCOUNT_ID, BUNDLE_NAME, APP_NAME, PAYLOAD1);
resourceHelpers.addEmailAggregation(ACCOUNT_ID, BUNDLE_NAME, APP_NAME, PAYLOAD2);
resourceHelpers.addEmailAggregation("other-account", ORG_ID, BUNDLE_NAME, APP_NAME, PAYLOAD2);
resourceHelpers.addEmailAggregation(ACCOUNT_ID, "other-bundle", APP_NAME, PAYLOAD2);
resourceHelpers.addEmailAggregation(ACCOUNT_ID, BUNDLE_NAME, "other-app", PAYLOAD2);
List<EmailAggregation> aggregations = emailAggregationRepository.getEmailAggregation(key, start, end);
assertEquals(2, aggregations.size());
assertNull(aggregations.get(0).getOrgId());
assertNull(aggregations.get(1).getOrgId());
assertTrue(aggregations.stream().map(EmailAggregation::getAccountId).allMatch(ACCOUNT_ID::equals));
assertTrue(aggregations.stream().map(EmailAggregation::getBundleName).allMatch(BUNDLE_NAME::equals));
assertTrue(aggregations.stream().map(EmailAggregation::getApplicationName).allMatch(APP_NAME::equals));
assertEquals(1, aggregations.stream().map(EmailAggregation::getPayload).filter(PAYLOAD1::equals).count());
assertEquals(1, aggregations.stream().map(EmailAggregation::getPayload).filter(PAYLOAD2::equals).count());
List<EmailAggregationKey> keys = getApplicationsWithPendingAggregation(start, end);
assertEquals(4, keys.size());
assertEquals(ACCOUNT_ID, keys.get(0).getAccountId());
assertEquals(BUNDLE_NAME, keys.get(0).getBundle());
assertEquals(APP_NAME, keys.get(0).getApplication());
assertEquals(2, emailAggregationRepository.purgeOldAggregation(key, end));
assertEquals(0, emailAggregationRepository.getEmailAggregation(key, start, end).size());
assertEquals(3, getApplicationsWithPendingAggregation(start, end).size());
clearEmailAggregations();
});
}
Aggregations