use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method findByIdTest.
@Test
void findByIdTest() {
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.findById(Mockito.any())).thenReturn(Optional.of(notificationEntity));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
Optional<AlertNotificationModel> alertNotificationModel = notificationManager.findById(1L);
assertTrue(alertNotificationModel.isPresent());
testExpectedAlertNotificationModel(expectedAlertNotificationModel, alertNotificationModel.get());
}
use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method setNotificationsProcessedTest.
@Test
void setNotificationsProcessedTest() {
AlertNotificationModel alertNotificationModel = new AlertNotificationModel(null, providerConfigId, provider, providerConfigName, notificationType, content, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
notificationManager.setNotificationsProcessed(List.of(alertNotificationModel));
Mockito.verify(notificationContentRepository).setProcessedByIds(Mockito.any());
}
use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method findByIdsTest.
@Test
void findByIdsTest() {
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.findAllById(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.findByIds(List.of(1L));
assertEquals(1, alertNotificationModelList.size());
AlertNotificationModel alertNotificationModel = alertNotificationModelList.get(0);
testExpectedAlertNotificationModel(expectedAlertNotificationModel, alertNotificationModel);
}
use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method findAllWithSearchTest.
@Test
void findAllWithSearchTest() {
final String searchTerm = "searchTerm-test";
PageRequest pageRequest = PageRequest.of(0, 10);
NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
Page<NotificationEntity> notificationEntityPage = new PageImpl<>(List.of(notificationEntity));
ConfigurationModel configurationModel = createConfigurationModel();
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(notificationContentRepository.findMatchingSentNotification(Mockito.any(), Mockito.any())).thenReturn(notificationEntityPage);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
Mockito.when(notificationContentRepository.findMatchingNotification(Mockito.any(), Mockito.any())).thenReturn(notificationEntityPage);
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
Page<AlertNotificationModel> alertNotificationModelPage = notificationManager.findAllWithSearch(searchTerm, pageRequest, Boolean.TRUE);
Page<AlertNotificationModel> alertNotificationModelPageShowNotificationsFalse = notificationManager.findAllWithSearch(searchTerm, pageRequest, Boolean.FALSE);
assertEquals(1, alertNotificationModelPage.getTotalPages());
AlertNotificationModel testAlertNotificationModel = alertNotificationModelPage.getContent().get(0);
testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel);
assertEquals(1, alertNotificationModelPageShowNotificationsFalse.getTotalPages());
AlertNotificationModel testAlertNotificationModel2 = alertNotificationModelPageShowNotificationsFalse.getContent().get(0);
testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel2);
}
use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method getFirstPageOfNotificationsNotProcessedTest.
@Test
void getFirstPageOfNotificationsNotProcessedTest() {
NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
Page<NotificationEntity> pageOfNotificationEntities = new PageImpl<>(List.of(notificationEntity));
ConfigurationModel configurationModel = createConfigurationModel();
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(notificationContentRepository.findByProcessedFalseOrderByProviderCreationTimeAsc(Mockito.any())).thenReturn(pageOfNotificationEntities);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
AlertPagedModel<AlertNotificationModel> model = notificationManager.getFirstPageOfNotificationsNotProcessed(100);
List<AlertNotificationModel> alertNotificationModelList = model.getModels();
assertEquals(1, alertNotificationModelList.size());
testExpectedAlertNotificationModel(expectedAlertNotificationModel, alertNotificationModelList.get(0));
}
Aggregations