use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testFilterByTopic.
@Test
public void testFilterByTopic() {
IdmNotificationTemplateDto template = createTestTemplate();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
NotificationConfigurationDto config = createConfig();
//
notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
// Test there is just one filtered log record.
filter.setTopic(config.getTopic());
List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
//
Assert.assertEquals(2, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> n.getType().equals(IdmNotificationLog.NOTIFICATION_TYPE)));
Assert.assertTrue(notifications.stream().anyMatch(n -> n.getType().equals(IdmEmailLog.NOTIFICATION_TYPE)));
// Test there is none log record after setting the filter to non-existing value.
filter.setTopic("nonexistingTopic-147258369");
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 testReferentialIntegrity.
@Test
public void testReferentialIntegrity() {
// delete recipients and children
NotificationConfigurationDto config = createConfig();
IdmNotificationTemplateDto template = createTestTemplate();
IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identitySender = getHelper().createIdentity((GuardedString) null);
List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identitySender, Lists.newArrayList(identityOne, identityTwo));
Assert.assertEquals(1, notifications.size());
List<IdmNotificationLogDto> notificationOthers = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identitySender, Lists.newArrayList(identityOne, identityTwo));
Assert.assertEquals(1, notificationOthers.size());
IdmNotificationLogDto notificationOther = notificationLogService.get(notificationOthers.get(0));
//
IdmNotificationLogDto notification = notificationLogService.get(notifications.get(0));
Assert.assertNotNull(notification);
Assert.assertEquals(identitySender.getId(), notification.getIdentitySender());
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setParent(notification.getId());
List<IdmEmailLogDto> emails = emailLogService.find(notificationFilter, null).getContent();
Assert.assertEquals(1, emails.size());
IdmEmailLogDto emailNotification = emails.get(0);
Assert.assertEquals(notification.getId(), emailNotification.getParent());
//
IdmNotificationRecipientFilter recipientFilter = new IdmNotificationRecipientFilter();
recipientFilter.setNotification(notification.getId());
List<IdmNotificationRecipientDto> notificationRecipients = recipientService.find(recipientFilter, null).getContent();
Assert.assertEquals(2, notificationRecipients.size());
Assert.assertTrue(notificationRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityOne.getId())));
Assert.assertTrue(notificationRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityTwo.getId())));
recipientFilter.setNotification(emailNotification.getId());
List<IdmNotificationRecipientDto> emailRecipients = recipientService.find(recipientFilter, null).getContent();
Assert.assertEquals(2, emailRecipients.size());
Assert.assertTrue(emailRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityOne.getId())));
Assert.assertTrue(emailRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityTwo.getId())));
//
// sender is removed from notifications when sender identity was deleted
IdmNotificationFilter senderFilter = new IdmNotificationFilter();
senderFilter.setIdentitySender(identitySender.getId());
List<IdmNotificationLogDto> notificationLogDtos = notificationLogService.find(senderFilter, null).getContent();
Assert.assertFalse(notificationLogDtos.isEmpty());
notificationLogDtos.forEach(notif -> {
Assert.assertEquals(identitySender.getId(), notif.getIdentitySender());
});
identityService.delete(identitySender);
Assert.assertNull(identityService.get(identitySender.getId()));
// shouldn't throw despite the fact that identitySender contained in notificationLogDtos has been deleted
notificationLogDtos = notificationLogService.find(senderFilter, null).getContent();
//
// create notifications and attachments
// other owner
IdmAttachmentDto attachmentOther = attachmentManager.save(DefaultAttachmentManagerIntegrationTest.prepareDto());
IdmAttachmentDto attachment = DefaultAttachmentManagerIntegrationTest.prepareDto();
attachment.setOwnerType(null);
attachment.setInputData(IOUtils.toInputStream("mock content"));
attachment = attachmentManager.saveAttachment(notification, attachment);
//
IdmNotificationAttachmentDto notificationAttachment = new IdmNotificationAttachmentDto();
notificationAttachment.setAttachment(attachment.getId());
notificationAttachment.setName(attachment.getName());
notificationAttachment.setNotification(notification.getId());
notificationAttachment = notificationAttachmentService.save(notificationAttachment);
Assert.assertNotNull(attachmentManager.get(attachment));
Assert.assertNotNull(notificationAttachmentService.get(notificationAttachment));
//
IdmNotificationAttachmentDto notificationAttachmentOther = new IdmNotificationAttachmentDto();
notificationAttachmentOther.setAttachment(attachmentOther.getId());
notificationAttachmentOther.setName(attachmentOther.getName());
notificationAttachmentOther.setNotification(notificationOther.getId());
notificationAttachmentOther = notificationAttachmentService.save(notificationAttachmentOther);
Assert.assertNotNull(attachmentManager.get(attachmentOther));
Assert.assertNotNull(notificationAttachmentService.get(notificationAttachmentOther));
//
// delete parent notification
notificationLogService.delete(notification);
//
// all removed
Assert.assertNull(notificationLogService.get(notification));
Assert.assertNull(notificationLogService.get(emailNotification));
recipientFilter.setNotification(notification.getId());
Assert.assertTrue(recipientService.find(recipientFilter, null).getContent().isEmpty());
recipientFilter.setNotification(emailNotification.getId());
Assert.assertTrue(recipientService.find(recipientFilter, null).getContent().isEmpty());
Assert.assertNull(attachmentManager.get(attachment));
Assert.assertNotNull(attachmentManager.get(attachmentOther));
Assert.assertNull(notificationAttachmentService.get(notificationAttachment));
Assert.assertNotNull(notificationAttachmentService.get(notificationAttachmentOther));
//
notificationLogService.delete(notificationOther);
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendWithAttachments.
@Test
public void testSendWithAttachments() {
NotificationConfigurationDto config = createConfig();
IdmNotificationTemplateDto template = createTestTemplate();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
//
IdmAttachmentDto attachmentOne = DefaultAttachmentManagerIntegrationTest.prepareDtoWithoutContent();
// prepared attachment
attachmentOne.setInputData(IOUtils.toInputStream("mock-content"));
IdmAttachmentDto attachment = DefaultAttachmentManagerIntegrationTest.prepareDtoWithoutContent();
attachment.setInputData(IOUtils.toInputStream("mock-content"));
IdmAttachmentDto attachmentTwo = attachmentManager.saveAttachment(identity, attachment);
List<IdmAttachmentDto> attachments = Lists.newArrayList(attachmentOne, attachmentTwo);
//
List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), null, Lists.newArrayList(identity), attachments);
Assert.assertEquals(1, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> n.getType().equals(IdmEmailLog.NOTIFICATION_TYPE)));
//
IdmNotificationLogDto notification = notifications.get(0);
//
IdmNotificationAttachmentFilter notificationAttachmentFilter = new IdmNotificationAttachmentFilter();
notificationAttachmentFilter.setNotification(notification.getId());
List<IdmNotificationAttachmentDto> notificationAttachments = notificationAttachmentService.find(notificationAttachmentFilter, null).getContent();
Assert.assertEquals(2, notificationAttachments.size());
Assert.assertTrue(notificationAttachments.stream().allMatch(na -> na.getAttachment() != null));
Assert.assertTrue(notificationAttachments.stream().anyMatch(na -> na.getAttachment().equals(attachmentTwo.getId())));
//
notificationLogService.delete(notification);
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testParentFilterText.
@Test
public void testParentFilterText() {
IdmNotificationFilter filter = new IdmNotificationFilter();
IdmNotificationDto notification = new IdmNotificationDto();
IdmNotificationDto parentNotification = new IdmNotificationDto();
// prepare template and message
IdmNotificationTemplateDto template2 = createTestTemplate();
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();
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.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendWildCardsWithTemplateWithoutText.
@Test
public void testSendWildCardsWithTemplateWithoutText() {
String topic = "testTopic-" + 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);
//
List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
NotificationLevel.SUCCESS).build(), identity);
//
assertEquals(1, notifications.size());
//
IdmNotificationLogDto notification = notifications.get(0);
// topic has own template and in message isnt set text
assertEquals(textTemplate, notification.getMessage().getHtmlMessage());
assertEquals(textTemplate, notification.getMessage().getSubject());
assertEquals(textTemplate, notification.getMessage().getTextMessage());
}
Aggregations