Search in sources :

Example 56 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method textFilterTest.

@Test
public void textFilterTest() {
    IdmIdentityDto identity = helper.createIdentity();
    IdmNotificationFilter filter = new IdmNotificationFilter();
    // 
    // create templates
    IdmNotificationTemplateDto template = createTestTemplate("TestTemplate1", "testSubject");
    IdmNotificationTemplateDto template2 = createTestTemplate("TestTemplate2", "testSubject2");
    // 
    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(template.getSubject());
    result = notificationLogService.find(filter, null);
    assertEquals("Wrong text message html", 2, result.getTotalElements());
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 57 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method sendTwoWildCardsWithDifferentTemplate.

@Test
public void sendTwoWildCardsWithDifferentTemplate() {
    String topic = "testTopic-" + System.currentTimeMillis();
    String textTemplate1 = "testMessageTemplate1-" + System.currentTimeMillis();
    String textTemplate2 = "testMessageTemplate2-" + System.currentTimeMillis();
    // 
    IdmNotificationTemplateDto template1 = new IdmNotificationTemplateDto();
    template1.setName(textTemplate1);
    template1.setCode(textTemplate1);
    template1.setBodyHtml(textTemplate1);
    template1.setBodyText(textTemplate1);
    template1.setSubject(textTemplate1);
    template1 = notificationTemplateService.save(template1);
    // 
    IdmNotificationTemplateDto template2 = new IdmNotificationTemplateDto();
    template2.setName(textTemplate2);
    template2.setCode(textTemplate2);
    template2.setBodyHtml(textTemplate2);
    template2.setBodyText(textTemplate2);
    template2.setSubject(textTemplate2);
    template2 = notificationTemplateService.save(template2);
    // 
    IdmIdentityDto identity = helper.createIdentity();
    // create config, for email, topic, template and without level = wildcard
    NotificationConfigurationDto config1 = new NotificationConfigurationDto();
    // topic
    config1.setTopic(topic);
    // template
    config1.setTemplate(template1.getId());
    // email
    config1.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
    config1 = notificationConfigurationService.save(config1);
    // 
    // create second config, for console, topic, template and without level = wildcard
    NotificationConfigurationDto config = new NotificationConfigurationDto();
    // same topic
    config.setTopic(topic);
    // different template
    config.setTemplate(template2.getId());
    // console
    config.setNotificationType(IdmConsoleLog.NOTIFICATION_TYPE);
    config = notificationConfigurationService.save(config);
    // 
    List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
    NotificationLevel.SUCCESS).build(), identity);
    // 
    assertEquals(2, notifications.size());
    // 
    // 
    int orderConsole = 0;
    int orderEmail = 1;
    // we didn't know order
    if (!notifications.get(0).getMessage().getHtmlMessage().equals(textTemplate2)) {
        // email first
        orderConsole = 1;
        orderEmail = 0;
    }
    // 
    // Notification has different text
    IdmNotificationLogDto notificationConsole = notifications.get(orderConsole);
    assertEquals(textTemplate2, notificationConsole.getMessage().getHtmlMessage());
    assertEquals(textTemplate2, notificationConsole.getMessage().getSubject());
    assertEquals(textTemplate2, notificationConsole.getMessage().getTextMessage());
    // 
    IdmNotificationLogDto notificationEmail = notifications.get(orderEmail);
    assertEquals(textTemplate1, notificationEmail.getMessage().getHtmlMessage());
    assertEquals(textTemplate1, notificationEmail.getMessage().getSubject());
    assertEquals(textTemplate1, notificationEmail.getMessage().getTextMessage());
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 58 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method stateFilterTest.

@Test
@Ignore
public void stateFilterTest() {
    IdmIdentityDto identity1 = helper.createIdentity();
    IdmIdentityDto identity2 = helper.createIdentity();
    IdmIdentityDto identity3 = helper.createIdentity();
    IdmIdentityDto identity4 = helper.createIdentity();
    List<IdmIdentityDto> identities = Arrays.asList(identity1, identity2, identity3, identity4);
    IdmNotificationTemplateDto template = createTestTemplate("TestTemplate6", "testSubject6");
    IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
    notificationManager.send(message, identities);
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setState(NotificationState.ALL);
    Page<IdmNotificationLogDto> result = notificationLogService.find(filter, null);
    assertEquals("Wrong state ALL", 1, result.getTotalElements());
    filter.setState(NotificationState.NOT);
    Page<IdmNotificationLogDto> result2 = notificationLogService.find(filter, null);
    assertEquals("Wrong state NOT", 1, result2.getTotalElements());
    filter.setState(NotificationState.PARTLY);
    result = notificationLogService.find(filter, null);
    assertEquals("Wrong state PARTLY", 0, result.getTotalElements());
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) Ignore(org.junit.Ignore) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 59 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto 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);
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Arrays(java.util.Arrays) IdmNotificationRecipientService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationRecipientService) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationState(eu.bcvsolutions.idm.core.notification.api.domain.NotificationState) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmEmailLogService) Page(org.springframework.data.domain.Page) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) IdmNotificationTemplateService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmConsoleLog(eu.bcvsolutions.idm.core.notification.entity.IdmConsoleLog) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) IdmNotificationConfigurationRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationConfigurationRepository) IdmNotificationConfigurationService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationConfigurationService) Lists(com.google.common.collect.Lists) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) EmailNotificationSender(eu.bcvsolutions.idm.core.notification.api.service.EmailNotificationSender) Before(org.junit.Before) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLog(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationLog) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) IdmEmailLog(eu.bcvsolutions.idm.core.notification.entity.IdmEmailLog) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationAttachmentService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationAttachmentService) Transactional(org.springframework.transaction.annotation.Transactional) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 60 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto 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());
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) 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