use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendNotificationToAlias.
@Test
public void testSendNotificationToAlias() {
final IdmIdentityDto originalRecipient = getHelper().createIdentity((GuardedString) null);
NotificationConfigurationDto config = new NotificationConfigurationDto();
config.setTopic(getHelper().createName());
config.setNotificationType(IdmConsoleLog.NOTIFICATION_TYPE);
config.setRecipients("one,two,two,two");
config.setRedirect(false);
//
// we are using repository directly - validations are on the service layer
config = notificationConfigurationService.save(config);
//
String subject = getHelper().createName();
List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).setMessage("message").setSubject(subject).build(), originalRecipient);
//
Assert.assertEquals(2, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> {
return n.getRecipients().size() == 1 && originalRecipient.getId().equals(n.getRecipients().get(0).getIdentityRecipient());
}));
Assert.assertTrue(notifications.stream().anyMatch(n -> {
return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> "one".equals(r.getRealRecipient())) && n.getRecipients().stream().anyMatch(r -> "two".equals(r.getRealRecipient()));
}));
//
// test by filter
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setText(subject);
// envelope only
filter.setNotificationType(IdmNotificationLog.class);
notifications = notificationLogService.find(filter, null).getContent();
//
Assert.assertEquals(2, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> {
return n.getRecipients().size() == 1 && originalRecipient.getId().equals(n.getRecipients().get(0).getIdentityRecipient());
}));
Assert.assertTrue(notifications.stream().anyMatch(n -> {
return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> "one".equals(r.getRealRecipient())) && n.getRecipients().stream().anyMatch(r -> "two".equals(r.getRealRecipient()));
}));
//
// target sender
filter.setNotificationType(IdmConsoleLog.class);
notifications = notificationLogService.find(filter, null).getContent();
//
Assert.assertEquals(2, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> {
return n.getRecipients().size() == 1 && originalRecipient.getId().equals(n.getRecipients().get(0).getIdentityRecipient());
}));
Assert.assertTrue(notifications.stream().anyMatch(n -> {
return n.getRecipients().size() == 2 && n.getRecipients().stream().allMatch(r -> IdmConsoleLog.NOTIFICATION_TYPE.equals(r.getRealRecipient()));
}));
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto 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.IdmNotificationLogDto 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.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendNotificationToAliasWithRedirect.
@Test
public void testSendNotificationToAliasWithRedirect() {
final IdmIdentityDto originalRecipient = getHelper().createIdentity((GuardedString) null);
NotificationConfigurationDto config = new NotificationConfigurationDto();
config.setTopic(getHelper().createName());
config.setNotificationType(IdmConsoleLog.NOTIFICATION_TYPE);
config.setRecipients("one,two,two,two");
config.setRedirect(true);
//
// we are using repository directly - validations are on the service layer
config = notificationConfigurationService.save(config);
//
String subject = getHelper().createName();
List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).setMessage("message").setSubject(subject).build(), originalRecipient);
//
Assert.assertEquals(1, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> {
return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> "one".equals(r.getRealRecipient())) && n.getRecipients().stream().anyMatch(r -> "two".equals(r.getRealRecipient()));
}));
//
// test by filter
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setText(subject);
// envelope only
filter.setNotificationType(IdmNotificationLog.class);
notifications = notificationLogService.find(filter, null).getContent();
//
Assert.assertEquals(1, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> {
return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> "one".equals(r.getRealRecipient())) && n.getRecipients().stream().anyMatch(r -> "two".equals(r.getRealRecipient()));
}));
//
// target sender
filter.setNotificationType(IdmConsoleLog.class);
notifications = notificationLogService.find(filter, null).getContent();
//
Assert.assertEquals(1, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> {
return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> IdmConsoleLog.NOTIFICATION_TYPE.equals(r.getRealRecipient()));
}));
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class IdmNotificationLogControllerRestTest method prepareDto.
@Override
protected IdmNotificationLogDto prepareDto() {
IdmIdentityDto recipient = getHelper().createIdentity((GuardedString) null);
IdmNotificationLogDto dto = new IdmNotificationLogDto();
dto.setMessage(new IdmMessageDto.Builder(NotificationLevel.SUCCESS).setMessage(getHelper().createName()).build());
dto.getRecipients().add(new IdmNotificationRecipientDto(recipient.getId()));
//
return dto;
}
Aggregations