use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto 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.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationTemplateServiceIntegrationTest method initFromMultipleLocations.
@Test
public void initFromMultipleLocations() {
IdmNotificationTemplateDto templateTwo = notificationTemplateService.getByCode(TEST_TEMPLATE_TWO);
IdmNotificationTemplateDto templateOverride = notificationTemplateService.getByCode(TEST_TEMPLATE_OVERRIDE);
assertNotNull(templateTwo);
assertNotNull(templateOverride);
assertEquals(TEST_TEMPLATE_TWO, templateTwo.getCode());
assertEquals(TEST_TEMPLATE_OVERRIDE, templateOverride.getCode());
//
assertEquals("CzechIdM - test isOverriden", templateOverride.getSubject());
assertEquals("isOverriden", templateOverride.getBodyHtml().trim());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationTemplateServiceIntegrationTest method redeployNewTemplate.
@Test
public void redeployNewTemplate() {
IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
String name = "temp_" + System.currentTimeMillis();
template.setCode(name);
template.setName(name);
template.setBodyText(name);
template.setSubject(name);
template = notificationTemplateService.save(template);
// check exception
try {
notificationTemplateService.redeploy(template);
fail();
} catch (Exception e) {
assertTrue(e instanceof ResultCodeException);
ResultCodeException resultCode = (ResultCodeException) e;
assertEquals(resultCode.getError().getError().getStatusEnum(), CoreResultCode.NOTIFICATION_TEMPLATE_XML_FILE_NOT_FOUND.name());
}
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationTemplateServiceIntegrationTest method redeployExistTemplateAndCheckBackup.
@Test
public void redeployExistTemplateAndCheckBackup() {
// check if exist directory and remove it with all files in
String backupFolder = "/tmp/idm_test_backup/";
//
File directory = new File(backupFolder);
if (directory.exists() && directory.isDirectory()) {
try {
FileUtils.deleteDirectory(directory);
} catch (IOException e) {
fail();
}
}
//
configurationService.setValue(DefaultIdmNotificationTemplateService.BACKUP_FOLDER_CONFIG, backupFolder);
//
IdmNotificationTemplateDto testTemplate = notificationTemplateService.getByCode(TEST_TEMPLATE);
Assert.assertNotNull(testTemplate);
assertEquals(TEST_TEMPLATE, testTemplate.getCode());
//
IdmNotificationTemplateDto testTemplateNew = notificationTemplateService.redeploy(testTemplate);
//
assertEquals(testTemplateNew.getId(), testTemplate.getId());
//
// after redeploy check directory
ZonedDateTime date = ZonedDateTime.now();
DecimalFormat decimalFormat = new DecimalFormat("00");
directory = new File(backupFolder + "templates/" + date.getYear() + decimalFormat.format(date.getMonthValue()) + decimalFormat.format(date.getDayOfMonth()) + "/");
assertTrue(directory.exists());
assertTrue(directory.isDirectory());
//
File[] files = directory.listFiles();
assertEquals(1, files.length);
File backup = files[0];
assertTrue(backup.exists());
assertTrue(backup.getName().contains(SpinalCase.format(InitTestDataProcessor.TEST_USER_1)));
assertTrue(backup.getName().contains(testTemplateNew.getCode()));
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationTemplateServiceIntegrationTest method evaluateEmptyText.
@Test
public void evaluateEmptyText() {
IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
template.setCode(getHelper().createName());
template.setName(getHelper().createName());
template.setSubject(getHelper().createName());
template.setBodyHtml(getHelper().createName());
template = notificationTemplateService.save(template);
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
notificationTemplateService.buildMessage(message);
}
Aggregations