Search in sources :

Example 6 with NotificationContentRepository

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

the class DefaultNotificationAccessorTest method findAllWithSearchTest.

@Test
void findAllWithSearchTest() {
    final String searchTerm = "searchTerm-test";
    PageRequest pageRequest = PageRequest.of(0, 10);
    NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
    Page<NotificationEntity> notificationEntityPage = new PageImpl<>(List.of(notificationEntity));
    ConfigurationModel configurationModel = createConfigurationModel();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(notificationContentRepository.findMatchingSentNotification(Mockito.any(), Mockito.any())).thenReturn(notificationEntityPage);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
    Mockito.when(notificationContentRepository.findMatchingNotification(Mockito.any(), Mockito.any())).thenReturn(notificationEntityPage);
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
    Page<AlertNotificationModel> alertNotificationModelPage = notificationManager.findAllWithSearch(searchTerm, pageRequest, Boolean.TRUE);
    Page<AlertNotificationModel> alertNotificationModelPageShowNotificationsFalse = notificationManager.findAllWithSearch(searchTerm, pageRequest, Boolean.FALSE);
    assertEquals(1, alertNotificationModelPage.getTotalPages());
    AlertNotificationModel testAlertNotificationModel = alertNotificationModelPage.getContent().get(0);
    testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel);
    assertEquals(1, alertNotificationModelPageShowNotificationsFalse.getTotalPages());
    AlertNotificationModel testAlertNotificationModel2 = alertNotificationModelPageShowNotificationsFalse.getContent().get(0);
    testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel2);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) PageRequest(org.springframework.data.domain.PageRequest) 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 7 with NotificationContentRepository

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

the class DefaultNotificationAccessorTest method getFirstPageOfNotificationsNotProcessedTest.

@Test
void getFirstPageOfNotificationsNotProcessedTest() {
    NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
    Page<NotificationEntity> pageOfNotificationEntities = new PageImpl<>(List.of(notificationEntity));
    ConfigurationModel configurationModel = createConfigurationModel();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(notificationContentRepository.findByProcessedFalseOrderByProviderCreationTimeAsc(Mockito.any())).thenReturn(pageOfNotificationEntities);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
    AlertPagedModel<AlertNotificationModel> model = notificationManager.getFirstPageOfNotificationsNotProcessed(100);
    List<AlertNotificationModel> alertNotificationModelList = model.getModels();
    assertEquals(1, alertNotificationModelList.size());
    testExpectedAlertNotificationModel(expectedAlertNotificationModel, alertNotificationModelList.get(0));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) 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 8 with NotificationContentRepository

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

the class DefaultNotificationAccessorTest method finalAllShowNotificationsFalseTest.

@Test
void finalAllShowNotificationsFalseTest() {
    PageRequest pageRequest = PageRequest.of(0, 10);
    NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
    Page<NotificationEntity> allSentNotifications = new PageImpl<>(List.of(notificationEntity));
    ConfigurationModel configurationModel = createConfigurationModel();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
    Mockito.when(notificationContentRepository.findAll(pageRequest)).thenReturn(allSentNotifications);
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
    Page<AlertNotificationModel> alertNotificationModelPage = notificationManager.findAll(pageRequest, Boolean.FALSE);
    assertEquals(1, alertNotificationModelPage.getTotalPages());
    AlertNotificationModel testAlertNotificationModel = alertNotificationModelPage.getContent().get(0);
    testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) PageRequest(org.springframework.data.domain.PageRequest) 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 9 with NotificationContentRepository

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

the class DefaultNotificationAccessorTest method findByCreatedAtBeforeTest.

@Test
void findByCreatedAtBeforeTest() {
    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.findByCreatedAtBefore(DateUtils.createCurrentDateTimestamp());
    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 10 with NotificationContentRepository

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

the class DefaultNotificationAccessorTest method finalAllTest.

@Test
void finalAllTest() {
    PageRequest pageRequest = PageRequest.of(0, 10);
    NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
    Page<NotificationEntity> allSentNotifications = new PageImpl<>(List.of(notificationEntity));
    ConfigurationModel configurationModel = createConfigurationModel();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(notificationContentRepository.findAllSentNotifications(Mockito.any())).thenReturn(allSentNotifications);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
    Page<AlertNotificationModel> alertNotificationModelPage = notificationManager.findAll(pageRequest, Boolean.TRUE);
    assertEquals(1, alertNotificationModelPage.getTotalPages());
    AlertNotificationModel testAlertNotificationModel = alertNotificationModelPage.getContent().get(0);
    testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) PageRequest(org.springframework.data.domain.PageRequest) 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