use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto 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.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class NotificationSmtpTest method C_sendEmailWithAttachments.
/**
* Smtp email model don't contain attachments - it's tested, if attachment are not lost diring processing only.
*/
@Test
public void C_sendEmailWithAttachments() {
// create config
NotificationConfigurationDto config = new NotificationConfigurationDto();
config.setTopic(TOPIC);
config.setLevel(NotificationLevel.SUCCESS);
config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
config = notificationConfigurationService.save(config);
String textHtml = "textHtml-" + System.currentTimeMillis();
String textText = "textText-" + System.currentTimeMillis();
String subject = "subject-" + System.currentTimeMillis();
IdmIdentityDto identity = helper.createIdentity();
identity.setEmail("example@example.tld");
identity = identityService.save(identity);
IdmAttachmentDto attachment = new IdmAttachmentDto();
attachment.setName("rest2.txt");
attachment.setInputData(IOUtils.toInputStream("test txt content 1234567899 ě+ščřžýáííéáýžřčšě+;ěščřžýáíééů", AttachableEntity.DEFAULT_CHARSET));
attachment.setEncoding(AttachableEntity.DEFAULT_ENCODING);
attachment.setMimetype("text/plain");
List<IdmNotificationLogDto> send = notificationManager.send(TOPIC, new IdmMessageDto.Builder().setTextMessage(textText).setHtmlMessage(textHtml).setSubject(subject).setLevel(NotificationLevel.SUCCESS).build(), null, Lists.newArrayList(identity), Lists.newArrayList(attachment));
assertEquals(attachment.getName(), send.get(0).getAttachments().get(0).getName());
notificationConfigurationService.delete(config);
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessorTest method testDisableDeleteOperation.
@Test
public void testDisableDeleteOperation() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identity2 = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identity3 = getHelper().createIdentity((GuardedString) null);
SysProvisioningBreakConfigDto breakConfig = createProvisioningBreak(20l, 2, null, ProvisioningEventType.DELETE, system.getId());
IdmIdentityDto recipient = getHelper().createIdentity((GuardedString) null);
createRecipient(breakConfig.getId(), recipient.getId(), null);
//
this.createAccount(system, identity);
this.createAccount(system, identity2);
this.createAccount(system, identity3);
//
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity2);
provisioningService.doProvisioning(identity3);
//
identityService.delete(identity);
identityService.delete(identity2);
identityService.delete(identity3);
//
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setRecipient(recipient.getUsername());
List<IdmNotificationLogDto> content = notificationLogService.find(filter, null).getContent();
// two notification (notification +
assertEquals(2, content.size());
// parent)
//
system = systemService.get(system.getId());
assertNotEquals(Boolean.TRUE, system.getBlockedOperation().getUpdateOperation());
assertNotEquals(Boolean.TRUE, system.getBlockedOperation().getCreateOperation());
assertEquals(Boolean.TRUE, system.getBlockedOperation().getDeleteOperation());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessorTest method testWarningUpdateOperation.
@Test
public void testWarningUpdateOperation() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
SysProvisioningBreakConfigDto breakConfig = createProvisioningBreak(20l, null, 2, ProvisioningEventType.UPDATE, system.getId());
IdmIdentityDto recipient = getHelper().createIdentity((GuardedString) null);
createRecipient(breakConfig.getId(), recipient.getId(), null);
//
this.createAccount(system, identity);
//
//
// create
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
//
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setRecipient(recipient.getUsername());
List<IdmNotificationLogDto> content = notificationLogService.find(filter, null).getContent();
// two notification (notification +
assertEquals(2, content.size());
// parent)
//
system = systemService.get(system.getId());
assertNotEquals(Boolean.TRUE, system.getBlockedOperation().getUpdateOperation());
assertNotEquals(Boolean.TRUE, system.getBlockedOperation().getCreateOperation());
assertNotEquals(Boolean.TRUE, system.getBlockedOperation().getDeleteOperation());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessorTest method testWarningDeleteOperation.
@Test
public void testWarningDeleteOperation() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identity2 = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identity3 = getHelper().createIdentity((GuardedString) null);
SysProvisioningBreakConfigDto breakConfig = createProvisioningBreak(20l, null, 2, ProvisioningEventType.DELETE, system.getId());
IdmIdentityDto recipient = getHelper().createIdentity((GuardedString) null);
createRecipient(breakConfig.getId(), recipient.getId(), null);
//
this.createAccount(system, identity);
this.createAccount(system, identity2);
this.createAccount(system, identity3);
//
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity2);
provisioningService.doProvisioning(identity3);
//
identityService.delete(identity);
identityService.delete(identity2);
identityService.delete(identity3);
//
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setRecipient(recipient.getUsername());
List<IdmNotificationLogDto> content = notificationLogService.find(filter, null).getContent();
// two notification (notification +
assertEquals(2, content.size());
// parent)
//
system = systemService.get(system.getId());
assertNotEquals(Boolean.TRUE, system.getBlockedOperation().getUpdateOperation());
assertNotEquals(Boolean.TRUE, system.getBlockedOperation().getCreateOperation());
assertNotEquals(Boolean.TRUE, system.getBlockedOperation().getDeleteOperation());
}
Aggregations