use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter in project CzechIdMng by bcvsolutions.
the class IdmNotificationAttachmentControllerTest method testDownload.
@Test
public void testDownload() throws Exception {
NotificationConfigurationDto config = createConfig();
IdmNotificationTemplateDto template = createTestTemplate();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
//
IdmAttachmentDto attachmentOne = DefaultAttachmentManagerIntegrationTest.prepareDtoWithoutContent();
// prepared attachment
attachmentOne.setInputData(IOUtils.toInputStream(getHelper().createName()));
IdmAttachmentDto attachment = DefaultAttachmentManagerIntegrationTest.prepareDtoWithoutContent();
String content = getHelper().createName();
attachment.setInputData(IOUtils.toInputStream(content));
IdmAttachmentDto attachmentTwo = attachmentManager.saveAttachment(identity, attachment);
List<IdmAttachmentDto> attachments = Lists.newArrayList(attachmentOne, attachmentTwo);
//
List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), null, Lists.newArrayList(identity), attachments);
Assert.assertEquals(1, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> n.getType().equals(IdmEmailLog.NOTIFICATION_TYPE)));
//
IdmNotificationLogDto notification = notifications.get(0);
//
IdmNotificationAttachmentFilter notificationAttachmentFilter = new IdmNotificationAttachmentFilter();
notificationAttachmentFilter.setNotification(notification.getId());
List<IdmNotificationAttachmentDto> notificationAttachments = notificationAttachmentService.find(notificationAttachmentFilter, null).getContent();
Assert.assertEquals(2, notificationAttachments.size());
Assert.assertTrue(notificationAttachments.stream().allMatch(na -> na.getAttachment() != null));
Assert.assertTrue(notificationAttachments.stream().anyMatch(na -> na.getAttachment().equals(attachmentTwo.getId())));
IdmNotificationAttachmentDto notificationAttachment = notificationAttachments.stream().filter(na -> na.getAttachment().equals(attachmentTwo.getId())).findFirst().get();
//
// download attachment
String response = getMockMvc().perform(MockMvcRequestBuilders.get(getDetailUrl(notificationAttachment.getId()) + "/download").with(authentication(getAdminAuthentication()))).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
Assert.assertEquals(content, response);
//
// 404 - notification attachment not found
getMockMvc().perform(MockMvcRequestBuilders.get(getDetailUrl(UUID.randomUUID()) + "/download").with(authentication(getAdminAuthentication()))).andExpect(status().isNotFound());
//
// 404 - delete attachment (e.g. simulate ecm store purge)
attachmentManager.delete(attachmentTwo);
getMockMvc().perform(MockMvcRequestBuilders.get(getDetailUrl(notificationAttachment.getId()) + "/download").with(authentication(getAdminAuthentication()))).andExpect(status().isNotFound());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter in project CzechIdMng by bcvsolutions.
the class IdmNotificationAttachmentControllerTest method testFindByNotification.
@Test
public void testFindByNotification() {
IdmNotificationAttachmentDto attachmentOne = createDto();
// other
createDto();
//
IdmNotificationAttachmentFilter filter = new IdmNotificationAttachmentFilter();
filter.setNotification(attachmentOne.getNotification());
List<IdmNotificationAttachmentDto> attachments = find(filter);
Assert.assertEquals(1, attachments.size());
Assert.assertTrue(attachments.stream().anyMatch(r -> r.getId().equals(attachmentOne.getId())));
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter 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();
}
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter 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);
}
use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method testSendWithAttachments.
@Test
public void testSendWithAttachments() {
NotificationConfigurationDto config = createConfig();
IdmNotificationTemplateDto template = createTestTemplate();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
//
IdmAttachmentDto attachmentOne = DefaultAttachmentManagerIntegrationTest.prepareDtoWithoutContent();
// prepared attachment
attachmentOne.setInputData(IOUtils.toInputStream("mock-content"));
IdmAttachmentDto attachment = DefaultAttachmentManagerIntegrationTest.prepareDtoWithoutContent();
attachment.setInputData(IOUtils.toInputStream("mock-content"));
IdmAttachmentDto attachmentTwo = attachmentManager.saveAttachment(identity, attachment);
List<IdmAttachmentDto> attachments = Lists.newArrayList(attachmentOne, attachmentTwo);
//
List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), null, Lists.newArrayList(identity), attachments);
Assert.assertEquals(1, notifications.size());
Assert.assertTrue(notifications.stream().anyMatch(n -> n.getType().equals(IdmEmailLog.NOTIFICATION_TYPE)));
//
IdmNotificationLogDto notification = notifications.get(0);
//
IdmNotificationAttachmentFilter notificationAttachmentFilter = new IdmNotificationAttachmentFilter();
notificationAttachmentFilter.setNotification(notification.getId());
List<IdmNotificationAttachmentDto> notificationAttachments = notificationAttachmentService.find(notificationAttachmentFilter, null).getContent();
Assert.assertEquals(2, notificationAttachments.size());
Assert.assertTrue(notificationAttachments.stream().allMatch(na -> na.getAttachment() != null));
Assert.assertTrue(notificationAttachments.stream().anyMatch(na -> na.getAttachment().equals(attachmentTwo.getId())));
//
notificationLogService.delete(notification);
}
Aggregations