use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationContentRepositoryIT method notificationQueryTest.
public void notificationQueryTest(BiFunction<String, Pageable, Page<NotificationEntity>> queryFunction) throws ParseException, AlertException {
final String searchTerm = "searchTerm";
final int numberToCreate = 1000;
Number numberOfSearchTermMatches = initializeNotificationRepo(searchTerm, numberToCreate);
Instant beforeQueryInstant = Instant.now();
Page<NotificationEntity> matchingNotifications = queryFunction.apply(searchTerm, Pageable.unpaged());
Instant afterQueryInstant = Instant.now();
Duration queryDuration = Duration.between(beforeQueryInstant, afterQueryInstant);
Long durationInSeconds = queryDuration.toSeconds();
System.out.println("Duration (in seconds): " + durationInSeconds);
assertEquals(numberOfSearchTermMatches, matchingNotifications.getTotalElements());
}
use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationContentRepositoryIT method initializeNotificationRepo.
private Long initializeNotificationRepo(String searchTerm, int numberToCreate) throws ParseException {
List<NotificationEntity> notifications = new ArrayList<>(numberToCreate);
long searchableCount = 0;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(RestConstants.JSON_DATE_FORMAT);
for (int i = 0; i < numberToCreate; i++) {
Date newDate = new Date();
String dateString = simpleDateFormat.format(newDate);
NotificationEntity entity;
if (i % 31 == 0) {
entity = createEntity(dateString, searchTerm);
searchableCount++;
} else {
entity = createEntity(dateString);
}
notifications.add(entity);
}
List<NotificationEntity> savedNotifications = notificationContentRepository.saveAll(notifications);
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
UUID jobId = jobModel.getJobId();
// more investigation is needed
for (NotificationEntity savedNotification : savedNotifications) {
AuditEntryEntity newEntry = new AuditEntryEntity(jobId, OffsetDateTime.now(), null, AuditEntryStatus.PENDING.name(), null, null);
AuditEntryEntity savedEntry = auditEntryRepository.save(newEntry);
AuditNotificationRelation notifAudit = new AuditNotificationRelation(savedEntry.getId(), savedNotification.getId());
auditNotificationRepository.save(notifAudit);
}
auditEntryRepository.flush();
return searchableCount;
}
use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationContentRepositoryIT method testSaveEntity.
@Test
public void testSaveEntity() throws Exception {
NotificationEntity entity = createEntity(RestConstants.formatDate(new Date()));
NotificationEntity savedEntity = notificationContentRepository.save(entity);
long count = notificationContentRepository.count();
assertEquals(1, count);
Optional<NotificationEntity> foundEntityOptional = notificationContentRepository.findById(savedEntity.getId());
NotificationEntity foundEntity = foundEntityOptional.get();
assertEquals(entity.getCreatedAt(), foundEntity.getCreatedAt());
assertEquals(entity.getNotificationType(), foundEntity.getNotificationType());
assertEquals(entity.getProvider(), foundEntity.getProvider());
assertEquals(entity.getProviderCreationTime(), foundEntity.getProviderCreationTime());
assertEquals(entity.getContent(), foundEntity.getContent());
}
use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationContentRepositoryIT method createEntity.
private NotificationEntity createEntity(String dateString, String content) throws ParseException {
OffsetDateTime providerCreationTime = DateUtils.parseDateFromJsonString(dateString);
final String provider = "provider_blackduck";
final String notificationType = "type_1";
NotificationEntity entity = new MockNotificationContent(providerCreationTime, provider, providerCreationTime, notificationType, content, null, providerConfigModel.getConfigurationId()).createEntity();
NotificationEntity savedEntity = notificationContentRepository.save(entity);
return savedEntity;
}
use of com.synopsys.integration.alert.database.notification.NotificationEntity 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());
}
Aggregations