use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class IdentityMonitoredFieldsProcessorTest method sendNotificationTest.
@Test
public void sendNotificationTest() {
configurationService.setValue(PROCESSOR_KEY + "enabled", Boolean.TRUE.toString());
configurationService.setValue(PROCESSOR_KEY + IdentityMonitoredFieldsProcessor.PROPERTY_MONITORED_FIELDS, "firstName");
configurationService.setValue(PROCESSOR_KEY + IdentityMonitoredFieldsProcessor.PROPERTY_RECIPIENTS_ROLE, "superAdminRole");
//
IdmIdentityDto identity = helper.createIdentity();
List<IdmIdentityDto> recipients = identityService.findAllByRoleName("superAdminRole");
Assert.notEmpty(recipients, "Test need some recipients");
// Test before notify
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
filter.setRecipient(recipients.get(0).getUsername());
identity.setFirstName("changed" + UUID.randomUUID());
identity.setLastName("changed" + UUID.randomUUID());
identityService.save(identity);
// Test after notify
List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent().stream().filter(notification -> {
return notification.getTopic().equals(CoreModuleDescriptor.TOPIC_IDENTITY_MONITORED_CHANGED_FIELDS);
}).collect(Collectors.toList());
assertEquals(1, notifications.size());
assertEquals(CoreModuleDescriptor.TOPIC_IDENTITY_MONITORED_CHANGED_FIELDS, notifications.get(0).getTopic());
Assert.isTrue(notifications.get(0).getMessage().getHtmlMessage().contains(identity.getFirstName()));
// Last name is not monitored
Assert.isTrue(!notifications.get(0).getMessage().getHtmlMessage().contains(identity.getLastName()));
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testEmailFilterBySent.
@Test
@Transactional
public void testEmailFilterBySent() {
IdmIdentityDto identity = identityService.getByUsername(InitTestData.TEST_USER_1);
IdmNotificationFilter filter = new IdmNotificationFilter();
//
// create templates
IdmNotificationTemplateDto template = createTestTemplate("Idm notification", "subject");
//
emailService.send(new IdmMessageDto.Builder().setTemplate(template).build(), identity);
filter.setSent(true);
assertEquals(0, emailLogService.find(filter, null).getTotalElements());
emailService.send(new IdmMessageDto.Builder().setTemplate(template).build(), identity);
filter.setSent(false);
assertEquals(2, emailLogService.find(filter, null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method parentFilterText.
@Test
public void parentFilterText() {
IdmNotificationFilter filter = new IdmNotificationFilter();
IdmNotificationDto notification = new IdmNotificationDto();
IdmNotificationDto parentNotification = new IdmNotificationDto();
// prepare template and message
IdmNotificationTemplateDto template2 = createTestTemplate("TestTemplate5", "testSubject5");
IdmMessageDto message2 = new IdmMessageDto.Builder().setTemplate(template2).build();
// set parent
parentNotification.setMessage(message2);
IdmNotificationLogDto logDto = notificationManager.send(parentNotification);
notification.setParent(logDto.getMessage().getId());
//
// send message
IdmNotificationTemplateDto template = createTestTemplate("TestTemplate4", "testSubject4");
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
notification.setMessage(message);
notificationManager.send(notification);
// set filter
filter.setParent(logDto.getId());
Page<IdmNotificationLogDto> result = notificationLogService.find(filter, null);
assertEquals("Wrong sender", logDto.getId(), result.getContent().get(0).getParent());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method senderFilterTest.
@Test
public void senderFilterTest() {
IdmIdentityDto sender = helper.createIdentity();
IdmNotificationFilter filter = new IdmNotificationFilter();
IdmNotificationDto notification = new IdmNotificationDto();
notification.setIdentitySender(sender.getId());
//
// create templates
IdmNotificationTemplateDto template = createTestTemplate("TestTemplate3", "testSubject3");
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.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method textFilterTest.
@Test
public void textFilterTest() {
IdmIdentityDto identity = helper.createIdentity();
IdmNotificationFilter filter = new IdmNotificationFilter();
//
// create templates
IdmNotificationTemplateDto template = createTestTemplate("TestTemplate1", "testSubject");
IdmNotificationTemplateDto template2 = createTestTemplate("TestTemplate2", "testSubject2");
//
emailService.send(new IdmMessageDto.Builder().setTemplate(template).build(), identity);
emailService.send(new IdmMessageDto.Builder().setTemplate(template2).build(), identity);
// filter text BODY
filter.setText(template.getBodyText());
Page<IdmNotificationLogDto> result = notificationLogService.find(filter, null);
assertEquals("Wrong text message body", 1, result.getTotalElements());
// filter text HTML
filter.setText(template2.getBodyHtml());
result = notificationLogService.find(filter, null);
assertEquals("Wrong text message html", 1, result.getTotalElements());
// filter text subject
filter.setText(template.getSubject());
result = notificationLogService.find(filter, null);
assertEquals("Wrong text message html", 2, result.getTotalElements());
}
Aggregations