Search in sources :

Example 31 with IdmNotificationFilter

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

the class IdentityMonitoredFieldsProcessorTest method sendNotificationTest.

@Test
public void sendNotificationTest() {
    configurationService.setValue(PROCESSOR_KEY + "enabled", Boolean.TRUE.toString());
    configurationService.setValue(PROCESSOR_KEY + IdentityMonitoredFieldsProcessor.PROPERTY_MONITORED_FIELDS, "firstName");
    configurationService.setValue(PROCESSOR_KEY + IdentityMonitoredFieldsProcessor.PROPERTY_RECIPIENTS_ROLE, "superAdminRole");
    // 
    IdmIdentityDto identity = helper.createIdentity();
    List<IdmIdentityDto> recipients = identityService.findAllByRoleName("superAdminRole");
    Assert.notEmpty(recipients, "Test need some recipients");
    // Test before notify
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setNotificationType(IdmNotificationLog.class);
    filter.setRecipient(recipients.get(0).getUsername());
    identity.setFirstName("changed" + UUID.randomUUID());
    identity.setLastName("changed" + UUID.randomUUID());
    identityService.save(identity);
    // Test after notify
    List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent().stream().filter(notification -> {
        return notification.getTopic().equals(CoreModuleDescriptor.TOPIC_IDENTITY_MONITORED_CHANGED_FIELDS);
    }).collect(Collectors.toList());
    assertEquals(1, notifications.size());
    assertEquals(CoreModuleDescriptor.TOPIC_IDENTITY_MONITORED_CHANGED_FIELDS, notifications.get(0).getTopic());
    Assert.isTrue(notifications.get(0).getMessage().getHtmlMessage().contains(identity.getFirstName()));
    // Last name is not monitored
    Assert.isTrue(!notifications.get(0).getMessage().getHtmlMessage().contains(identity.getLastName()));
}
Also used : IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) InitTestData(eu.bcvsolutions.idm.InitTestData) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) UUID(java.util.UUID) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) Collectors(java.util.stream.Collectors) IdmNotificationLog(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationLog) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) List(java.util.List) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdentityMonitoredFieldsProcessor(eu.bcvsolutions.idm.core.model.event.processor.identity.IdentityMonitoredFieldsProcessor) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Assert(org.springframework.util.Assert) 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) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 32 with IdmNotificationFilter

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());
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) 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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with IdmNotificationFilter

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

the class DefaultNotificationServiceIntegrationTest method parentFilterText.

@Test
public void parentFilterText() {
    IdmNotificationFilter filter = new IdmNotificationFilter();
    IdmNotificationDto notification = new IdmNotificationDto();
    IdmNotificationDto parentNotification = new IdmNotificationDto();
    // prepare template and message
    IdmNotificationTemplateDto template2 = createTestTemplate("TestTemplate5", "testSubject5");
    IdmMessageDto message2 = new IdmMessageDto.Builder().setTemplate(template2).build();
    // set parent
    parentNotification.setMessage(message2);
    IdmNotificationLogDto logDto = notificationManager.send(parentNotification);
    notification.setParent(logDto.getMessage().getId());
    // 
    // send message
    IdmNotificationTemplateDto template = createTestTemplate("TestTemplate4", "testSubject4");
    IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
    notification.setMessage(message);
    notificationManager.send(notification);
    // set filter
    filter.setParent(logDto.getId());
    Page<IdmNotificationLogDto> result = notificationLogService.find(filter, null);
    assertEquals("Wrong sender", logDto.getId(), result.getContent().get(0).getParent());
}
Also used : IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) 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) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 34 with IdmNotificationFilter

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

the class DefaultNotificationServiceIntegrationTest method senderFilterTest.

@Test
public void senderFilterTest() {
    IdmIdentityDto sender = helper.createIdentity();
    IdmNotificationFilter filter = new IdmNotificationFilter();
    IdmNotificationDto notification = new IdmNotificationDto();
    notification.setIdentitySender(sender.getId());
    // 
    // create templates
    IdmNotificationTemplateDto template = createTestTemplate("TestTemplate3", "testSubject3");
    IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
    notification.setMessage(message);
    notificationManager.send(notification);
    // 
    // filter text BODY
    filter.setSender(sender.getUsername());
    Page<IdmNotificationLogDto> result = notificationLogService.find(filter, null);
    assertEquals("Wrong sender", sender.getId(), result.getContent().get(0).getIdentitySender());
}
Also used : IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) 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 35 with IdmNotificationFilter

use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter 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)

Aggregations

IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)53 Test (org.junit.Test)52 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)50 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)48 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)28 List (java.util.List)28 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)24 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)24 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)24 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)24 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)24 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)24 ArrayList (java.util.ArrayList)24 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)23 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)12 SysProvisioningBreakConfigDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto)10 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)7 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)7 InitTestData (eu.bcvsolutions.idm.InitTestData)4 CoreModuleDescriptor (eu.bcvsolutions.idm.core.CoreModuleDescriptor)4