Search in sources :

Example 21 with NotificationMessage

use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.

the class NotificationManagerTest method testCreateNotificationWithExistingCopyUser.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testCreateNotificationWithExistingCopyUser() {
    final NotificationMessageVO message = new NotificationMessageVO();
    message.setBody(BODY);
    message.setSubject(SUBJECT);
    message.setParameters(PARAMETERS);
    message.setToUser(testUser1.getUserName());
    message.setCopyUsers(Collections.singletonList(testUser2.getUserName()));
    final NotificationMessage savedMessage = notificationManager.createNotification(message);
    final NotificationMessage loadedMessage = monitoringNotificationDao.loadMonitoringNotification(savedMessage.getId());
    Assert.assertEquals(BODY, loadedMessage.getBody());
    Assert.assertEquals(SUBJECT, loadedMessage.getSubject());
    Assert.assertEquals(PARAMETERS, loadedMessage.getTemplateParameters());
    Assert.assertEquals(testUser1.getId(), loadedMessage.getToUserId());
    Assert.assertEquals(Collections.singletonList(testUser2.getId()), loadedMessage.getCopyUserIds());
}
Also used : NotificationMessageVO(com.epam.pipeline.controller.vo.notification.NotificationMessageVO) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with NotificationMessage

use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.

the class NotificationManagerTest method testNotifyIssue.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyIssue() {
    Pipeline pipeline = createPipeline(testOwner);
    Issue issue = createIssue(testUser2, pipeline);
    notificationManager.notifyIssue(issue, pipeline, issue.getText());
    List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
    Assert.assertEquals(1, messages.size());
    NotificationMessage message = messages.get(0);
    Assert.assertEquals(testOwner.getId(), message.getToUserId());
    Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testUser1.getId())));
    Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testUser2.getId())));
    Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(admin.getId())));
    updateKeepInformedOwner(issueSettings, false);
    notificationManager.notifyIssue(issue, pipeline, issue.getText());
    messages = monitoringNotificationDao.loadAllNotifications();
    Assert.assertEquals(2, messages.size());
    Assert.assertNull(messages.get(1).getToUserId());
}
Also used : Arrays(java.util.Arrays) DateTimeZone(org.joda.time.DateTimeZone) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) PodMonitor(com.epam.pipeline.manager.cluster.PodMonitor) Autowired(org.springframework.beans.factory.annotation.Autowired) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) MockitoAnnotations(org.mockito.MockitoAnnotations) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) Map(java.util.Map) IssueComment(com.epam.pipeline.entity.issue.IssueComment) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) MockBean(org.springframework.boot.test.mock.mockito.MockBean) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) DateUtils(com.epam.pipeline.entity.utils.DateUtils) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) NotificationTemplateDao(com.epam.pipeline.dao.notification.NotificationTemplateDao) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) List(java.util.List) MonitoringNotificationDao(com.epam.pipeline.dao.notification.MonitoringNotificationDao) NotificationSettings(com.epam.pipeline.entity.notification.NotificationSettings) UserDao(com.epam.pipeline.dao.user.UserDao) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) EntityVO(com.epam.pipeline.controller.vo.EntityVO) Mockito.mock(org.mockito.Mockito.mock) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NotificationSettingsDao(com.epam.pipeline.dao.notification.NotificationSettingsDao) Mock(org.mockito.Mock) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) Duration(org.joda.time.Duration) TestApplication(com.epam.pipeline.app.TestApplication) PipelineDao(com.epam.pipeline.dao.pipeline.PipelineDao) ArgumentCaptor(org.mockito.ArgumentCaptor) Propagation(org.springframework.transaction.annotation.Propagation) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) KubernetesManager(com.epam.pipeline.manager.cluster.KubernetesManager) KubernetesTestUtils(com.epam.pipeline.util.KubernetesTestUtils) NotificationType(com.epam.pipeline.entity.notification.NotificationSettings.NotificationType) Before(org.junit.Before) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) PodStatus(io.fabric8.kubernetes.api.model.PodStatus) CustomAssertions.assertThrows(com.epam.pipeline.util.CustomAssertions.assertThrows) DateTime(org.joda.time.DateTime) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) Matchers(org.hamcrest.Matchers) Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) NotificationMessageVO(com.epam.pipeline.controller.vo.notification.NotificationMessageVO) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) Mockito.verify(org.mockito.Mockito.verify) PodList(io.fabric8.kubernetes.api.model.PodList) ContextConfiguration(org.springframework.test.context.ContextConfiguration) IssueDao(com.epam.pipeline.dao.issue.IssueDao) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assert(org.junit.Assert) Issue(com.epam.pipeline.entity.issue.Issue) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Issue(com.epam.pipeline.entity.issue.Issue) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with NotificationMessage

