use of com.synopsys.integration.alert.database.notification.NotificationContentRepository in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method findByCreatedAtBeforeDayOffsetTest.
@Test
void findByCreatedAtBeforeDayOffsetTest() {
NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
ConfigurationModel configurationModel = createConfigurationModel();
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(notificationContentRepository.findByCreatedAtBefore(Mockito.any())).thenReturn(List.of(notificationEntity));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
List<AlertNotificationModel> alertNotificationModelList = notificationManager.findByCreatedAtBeforeDayOffset(1);
assertEquals(1, alertNotificationModelList.size());
AlertNotificationModel alertNotificationModel = alertNotificationModelList.get(0);
testExpectedAlertNotificationModel(expectedAlertNotificationModel, alertNotificationModel);
}
use of com.synopsys.integration.alert.database.notification.NotificationContentRepository in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method saveAllNotificationsTest.
@Test
void saveAllNotificationsTest() {
OffsetDateTime createdAt = DateUtils.createCurrentDateTimestamp();
OffsetDateTime providerCreationTime = createdAt.minusSeconds(10);
AlertNotificationModel alertNotificationModel = new AlertNotificationModel(null, providerConfigId, provider, providerConfigName, notificationType, content, createdAt, providerCreationTime, false);
NotificationEntity notificationEntity = new NotificationEntity(id, createdAt, provider, providerConfigId, providerCreationTime, notificationType, content, false);
ConfigurationModel configurationModel = createConfigurationModel();
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(notificationContentRepository.saveAll(Mockito.any())).thenReturn(List.of(notificationEntity));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
List<AlertNotificationModel> alertNotificationModelList = notificationManager.saveAllNotifications(List.of(alertNotificationModel));
assertEquals(1, alertNotificationModelList.size());
AlertNotificationModel testAlertNotificationModel = alertNotificationModelList.get(0);
testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel);
}
use of com.synopsys.integration.alert.database.notification.NotificationContentRepository in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method hasMoreNotificationsToProcessFalseTest.
@Test
void hasMoreNotificationsToProcessFalseTest() {
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
Mockito.when(notificationContentRepository.existsByProcessedFalse()).thenReturn(Boolean.FALSE);
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, null);
assertFalse(notificationManager.hasMoreNotificationsToProcess());
}
use of com.synopsys.integration.alert.database.notification.NotificationContentRepository in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method findByCreatedAtBetweenTest.
@Test
void findByCreatedAtBetweenTest() {
NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
ConfigurationModel configurationModel = createConfigurationModel();
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(notificationContentRepository.findByCreatedAtBetween(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(new PageImpl<>(List.of(notificationEntity)));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
List<AlertNotificationModel> alertNotificationModelList = notificationManager.findByCreatedAtBetween(DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE).getModels();
assertEquals(1, alertNotificationModelList.size());
AlertNotificationModel alertNotificationModel = alertNotificationModelList.get(0);
testExpectedAlertNotificationModel(expectedAlertNotificationModel, alertNotificationModel);
}
use of com.synopsys.integration.alert.database.notification.NotificationContentRepository in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method saveAllNotificationsEmptyModelListTest.
@Test
void saveAllNotificationsEmptyModelListTest() {
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
Mockito.when(notificationContentRepository.saveAll(Mockito.any())).thenReturn(new ArrayList<>());
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, null);
List<AlertNotificationModel> alertNotificationModelList = notificationManager.saveAllNotifications(new ArrayList<>());
assertTrue(alertNotificationModelList.isEmpty());
}
Aggregations