Search in sources :

Example 11 with NotificationContentRepository

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

use of com.synopsys.integration.alert.database.notification.NotificationContentRepository 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);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) OffsetDateTime(java.time.OffsetDateTime) 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 13 with NotificationContentRepository

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

the class DefaultNotificationAccessorTest method hasMoreNotificationsToProcessFalseTest.

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

Example 14 with NotificationContentRepository

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

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

the class DefaultNotificationAccessorTest method saveAllNotificationsEmptyModelListTest.

@Test
void saveAllNotificationsEmptyModelListTest() {
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    Mockito.when(notificationContentRepository.saveAll(Mockito.any())).thenReturn(new ArrayList<>());
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, null);
    List<AlertNotificationModel> alertNotificationModelList = notificationManager.saveAllNotifications(new ArrayList<>());
    assertTrue(alertNotificationModelList.isEmpty());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) 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