1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.persistence.jpa.inner;
20
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22 import static org.junit.jupiter.api.Assertions.assertNotNull;
23 import static org.junit.jupiter.api.Assertions.assertNull;
24
25 import java.util.List;
26 import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
27 import org.apache.syncope.core.persistence.api.dao.MailTemplateDAO;
28 import org.apache.syncope.core.persistence.api.dao.NotificationDAO;
29 import org.apache.syncope.core.persistence.api.entity.AnyAbout;
30 import org.apache.syncope.core.persistence.api.entity.Notification;
31 import org.apache.syncope.core.persistence.jpa.AbstractTest;
32 import org.junit.jupiter.api.Test;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.transaction.annotation.Transactional;
35
36 @Transactional("Master")
37 public class NotificationTest extends AbstractTest {
38
39 @Autowired
40 private AnyTypeDAO anyTypeDAO;
41
42 @Autowired
43 private NotificationDAO notificationDAO;
44
45 @Autowired
46 private MailTemplateDAO mailTemplateDAO;
47
48 @Test
49 public void find() {
50 Notification notification = notificationDAO.find("9e2b911c-25de-4c77-bcea-b86ed9451050");
51 assertNotNull(notification);
52 assertNotNull(notification.getEvents());
53 assertFalse(notification.getEvents().isEmpty());
54 assertNotNull(notification.getAbout(anyTypeDAO.findUser()));
55 assertNotNull(notification.getRecipientsFIQL());
56
57 }
58
59 @Test
60 public void findAll() {
61 List<Notification> notifications = notificationDAO.findAll();
62 assertNotNull(notifications);
63 assertFalse(notifications.isEmpty());
64 }
65
66 @Test
67 public void save() {
68 Notification notification = entityFactory.newEntity(Notification.class);
69 notification.getEvents().add("save");
70
71 AnyAbout about = entityFactory.newEntity(AnyAbout.class);
72 about.setNotification(notification);
73 notification.add(about);
74 about.setAnyType(anyTypeDAO.findUser());
75 about.set("fake search condition");
76
77 notification.setRecipientsFIQL("fake recipients");
78
79 notification.setRecipientAttrName("email");
80
81 notification.setSender("syncope@syncope.apache.org");
82 notification.setSubject("Test notification");
83 notification.setTemplate(mailTemplateDAO.find("test"));
84
85 Notification actual = notificationDAO.save(notification);
86 assertNotNull(actual);
87 assertNotNull(actual.getKey());
88 }
89
90 @Test
91 public void delete() {
92 notificationDAO.delete("9e2b911c-25de-4c77-bcea-b86ed9451050");
93 assertNull(notificationDAO.find("9e2b911c-25de-4c77-bcea-b86ed9451050"));
94 }
95
96 @Test
97 public void issueSYNCOPE445() {
98 Notification notification = entityFactory.newEntity(Notification.class);
99 notification.getEvents().add("save");
100
101 AnyAbout about = entityFactory.newEntity(AnyAbout.class);
102 about.setNotification(notification);
103 notification.add(about);
104 about.setAnyType(anyTypeDAO.findUser());
105 about.set("fake search condition");
106
107 notification.setRecipientsFIQL("fake search condition");
108
109 notification.setRecipientAttrName("email");
110
111 notification.getStaticRecipients().add("syncope445@syncope.apache.org");
112
113 notification.setSender("syncope@syncope.apache.org");
114 notification.setSubject("Test notification");
115 notification.setTemplate(mailTemplateDAO.find("test"));
116
117 notification = notificationDAO.save(notification);
118
119 entityManager().flush();
120
121 Notification actual = notificationDAO.find(notification.getKey());
122 assertNotNull(actual);
123 assertNotNull(actual.getKey());
124 assertNotNull(actual.getStaticRecipients());
125 assertFalse(actual.getStaticRecipients().isEmpty());
126 }
127
128 @Test
129 public void issueSYNCOPE446() {
130 Notification notification = entityFactory.newEntity(Notification.class);
131 notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
132
133 AnyAbout about = entityFactory.newEntity(AnyAbout.class);
134 about.setNotification(notification);
135 notification.add(about);
136 about.setAnyType(anyTypeDAO.findUser());
137 about.set("fake search condition");
138
139 notification.setRecipientAttrName("email");
140
141 notification.getStaticRecipients().add("syncope446@syncope.apache.org");
142
143 notification.setSender("syncope@syncope.apache.org");
144 notification.setSubject("Test notification");
145 notification.setTemplate(mailTemplateDAO.find("test"));
146
147 notification = notificationDAO.save(notification);
148
149 entityManager().flush();
150
151 Notification actual = notificationDAO.find(notification.getKey());
152 assertNotNull(actual);
153 assertNotNull(actual.getKey());
154 assertNotNull(actual.getStaticRecipients());
155 assertFalse(actual.getStaticRecipients().isEmpty());
156 }
157 }