use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class DeleteNotificationTaskExecutorIntegrationTest method testDeleteOldSentNotifications.
@Test
public void testDeleteOldSentNotifications() {
// prepare provisioning operations
ZonedDateTime createdOne = ZonedDateTime.now().minusDays(2);
String subject = UUID.randomUUID().toString();
IdmNotificationLogDto operationOne = createDto(subject, createdOne, NotificationState.ALL);
// all other variants for not removal
createDto(subject, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).plusMinutes(1), NotificationState.ALL);
createDto(subject, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).plusMinutes(1), NotificationState.NOT);
createDto(subject, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).plusMinutes(1), NotificationState.ALL);
createDto(subject, ZonedDateTime.now().minusDays(2), NotificationState.PARTLY);
createDto(subject, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).minusHours(22), NotificationState.ALL);
//
Assert.assertEquals(createdOne, operationOne.getCreated());
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setText(subject);
List<IdmNotificationLogDto> notifications = service.find(filter, null).getContent();
Assert.assertEquals(6, notifications.size());
//
DeleteNotificationTaskExecutor taskExecutor = new DeleteNotificationTaskExecutor();
Map<String, Object> properties = new HashMap<>();
properties.put(DeleteNotificationTaskExecutor.PARAMETER_NUMBER_OF_DAYS, 1);
properties.put(DeleteNotificationTaskExecutor.PARAMETER_SENT_ONLY, true);
AutowireHelper.autowire(taskExecutor);
taskExecutor.init(properties);
//
longRunningTaskManager.execute(taskExecutor);
//
notifications = service.find(filter, null).getContent();
Assert.assertEquals(5, notifications.size());
Assert.assertTrue(notifications.stream().allMatch(a -> !a.getId().equals(operationOne.getId())));
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testSendConfiguredNotificationAfterEnd.
@Test
public void testSendConfiguredNotificationAfterEnd() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity();
NotificationConfigurationDto config = createConfig(null, 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());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testNotSendDefaultNotificationWithoutLoggedIdentityAfterEnd.
@Test
public void testNotSendDefaultNotificationWithoutLoggedIdentityAfterEnd() throws Exception {
NotificationConfigurationDto config = createConfig(null, false);
//
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.setNotificationType(IdmNotificationLog.class);
List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
Assert.assertEquals(1, notifications.size());
Assert.assertEquals(NotificationState.NOT, notifications.get(0).getState());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testSendConfiguredRedirectNotificationAfterEnd.
@Test
public void testSendConfiguredRedirectNotificationAfterEnd() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity();
String recipient = getHelper().createName() + "@test-bcvsolutions.eu";
NotificationConfigurationDto config = createConfig(recipient, true);
//
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.assertTrue(notifications.isEmpty());
//
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.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());
}
Aggregations