Search in sources :

Example 16 with NotificationTemplate

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

the class MonitoringNotificationDaoTest method testCreateMonitoringNotifications.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testCreateMonitoringNotifications() {
    NotificationTemplate notificationTemplate = notificationTemplateDao.createNotificationTemplate(template);
    PipelineUser pipelineUser = userDao.loadUserByName(TEST_USER1);
    List<NotificationMessage> messages = IntStream.range(0, 5).mapToObj(i -> {
        NotificationMessage notificationMessage = new NotificationMessage();
        notificationMessage.setTemplate(notificationTemplate);
        notificationMessage.setToUserId(pipelineUser.getId());
        notificationMessage.setCopyUserIds(Collections.singletonList(pipelineUser.getId()));
        notificationMessage.setTemplateParameters(Collections.singletonMap("test", i));
        return notificationMessage;
    }).collect(Collectors.toList());
    monitoringNotificationDao.createMonitoringNotifications(messages);
    List<NotificationMessage> loaded = monitoringNotificationDao.loadAllNotifications();
    assertTrue(messages.size() <= loaded.size());
    assertTrue(loaded.stream().allMatch(l -> messages.stream().anyMatch(m -> m.getTemplateParameters().equals(l.getTemplateParameters()))));
}
Also used : IntStream(java.util.stream.IntStream) PipelineRunMapper(com.epam.pipeline.mapper.PipelineRunMapper) Arrays(java.util.Arrays) PipelineRunDao(com.epam.pipeline.dao.pipeline.PipelineRunDao) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) PipelineDao(com.epam.pipeline.dao.pipeline.PipelineDao) Propagation(org.springframework.transaction.annotation.Propagation) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) Before(org.junit.Before) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Collectors(java.util.stream.Collectors) com.epam.pipeline.entity.pipeline(com.epam.pipeline.entity.pipeline) Objects(java.util.Objects) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) UserDao(com.epam.pipeline.dao.user.UserDao) Collections(java.util.Collections) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with NotificationTemplate

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

the class MonitoringNotificationDaoTest method testLoadMonitoringNotification.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testLoadMonitoringNotification() {
    PipelineRun run1 = createTestPipelineRun();
    List<PipelineRun> pipelineRuns = pipelineRunDao.loadPipelineRuns(Collections.singletonList(run1.getId()));
    NotificationTemplate notificationTemplate = notificationTemplateDao.createNotificationTemplate(template);
    notificationMessage = new NotificationMessage();
    notificationMessage.setTemplate(notificationTemplate);
    PipelineUser pipelineUser = userDao.loadUserByName(TEST_USER1);
    notificationMessage.setToUserId(pipelineUser.getId());
    notificationMessage.setCopyUserIds(Collections.singletonList(pipelineUser.getId()));
    notificationMessage.setTemplateParameters(PipelineRunMapper.map(pipelineRuns.get(0), TEST_THRESHOLD));
    monitoringNotificationDao.createMonitoringNotification(notificationMessage);
    NotificationMessage actualMessage = monitoringNotificationDao.loadMonitoringNotification(notificationMessage.getId());
    assertEquals(notificationMessage.getId(), actualMessage.getId());
    assertEquals(notificationMessage.getTemplate().getId(), actualMessage.getTemplate().getId());
    assertEquals(user.getId(), notificationMessage.getToUserId());
    assertFalse(notificationMessage.getCopyUserIds().isEmpty());
    notificationMessage.getTemplateParameters().values().removeIf(Objects::isNull);
    notificationMessage.getTemplateParameters().forEach((k, v) -> {
        assertTrue(actualMessage.getTemplateParameters().containsKey(k));
        assertEquals(v.toString(), actualMessage.getTemplateParameters().get(k).toString());
    });
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) Objects(java.util.Objects) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with NotificationTemplate

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

the class MonitoringNotificationDaoTest method setUp.

@Before
public void setUp() {
    user = new PipelineUser();
    user.setUserName(TEST_USER1);
    userDao.createUser(user, Arrays.asList(DefaultRoles.ROLE_ADMIN.getId(), DefaultRoles.ROLE_USER.getId()));
    testPipeline = new Pipeline();
    testPipeline.setName("Test");
    testPipeline.setRepository("///");
    testPipeline.setOwner(TEST_USER1);
    pipelineDao.createPipeline(testPipeline);
    template = new NotificationTemplate();
    template.setId(1L);
    template.setSubject(SUBJECT_STRING);
    template.setBody(BODY_STRING);
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Before(org.junit.Before)

Example 19 with NotificationTemplate

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

the class NotificationTemplateDaoTest method createTemplate.

private NotificationTemplate createTemplate() {
    NotificationTemplate template = new NotificationTemplate();
    template.setId(1L);
    template.setSubject(SUBJECT_STRING);
    template.setName(TEST_NAME);
    template.setBody(BODY_STRING);
    return template;
}
Also used : NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate)

Example 20 with NotificationTemplate

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

the class NotificationAspectTest method setUp.

@Before
public void setUp() throws Exception {
    statusTemplate = new NotificationTemplate(5L);
    statusTemplate.setBody("///");
    statusTemplate.setSubject("//");
    statusTemplate.setName("testTemplate");
    notificationTemplateDao.createNotificationTemplate(statusTemplate);
    NotificationSettings settings = new NotificationSettings();
    settings.setType(NotificationSettings.NotificationType.PIPELINE_RUN_STATUS);
    settings.setKeepInformedAdmins(true);
    settings.setInformedUserIds(Collections.emptyList());
    settings.setTemplateId(statusTemplate.getId());
    settings.setThreshold(null);
    settings.setEnabled(true);
    settings.setResendDelay(null);
    settings.setKeepInformedOwner(true);
    notificationSettingsDao.createNotificationSettings(settings);
    testOwner = new PipelineUser("testOwner");
    userDao.createUser(testOwner, Collections.emptyList());
    pipeline = new Pipeline();
    pipeline.setName("TestPipeline");
    Mockito.when(pipelineManager.load(Mockito.anyLong())).thenReturn(pipeline);
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationSettings(com.epam.pipeline.entity.notification.NotificationSettings) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) Before(org.junit.Before)

Aggregations

NotificationTemplate (com.epam.pipeline.entity.notification.NotificationTemplate)24 Transactional (org.springframework.transaction.annotation.Transactional)17 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)13 NotificationMessage (com.epam.pipeline.entity.notification.NotificationMessage)12 Test (org.junit.Test)12 NotificationSettings (com.epam.pipeline.entity.notification.NotificationSettings)8 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)7 AbstractSpringTest (com.epam.pipeline.notifier.AbstractSpringTest)5 ExtendedRole (com.epam.pipeline.entity.user.ExtendedRole)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)3 MimeMessage (javax.mail.internet.MimeMessage)3 Before (org.junit.Before)3 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)2 Issue (com.epam.pipeline.entity.issue.Issue)2 IssueComment (com.epam.pipeline.entity.issue.IssueComment)2 NotificationType (com.epam.pipeline.entity.notification.NotificationSettings.NotificationType)2 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)2 PipelineRunMapper (com.epam.pipeline.mapper.PipelineRunMapper)2 Arrays (java.util.Arrays)2