use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method finalAllTest.
@Test
void finalAllTest() {
PageRequest pageRequest = PageRequest.of(0, 10);
NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
Page<NotificationEntity> allSentNotifications = new PageImpl<>(List.of(notificationEntity));
ConfigurationModel configurationModel = createConfigurationModel();
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(notificationContentRepository.findAllSentNotifications(Mockito.any())).thenReturn(allSentNotifications);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
Page<AlertNotificationModel> alertNotificationModelPage = notificationManager.findAll(pageRequest, Boolean.TRUE);
assertEquals(1, alertNotificationModelPage.getTotalPages());
AlertNotificationModel testAlertNotificationModel = alertNotificationModelPage.getContent().get(0);
testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel);
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel 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.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessor method getPageOfNotifications.
private Page<AlertNotificationModel> getPageOfNotifications(String sortField, String sortOrder, String searchTerm, Integer pageNumber, Integer pageSize, boolean onlyShowSentNotifications) {
PageRequest pageRequest = notificationAccessor.getPageRequestForNotifications(pageNumber, pageSize, sortField, sortOrder);
Page<AlertNotificationModel> auditPage;
if (StringUtils.isNotBlank(searchTerm)) {
auditPage = notificationAccessor.findAllWithSearch(searchTerm, pageRequest, onlyShowSentNotifications);
} else {
auditPage = notificationAccessor.findAll(pageRequest, onlyShowSentNotifications);
}
return auditPage;
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class NotificationAccessorTestIT method testDeleteNotification.
@Test
public void testDeleteNotification() {
AlertNotificationModel notificationEntity = createNotificationModel();
AlertNotificationModel savedModel = notificationManager.saveAllNotifications(List.of(notificationEntity)).get(0);
assertEquals(1, notificationContentRepository.count());
notificationManager.deleteNotification(savedModel);
assertEquals(0, notificationContentRepository.count());
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class NotificationAccessorTestIT method setNotificationsProcessedByIdTest.
@Test
public void setNotificationsProcessedByIdTest() {
AlertNotificationModel notificationModel = createNotificationModel();
List<AlertNotificationModel> savedModels = notificationManager.saveAllNotifications(List.of(notificationModel));
List<Long> notificationIds = savedModels.stream().map(AlertNotificationModel::getId).collect(Collectors.toList());
notificationManager.setNotificationsProcessedById(new HashSet<>(notificationIds));
assertEquals(1, notificationIds.size());
Optional<AlertNotificationModel> alertNotificationModelTest = notificationManager.findById(notificationIds.get(0));
assertTrue(alertNotificationModelTest.isPresent());
assertTrue(alertNotificationModelTest.get().getProcessed());
}
Aggregations