use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testSendConfiguredAdditionalNotificationAfterEnd.
@Test
public void testSendConfiguredAdditionalNotificationAfterEnd() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity();
String recipient = getHelper().createName() + "@test-bcvsolutions.eu";
NotificationConfigurationDto config = createConfig(recipient, false);
//
try {
// report is sent to logged identity by default
getHelper().login(identity);
//
RptReportDto report = new RptReportDto();
report.setExecutorName(TestReportExecutor.REPORT_NAME);
IdmFormDto filter = new IdmFormDto();
TestReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestReportExecutor.class);
IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
IdmFormValueDto topic = new IdmFormValueDto(definition.getMappedAttributeByCode(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS));
topic.setValue(config.getTopic());
filter.getValues().add(topic);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
report = manager.generate(report);
UUID reportId = report.getId();
Assert.assertNotNull(reportId);
Assert.assertNotNull(report.getData());
//
try (InputStream is = attachmentManager.getAttachmentData(report.getData())) {
Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(is));
}
reportService.delete(report);
attachmentManager.deleteAttachments(report);
//
// test notification is sent
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setTopic(config.getTopic());
notificationFilter.setRecipient(identity.getUsername());
notificationFilter.setNotificationType(IdmNotificationLog.class);
List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
Assert.assertEquals(1, notifications.size());
//
IdmNotificationRecipientFilter recipientFilter = new IdmNotificationRecipientFilter();
recipientFilter.setRealRecipient(recipient);
List<IdmNotificationRecipientDto> recipients = notificationRecipientService.find(recipientFilter, null).getContent();
Assert.assertFalse(recipients.isEmpty());
Assert.assertEquals(config.getTopic(), notificationService.get(recipients.get(0).getNotification()).getTopic());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testSendDefaultNotificationAfterEnd.
@Test
public void testSendDefaultNotificationAfterEnd() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity();
//
try {
// report is sent to logged identity by default
getHelper().login(identity);
//
RptReportDto report = new RptReportDto();
report.setExecutorName(TestReportExecutor.REPORT_NAME);
report = manager.generate(report);
UUID reportId = report.getId();
Assert.assertNotNull(reportId);
Assert.assertNotNull(report.getData());
//
try (InputStream is = attachmentManager.getAttachmentData(report.getData())) {
Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(is));
}
//
// test notification is sent
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setTopic(RptModuleDescriptor.TOPIC_REPORT_GENERATE_SUCCESS);
notificationFilter.setRecipient(identity.getUsername());
notificationFilter.setNotificationType(IdmNotificationLog.class);
List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
Assert.assertEquals(1, notifications.size());
//
// test notification attachments
IdmNotificationAttachmentFilter notificationAttachmentFilter = new IdmNotificationAttachmentFilter();
notificationAttachmentFilter.setNotification(notifications.get(0).getId());
List<IdmNotificationAttachmentDto> notificationAttachments = notificationAttachmentService.find(notificationAttachmentFilter, null).getContent();
Assert.assertEquals(1, notificationAttachments.size());
Assert.assertNotNull(notificationAttachments.get(0).getAttachment());
//
reportService.delete(report);
attachmentManager.deleteAttachments(report);
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultAuthenticationManagerIntegrationTest method testBlockLoginCheckNotification.
@Test
public void testBlockLoginCheckNotification() {
IdmPasswordPolicyDto passwordPolicy = new IdmPasswordPolicyDto();
passwordPolicy.setName(getHelper().createName());
passwordPolicy.setDefaultPolicy(true);
passwordPolicy.setType(IdmPasswordPolicyType.VALIDATE);
passwordPolicy.setBlockLoginTime(2);
passwordPolicy.setMaxUnsuccessfulAttempts(2);
passwordPolicy = passwordPolicyService.save(passwordPolicy);
String testPassword = "testPassword" + System.currentTimeMillis();
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString(testPassword));
LoginDto loginDto = tryLogin(identity.getUsername(), testPassword);
checkLoginDto(loginDto);
String wrongPassword = "badPassword" + System.currentTimeMillis();
tryLoginExceptFail(identity.getUsername(), wrongPassword);
tryLoginExceptFail(identity.getUsername(), wrongPassword);
// block
tryLoginExceptFail(identity.getUsername(), wrongPassword);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setRecipient(identity.getUsername());
filter.setNotificationType(IdmEmailLog.class);
List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
assertEquals(1, notifications.size());
IdmNotificationLogDto notification = notifications.get(0);
IdmMessageDto message = notification.getMessage();
assertNotNull(message);
// hardcode text form template
assertTrue(message.getSubject().contains("login blocked"));
assertTrue(message.getHtmlMessage().contains("has been exceeded the number of unsuccessful logon attempts"));
assertTrue(message.getHtmlMessage().contains(identity.getUsername()));
passwordPolicyService.delete(passwordPolicy);
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendWithWrongAttachments.
@Test
public void testSendWithWrongAttachments() {
NotificationConfigurationDto config = createConfig();
IdmNotificationTemplateDto template = createTestTemplate();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
// attachment without content
IdmAttachmentDto attachment = attachmentManager.save(DefaultAttachmentManagerIntegrationTest.prepareDto());
//
List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), null, Lists.newArrayList(identity), Lists.newArrayList(attachment));
Assert.assertEquals(1, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> n.getType().equals(IdmEmailLog.NOTIFICATION_TYPE)));
//
IdmNotificationLogDto notification = notifications.get(0);
Assert.assertEquals(NotificationState.NOT, notification.getState());
//
IdmNotificationAttachmentFilter notificationAttachmentFilter = new IdmNotificationAttachmentFilter();
notificationAttachmentFilter.setNotification(notification.getId());
List<IdmNotificationAttachmentDto> notificationAttachments = notificationAttachmentService.find(notificationAttachmentFilter, null).getContent();
Assert.assertEquals(1, notificationAttachments.size());
Assert.assertTrue(notificationAttachments.stream().allMatch(na -> na.getAttachment() != null));
Assert.assertTrue(notificationAttachments.stream().anyMatch(na -> na.getAttachment().equals(attachment.getId())));
//
notificationLogService.delete(notification);
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testTextFilterTest.
@Test
public void testTextFilterTest() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmNotificationFilter filter = new IdmNotificationFilter();
//
// create templates
IdmNotificationTemplateDto template = createTestTemplate();
IdmNotificationTemplateDto template2 = createTestTemplate();
//
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(template2.getSubject());
result = notificationLogService.find(filter, null);
assertEquals("Wrong text message html", 1, result.getTotalElements());
}
Aggregations