use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendTwoWildCardsWithDifferentTemplate.
@Test
public void testSendTwoWildCardsWithDifferentTemplate() {
String topic = "testTopic-" + System.currentTimeMillis();
String textTemplate1 = "testMessageTemplate1-" + System.currentTimeMillis();
String textTemplate2 = "testMessageTemplate2-" + System.currentTimeMillis();
//
IdmNotificationTemplateDto template1 = new IdmNotificationTemplateDto();
template1.setName(textTemplate1);
template1.setCode(textTemplate1);
template1.setBodyHtml(textTemplate1);
template1.setBodyText(textTemplate1);
template1.setSubject(textTemplate1);
template1 = notificationTemplateService.save(template1);
//
IdmNotificationTemplateDto template2 = new IdmNotificationTemplateDto();
template2.setName(textTemplate2);
template2.setCode(textTemplate2);
template2.setBodyHtml(textTemplate2);
template2.setBodyText(textTemplate2);
template2.setSubject(textTemplate2);
template2 = notificationTemplateService.save(template2);
//
IdmIdentityDto identity = getHelper().createIdentity();
// create config, for email, topic, template and without level = wildcard
NotificationConfigurationDto config1 = new NotificationConfigurationDto();
// topic
config1.setTopic(topic);
// template
config1.setTemplate(template1.getId());
// email
config1.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
config1 = notificationConfigurationService.save(config1);
//
// create second config, for console, topic, template and without level = wildcard
NotificationConfigurationDto config = new NotificationConfigurationDto();
// same topic
config.setTopic(topic);
// different template
config.setTemplate(template2.getId());
// console
config.setNotificationType(IdmConsoleLog.NOTIFICATION_TYPE);
config = notificationConfigurationService.save(config);
//
List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
NotificationLevel.SUCCESS).build(), identity);
//
assertEquals(2, notifications.size());
//
//
int orderConsole = 0;
int orderEmail = 1;
// we didn't know order
if (!notifications.get(0).getMessage().getHtmlMessage().equals(textTemplate2)) {
// email first
orderConsole = 1;
orderEmail = 0;
}
//
// Notification has different text
IdmNotificationLogDto notificationConsole = notifications.get(orderConsole);
assertEquals(textTemplate2, notificationConsole.getMessage().getHtmlMessage());
assertEquals(textTemplate2, notificationConsole.getMessage().getSubject());
assertEquals(textTemplate2, notificationConsole.getMessage().getTextMessage());
//
IdmNotificationLogDto notificationEmail = notifications.get(orderEmail);
assertEquals(textTemplate1, notificationEmail.getMessage().getHtmlMessage());
assertEquals(textTemplate1, notificationEmail.getMessage().getSubject());
assertEquals(textTemplate1, notificationEmail.getMessage().getTextMessage());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSenderFilterTest.
@Test
public void testSenderFilterTest() {
IdmIdentityDto sender = getHelper().createIdentity();
IdmNotificationFilter filter = new IdmNotificationFilter();
IdmNotificationDto notification = new IdmNotificationDto();
notification.setIdentitySender(sender.getId());
//
// create templates
IdmNotificationTemplateDto template = createTestTemplate();
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
notification.setMessage(message);
notificationManager.send(notification);
//
// filter text BODY
filter.setSender(sender.getUsername());
Page<IdmNotificationLogDto> result = notificationLogService.find(filter, null);
assertEquals("Wrong sender", sender.getId(), result.getContent().get(0).getIdentitySender());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendNofificationToConsoleIfTopicNotFound.
@Test
public void testSendNofificationToConsoleIfTopicNotFound() {
String topic = getHelper().createName();
// create config, for email, topic, template and without level = wildcard
NotificationConfigurationDto config = new NotificationConfigurationDto();
// topic
config.setTopic(topic);
config.setLevel(NotificationLevel.INFO);
// email
config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
config = notificationConfigurationService.save(config);
//
IdmIdentityDto identity = getHelper().createIdentity();
List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
NotificationLevel.SUCCESS).setMessage("message").setSubject("subject").build(), identity);
//
assertEquals(1, notifications.size());
//
// console channel is expected, because topic configuration is wrong
IdmNotificationLogDto notification = notifications.get(0);
//
Assert.assertEquals(IdmConsoleLog.NOTIFICATION_TYPE, notification.getType());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendWildCardsWithTemplateAndOwnText.
@Test
public void testSendWildCardsWithTemplateAndOwnText() {
String topic = "testTopic-" + System.currentTimeMillis();
String textMessage = "testMessageText-" + System.currentTimeMillis();
String textTemplate = "testMessageTemplate-" + System.currentTimeMillis();
//
IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
template.setName(textTemplate);
template.setCode(textTemplate);
template.setBodyHtml(textTemplate);
template.setBodyText(textTemplate);
template.setSubject(textTemplate);
template = notificationTemplateService.save(template);
//
IdmIdentityDto identity = getHelper().createIdentity();
// create config, for email, topic, template and without level = wildcard
NotificationConfigurationDto config = new NotificationConfigurationDto();
// topic
config.setTopic(topic);
// template
config.setTemplate(template.getId());
// email
config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
config = notificationConfigurationService.save(config);
//
// set all text into message
List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
NotificationLevel.SUCCESS).setHtmlMessage(textMessage).setTextMessage(textMessage).setSubject(textMessage).build(), identity);
//
assertEquals(1, notifications.size());
//
IdmNotificationLogDto notification = notifications.get(0);
// topic has own template, but in message is set text
assertEquals(textMessage, notification.getMessage().getHtmlMessage());
assertEquals(textMessage, notification.getMessage().getSubject());
assertEquals(textMessage, notification.getMessage().getTextMessage());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendWildCardsWithoutTemplate.
@Test
public void testSendWildCardsWithoutTemplate() {
String topic = "testTopic-" + System.currentTimeMillis();
String text = "testMessageText-" + System.currentTimeMillis();
//
IdmIdentityDto identity = getHelper().createIdentity();
// create config, for email, topic and without level = wildcard
NotificationConfigurationDto config = new NotificationConfigurationDto();
// topic
config.setTopic(topic);
// email
config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
config = notificationConfigurationService.save(config);
//
// set all text into message
List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
NotificationLevel.SUCCESS).setHtmlMessage(text).setTextMessage(text).setSubject(text).build(), identity);
//
assertEquals(1, notifications.size());
//
IdmNotificationLogDto notification = notifications.get(0);
assertEquals(text, notification.getMessage().getHtmlMessage());
assertEquals(text, notification.getMessage().getSubject());
assertEquals(text, notification.getMessage().getTextMessage());
}
Aggregations