use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.
the class AuditEntryHandlerTestIT method getTestIT.
@Test
public void getTestIT() {
NotificationEntity savedNotificationEntity = notificationContentRepository.save(mockNotification.createEntity());
notificationContentRepository.save(new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), "provider", DateUtils.createCurrentDateTimestamp(), "notificationType", "{}", 234L, providerConfigModel.getConfigurationId()).createEntity());
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(jobModel.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null));
auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
AuditEntryActions auditEntryActions = createAuditActions(authorizationManager);
AuditEntryPageModel auditEntries = auditEntryActions.get(null, null, null, null, null, true).getContent().orElse(null);
assertEquals(1, auditEntries.getContent().size());
AuditEntryModel auditEntryResponse = auditEntryActions.get(savedNotificationEntity.getId()).getContent().orElse(null);
assertNotNull(auditEntryResponse);
AuditEntryModel auditEntry = auditEntries.getContent().get(0);
assertEquals(savedNotificationEntity.getId().toString(), auditEntry.getId());
assertFalse(auditEntry.getJobs().isEmpty());
assertEquals(1, auditEntry.getJobs().size());
NotificationConfig notification = auditEntry.getNotification();
String createdAtStringValue = DateUtils.formatDate(savedNotificationEntity.getCreatedAt(), DateUtils.AUDIT_DATE_FORMAT);
assertEquals(createdAtStringValue, notification.getCreatedAt());
assertEquals(savedNotificationEntity.getNotificationType(), notification.getNotificationType());
assertNotNull(notification.getContent());
auditEntries = auditEntryActions.get(null, null, null, null, null, false).getContent().orElse(null);
assertEquals(2, auditEntries.getContent().size());
}
use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationAccessorTestIT method deleteNotificationsCreatedBeforeTest.
@Test
public void deleteNotificationsCreatedBeforeTest() {
OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
OffsetDateTime oneHourAgo = currentTime.minusHours(1);
OffsetDateTime oneAndAHalfHoursAgo = oneHourAgo.minusMinutes(30);
OffsetDateTime twoHoursAgo = currentTime.minusHours(2);
OffsetDateTime threeHoursAgo = currentTime.minusHours(3);
OffsetDateTime oneDayAgo = currentTime.minusDays(1);
NotificationEntity notification1 = createNotificationContent(oneHourAgo);
// These notifications should be deleted
NotificationEntity notification2 = createNotificationContent(twoHoursAgo);
NotificationEntity notification3 = createNotificationContent(threeHoursAgo);
NotificationEntity notification4 = createNotificationContent(oneDayAgo);
notificationContentRepository.saveAll(List.of(notification1, notification2, notification3, notification4));
int deletedCount = notificationManager.deleteNotificationsCreatedBefore(oneAndAHalfHoursAgo);
assertEquals(3, deletedCount);
List<NotificationEntity> remainingNotifications = notificationContentRepository.findAll();
assertEquals(1, remainingNotifications.size());
NotificationEntity remainingNotification = remainingNotifications.get(0);
assertEquals(notification1.getCreatedAt(), remainingNotification.getCreatedAt());
}
use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTestIT method createAlertNotificationModel.
private AlertNotificationModel createAlertNotificationModel(boolean processed) {
String bomEditContent = "{" + "\"type\":\"" + NotificationType.BOM_EDIT.name() + "\"," + "\"content\": {" + "\"projectVersion\": \"" + properties.getBlackDuckURL() + "/api/projects\"," + "\"bomComponent\": \"" + properties.getBlackDuckURL() + "\"," + "\"componentName\": \"test\"," + "\"componentVersionName\": \"test\"" + "}" + "}";
MockNotificationContent notificationMocker = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), blackDuckProviderKey.getUniversalKey(), DateUtils.createCurrentDateTimestamp(), NotificationType.BOM_EDIT.name(), bomEditContent, null, blackDuckGlobalConfigId);
NotificationEntity entity = notificationMocker.createEntity();
return new AlertNotificationModel(null, entity.getProviderConfigId(), entity.getProvider(), "providerConfigName", entity.getNotificationType(), entity.getContent(), entity.getCreatedAt(), entity.getProviderCreationTime(), processed);
}
use of com.synopsys.integration.alert.database.notification.NotificationEntity 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.NotificationEntity 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);
}
Aggregations