Search in sources :

Example 76 with IdmNotificationLogDto

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

the class DefaultRptReportManagerIntegrationTest method testSendConfiguredAdditionalNotificationAfterEnd.

@Test
public void testSendConfiguredAdditionalNotificationAfterEnd() throws Exception {
    IdmIdentityDto identity = getHelper().createIdentity();
    String recipient = getHelper().createName() + "@test-bcvsolutions.eu";
    NotificationConfigurationDto config = createConfig(recipient, false);
    // 
    try {
        // report is sent to logged identity by default
        getHelper().login(identity);
        // 
        RptReportDto report = new RptReportDto();
        report.setExecutorName(TestReportExecutor.REPORT_NAME);
        IdmFormDto filter = new IdmFormDto();
        TestReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestReportExecutor.class);
        IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
        IdmFormValueDto topic = new IdmFormValueDto(definition.getMappedAttributeByCode(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS));
        topic.setValue(config.getTopic());
        filter.getValues().add(topic);
        filter.setFormDefinition(definition.getId());
        report.setFilter(filter);
        report = manager.generate(report);
        UUID reportId = report.getId();
        Assert.assertNotNull(reportId);
        Assert.assertNotNull(report.getData());
        // 
        try (InputStream is = attachmentManager.getAttachmentData(report.getData())) {
            Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(is));
        }
        reportService.delete(report);
        attachmentManager.deleteAttachments(report);
        // 
        // test notification is sent
        IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
        notificationFilter.setTopic(config.getTopic());
        notificationFilter.setRecipient(identity.getUsername());
        notificationFilter.setNotificationType(IdmNotificationLog.class);
        List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
        Assert.assertEquals(1, notifications.size());
        // 
        IdmNotificationRecipientFilter recipientFilter = new IdmNotificationRecipientFilter();
        recipientFilter.setRealRecipient(recipient);
        List<IdmNotificationRecipientDto> recipients = notificationRecipientService.find(recipientFilter, null).getContent();
        Assert.assertFalse(recipients.isEmpty());
        Assert.assertEquals(config.getTopic(), notificationService.get(recipients.get(0).getNotification()).getTopic());
    } finally {
        logout();
    }
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) InputStream(java.io.InputStream) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 77 with IdmNotificationLogDto

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

the class DefaultRptReportManagerIntegrationTest method testSendDefaultNotificationAfterEnd.

@Test
public void testSendDefaultNotificationAfterEnd() throws Exception {
    IdmIdentityDto identity = getHelper().createIdentity();
    // 
    try {
        // report is sent to logged identity by default
        getHelper().login(identity);
        // 
        RptReportDto report = new RptReportDto();
        report.setExecutorName(TestReportExecutor.REPORT_NAME);
        report = manager.generate(report);
        UUID reportId = report.getId();
        Assert.assertNotNull(reportId);
        Assert.assertNotNull(report.getData());
        // 
        try (InputStream is = attachmentManager.getAttachmentData(report.getData())) {
            Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(is));
        }
        // 
        // test notification is sent
        IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
        notificationFilter.setTopic(RptModuleDescriptor.TOPIC_REPORT_GENERATE_SUCCESS);
        notificationFilter.setRecipient(identity.getUsername());
        notificationFilter.setNotificationType(IdmNotificationLog.class);
        List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
        Assert.assertEquals(1, notifications.size());
        // 
        // test notification attachments
        IdmNotificationAttachmentFilter notificationAttachmentFilter = new IdmNotificationAttachmentFilter();
        notificationAttachmentFilter.setNotification(notifications.get(0).getId());
        List<IdmNotificationAttachmentDto> notificationAttachments = notificationAttachmentService.find(notificationAttachmentFilter, null).getContent();
        Assert.assertEquals(1, notificationAttachments.size());
        Assert.assertNotNull(notificationAttachments.get(0).getAttachment());
        // 
        reportService.delete(report);
        attachmentManager.deleteAttachments(report);
    } finally {
        logout();
    }
}
Also used : IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) InputStream(java.io.InputStream) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 78 with IdmNotificationLogDto

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

the class DefaultAuthenticationManagerIntegrationTest method testBlockLoginCheckNotification.

@Test
public void testBlockLoginCheckNotification() {
    IdmPasswordPolicyDto passwordPolicy = new IdmPasswordPolicyDto();
    passwordPolicy.setName(getHelper().createName());
    passwordPolicy.setDefaultPolicy(true);
    passwordPolicy.setType(IdmPasswordPolicyType.VALIDATE);
    passwordPolicy.setBlockLoginTime(2);
    passwordPolicy.setMaxUnsuccessfulAttempts(2);
    passwordPolicy = passwordPolicyService.save(passwordPolicy);
    String testPassword = "testPassword" + System.currentTimeMillis();
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString(testPassword));
    LoginDto loginDto = tryLogin(identity.getUsername(), testPassword);
    checkLoginDto(loginDto);
    String wrongPassword = "badPassword" + System.currentTimeMillis();
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    // block
    tryLoginExceptFail(identity.getUsername(), wrongPassword);
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setRecipient(identity.getUsername());
    filter.setNotificationType(IdmEmailLog.class);
    List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
    assertEquals(1, notifications.size());
    IdmNotificationLogDto notification = notifications.get(0);
    IdmMessageDto message = notification.getMessage();
    assertNotNull(message);
    // hardcode text form template
    assertTrue(message.getSubject().contains("login blocked"));
    assertTrue(message.getHtmlMessage().contains("has been exceeded the number of unsuccessful logon attempts"));
    assertTrue(message.getHtmlMessage().contains(identity.getUsername()));
    passwordPolicyService.delete(passwordPolicy);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 79 with IdmNotificationLogDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto 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 80 with IdmNotificationLogDto

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

IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)107 Test (org.junit.Test)97 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)93 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)82 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)63 List (java.util.List)40 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)33 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)33 ZonedDateTime (java.time.ZonedDateTime)32 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)28 NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)28 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)26 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)26 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)26 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)26 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)25 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)25 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)23 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)20 UUID (java.util.UUID)18