use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationTemplateServiceIntegrationTest method templateReferentialIntegrityTest.
@Test
public void templateReferentialIntegrityTest() {
IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
template.setCode(getHelper().createName());
template.setName(getHelper().createName());
template.setSubject(getHelper().createName());
template = notificationTemplateService.save(template);
// Template Dto successfully saved
IdmNotificationTemplateFilter templateFilter = new IdmNotificationTemplateFilter();
templateFilter.setText(template.getCode());
assertEquals(1, notificationTemplateService.find(templateFilter, null).getContent().size());
// Prevent from template deleting if used in notification configuration
NotificationConfigurationDto notificationCfgDto = new NotificationConfigurationDto(getHelper().createName(), NotificationLevel.INFO, getHelper().createName(), getHelper().createName(), template.getId());
notificationCfgDto = notificationConfigService.save(notificationCfgDto);
try {
notificationTemplateService.delete(template);
fail("Template deleted although used in a notification configuration.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
notificationConfigService.delete(notificationCfgDto);
// Found proper notification according to the used template
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
List<IdmEmailLogDto> emailLogDtos = emailSenderService.send(getHelper().createName(), message);
assertEquals(1, emailLogDtos.size());
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setTemplateId(template.getId());
List<IdmEmailLogDto> foundNotificationDtos = emailLogService.find(notificationFilter, null).getContent();
assertEquals(1, foundNotificationDtos.size());
assertEquals(emailLogDtos.get(0).getId(), foundNotificationDtos.get(0).getId());
// Prevent from template deleting if used in notification
try {
notificationTemplateService.delete(template);
fail("Template deleted although used in a notification.");
} catch (ResultCodeException e) {
// Success
} catch (Exception e) {
fail(e.getMessage());
}
emailLogService.delete(emailLogDtos.get(0));
// Template Dto successfully deleted
notificationTemplateService.delete(template);
assertEquals(0, notificationTemplateService.find(templateFilter, null).getContent().size());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testNotDisabledErrorWebsocket.
@Test
@Transactional
public void testNotDisabledErrorWebsocket() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, level, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), false));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(1, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testNotDisabled.
@Test
@Transactional
public void testNotDisabled() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, null, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), false));
configs.add(createNotificationConfiguration(TOPIC, null, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), false));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(2, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testDisabledErrorEmail.
@Test
@Transactional
public void testDisabledErrorEmail() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, level, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), true));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(0, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testOneDisabledError.
@Test
@Transactional
public void testOneDisabledError() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, level, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), false));
configs.add(createNotificationConfiguration(TOPIC, level, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), true));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(1, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
Aggregations