use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto 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.IdmNotificationTemplateDto 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.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testFilterByDate.
@Test
public void testFilterByDate() {
assertEquals(0, notificationRepository.count());
IdmNotificationTemplateDto template = createTestTemplate();
IdmIdentityDto identity = identityService.getByUsername(InitTestDataProcessor.TEST_USER_1);
NotificationConfigurationDto config = createConfig();
//
ZonedDateTime from = ZonedDateTime.now().minusDays(1);
ZonedDateTime till = ZonedDateTime.now().minusDays(1);
notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identity);
notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(2, notificationLogService.find(filter, null).getTotalElements());
filter.setFrom(from);
assertEquals(2, notificationLogService.find(filter, null).getTotalElements());
filter.setFrom(null);
filter.setTill(till);
assertEquals(0, notificationLogService.find(filter, null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testEmailFilterBySender.
@Test
public void testEmailFilterBySender() {
NotificationConfigurationDto config = createConfig();
// create templates
IdmNotificationTemplateDto template = createTestTemplate();
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setSender(InitTestDataProcessor.TEST_USER_2);
assertEquals(0, emailLogService.find(filter, null).getTotalElements());
filter.setSender(InitTestDataProcessor.TEST_USER_1);
assertEquals(0, emailLogService.find(filter, null).getTotalElements());
// send some email
IdmIdentityDto identity = identityService.getByUsername(InitTestDataProcessor.TEST_USER_1);
IdmIdentityDto identity2 = identityService.getByUsername(InitTestDataProcessor.TEST_USER_2);
emailService.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identity);
filter.setSender(null);
assertEquals(1, emailLogService.find(filter, null).getTotalElements());
filter.setSender(identity2.getUsername());
assertEquals(0, emailLogService.find(filter, null).getTotalElements());
filter.setSender(null);
filter.setRecipient(identity.getUsername());
assertEquals(1, emailLogService.find(filter, null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method createTestTemplate.
private IdmNotificationTemplateDto createTestTemplate() {
// create templates
IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
template.setName(getHelper().createName());
template.setBodyHtml(getHelper().createName());
template.setBodyText(template.getBodyHtml());
template.setCode(template.getName());
template.setSubject(getHelper().createName());
return notificationTemplateService.save(template);
}
Aggregations