Search in sources :

Example 1 with NotificationContentRepository

use of com.synopsys.integration.alert.database.notification.NotificationContentRepository in project hub-alert by blackducksoftware.

the class DefaultNotificationAccessorTest method getPageRequestForNotificationsTest.

@Test
void getPageRequestForNotificationsTest() {
    final int pageNumber = 1;
    final int pageSize = 1;
    final String sortField = "content";
    String sortOrder = Sort.Direction.ASC.name();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, auditEntryRepository, configurationModelConfigurationAccessor);
    PageRequest pageRequest = notificationManager.getPageRequestForNotifications(pageNumber, pageSize, sortField, sortOrder);
    assertEquals(pageNumber, pageRequest.getPageNumber());
    assertEquals(pageSize, pageRequest.getPageSize());
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) PageRequest(org.springframework.data.domain.PageRequest) AuditNotificationRepository(com.synopsys.integration.alert.database.audit.AuditNotificationRepository) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 2 with NotificationContentRepository

use of com.synopsys.integration.alert.database.notification.NotificationContentRepository in project hub-alert by blackducksoftware.

the class DefaultNotificationAccessorTest method hasMoreNotificationsToProcessTrueTest.

@Test
void hasMoreNotificationsToProcessTrueTest() {
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    Mockito.when(notificationContentRepository.existsByProcessedFalse()).thenReturn(Boolean.TRUE);
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, null);
    assertTrue(notificationManager.hasMoreNotificationsToProcess());
}
Also used : NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) Test(org.junit.jupiter.api.Test)

Example 3 with NotificationContentRepository

use of com.synopsys.integration.alert.database.notification.NotificationContentRepository 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)

Example 4 with NotificationContentRepository

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

Example 5 with NotificationContentRepository

use of com.synopsys.integration.alert.database.notification.NotificationContentRepository 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);
}
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

NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)19 Test (org.junit.jupiter.api.Test)19 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)15 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)14 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)13 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 PageRequest (org.springframework.data.domain.PageRequest)6 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)4 AuditNotificationRepository (com.synopsys.integration.alert.database.audit.AuditNotificationRepository)4 PageImpl (org.springframework.data.domain.PageImpl)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)3 AuditEntryPageModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel)3 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)3 AuditDescriptorKey (com.synopsys.integration.alert.component.audit.AuditDescriptorKey)3 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)3 DefaultRestApiAuditAccessor (com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3 MockNotificationContent (com.synopsys.integration.alert.mock.entity.MockNotificationContent)3 ContentConverter (com.synopsys.integration.alert.common.ContentConverter)2