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()))));
}
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());
});
}
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);
}
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;
}
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);
}
Aggregations