Search in sources :

Example 66 with IdmNotificationTemplateDto

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());
}
Also used : IdmNotificationTemplateFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) ConstraintViolationException(javax.validation.ConstraintViolationException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 67 with IdmNotificationTemplateDto

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());
}
Also used : IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 68 with IdmNotificationTemplateDto

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());
    }
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) ConstraintViolationException(javax.validation.ConstraintViolationException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 69 with IdmNotificationTemplateDto

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()));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) DecimalFormat(java.text.DecimalFormat) IOException(java.io.IOException) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) File(java.io.File) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 70 with IdmNotificationTemplateDto

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);
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)87 Test (org.junit.Test)68 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)53 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)42 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)42 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)31 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)23 NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)19 Transactional (org.springframework.transaction.annotation.Transactional)18 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)17 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)14 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)13 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)12 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)11 UUID (java.util.UUID)9 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)8 ZonedDateTime (java.time.ZonedDateTime)8 IdmNotificationDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto)7 IdmNotificationTemplateService (eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService)7 HashSet (java.util.HashSet)7