use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.

the class NotificationManagerTest method testCreateNotification.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testCreateNotification() {
    final NotificationMessageVO message = new NotificationMessageVO();
    message.setBody(BODY);
    message.setSubject(SUBJECT);
    message.setParameters(PARAMETERS);
    message.setToUser(testUser1.getUserName());
    final NotificationMessage savedMessage = notificationManager.createNotification(message);
    final NotificationMessage loadedMessage = monitoringNotificationDao.loadMonitoringNotification(savedMessage.getId());
    Assert.assertEquals(BODY, loadedMessage.getBody());
    Assert.assertEquals(SUBJECT, loadedMessage.getSubject());
    Assert.assertEquals(PARAMETERS, loadedMessage.getTemplateParameters());
    Assert.assertEquals(testUser1.getId(), loadedMessage.getToUserId());
}
Also used : NotificationMessageVO(com.epam.pipeline.controller.vo.notification.NotificationMessageVO) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with NotificationMessage

use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.

the class NotificationAspectTest method testNotifyRunStatusChanged.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyRunStatusChanged() {
    PipelineRun run = new PipelineRun();
    run.setStatus(TaskStatus.SUCCESS);
    run.setOwner(testOwner.getUserName());
    run.setStartDate(new Date());
    pipelineRunManager.updatePipelineStatus(run);
    List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
    Assert.assertFalse(messages.isEmpty());
    NotificationMessage message = messages.get(0);
    Assert.assertEquals(testOwner.getId(), message.getToUserId());
    Assert.assertEquals(TaskStatus.SUCCESS.name(), message.getTemplateParameters().get("status"));
    Mockito.verify(pipelineRunDao).updateRunStatus(Mockito.any());
    Mockito.verify(runStatusManager).saveStatus(Mockito.any());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) Date(java.util.Date) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with NotificationMessage

use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.

the class NotificationService method sendNotification.

/**
 * Scheduled task to load batch of {@link NotificationMessage} from database
 * and delegate it to all realizations of {@link NotificationManager}
 */
@Scheduled(fixedDelayString = "${notification.scheduler.delay}")
@Transactional(propagation = Propagation.REQUIRED)
public void sendNotification() {
    LOGGER.debug("Start scheduled notification loop...");
    Pageable limit = new PageRequest(0, notificationAtTime);
    List<NotificationMessage> result = notificationRepository.loadNotification(limit);
    result.forEach(message -> {
        notificationRepository.deleteById(message.getId());
        for (NotificationManager notificationManager : notificationManagers) {
            CompletableFuture.runAsync(() -> notificationManager.notifySubscribers(message), notificationThreadPool).exceptionally(throwable -> {
                LOGGER.warn("Exception while trying to send email", throwable);
                return null;
            });
        }
    });
    LOGGER.debug("End scheduled notification loop...");
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) NotificationManager(com.epam.pipeline.notifier.service.task.NotificationManager) Scheduled(org.springframework.scheduling.annotation.Scheduled) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NotificationMessage (com.epam.pipeline.entity.notification.NotificationMessage)26 Transactional (org.springframework.transaction.annotation.Transactional)25 Test (org.junit.Test)18 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)15 NotificationTemplate (com.epam.pipeline.entity.notification.NotificationTemplate)14 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)8 NotificationSettings (com.epam.pipeline.entity.notification.NotificationSettings)7 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)6 AbstractSpringTest (com.epam.pipeline.notifier.AbstractSpringTest)6 NotificationMessageVO (com.epam.pipeline.controller.vo.notification.NotificationMessageVO)5 ExtendedRole (com.epam.pipeline.entity.user.ExtendedRole)5 Collections (java.util.Collections)5 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)4 Issue (com.epam.pipeline.entity.issue.Issue)4 IssueComment (com.epam.pipeline.entity.issue.IssueComment)4 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)4 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)4 Arrays (java.util.Arrays)4 List (java.util.List)4 Map (java.util.Map)4