Search in sources :

Example 1 with NotificationEntity

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());
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity)

Example 2 with NotificationEntity

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;
}
Also used : ArrayList(java.util.ArrayList) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) Date(java.util.Date) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with NotificationEntity

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());
}
Also used : NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) Date(java.util.Date) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest)

Example 4 with NotificationEntity

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;
}
Also used : MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) OffsetDateTime(java.time.OffsetDateTime) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity)

Example 5 with NotificationEntity

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());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) Test(org.junit.jupiter.api.Test)

Aggregations

NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)29 Test (org.junit.jupiter.api.Test)24 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)16 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)13 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)13 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)11 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)9 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)9 PageRequest (org.springframework.data.domain.PageRequest)9 OffsetDateTime (java.time.OffsetDateTime)8 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)7 MockNotificationContent (com.synopsys.integration.alert.mock.entity.MockNotificationContent)6 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)5 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)4 PageImpl (org.springframework.data.domain.PageImpl)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 AuditEntryPageModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel)3 AuditDescriptorKey (com.synopsys.integration.alert.component.audit.AuditDescriptorKey)3 MockAuditEntryEntity (com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity)3