1616 * specific language governing permissions and limitations
1717 * under the License.
1818 */
19- package org .apache .syncope .core .provisioning .java .jexl ;
20-
21- import org .apache .syncope .core .provisioning .api .jexl .JexlUtils ;
19+ package org .apache .syncope .core .provisioning .api .jexl ;
2220
2321import static org .junit .jupiter .api .Assertions .assertFalse ;
2422import static org .junit .jupiter .api .Assertions .assertNotNull ;
3634import org .apache .syncope .common .lib .Attr ;
3735import org .apache .syncope .common .lib .to .MembershipTO ;
3836import org .apache .syncope .common .lib .to .UserTO ;
39- import org .apache .syncope .core .persistence .api .dao .MailTemplateDAO ;
40- import org .apache .syncope .core .provisioning .java .AbstractTest ;
37+ import org .apache .syncope .core .provisioning .api .AbstractTest ;
4138import org .junit .jupiter .api .Test ;
42- import org .springframework .beans .factory .annotation .Autowired ;
43- import org .springframework .transaction .annotation .Transactional ;
4439
45- @ Transactional ("Master" )
4640public class MailTemplateTest extends AbstractTest {
4741
48- @ Autowired
49- private MailTemplateDAO mailTemplateDAO ;
42+ private static final String CONFIRM_PASSWORD_RESET_TEMPLATE =
43+ "<html><body>"
44+ + "<p>Hi,<br/> we are happy to inform you that the password request was successfully executed for "
45+ + "your account.</p> <p>Best regards.</p> </body> </html>" ;
46+
47+ private static final String REQUEST_PASSWORD_RESET_TEMPLATE = "Hi, a password reset was request for "
48+ + "${user.getUsername()}. In order to complete this request, you need to visit this link: "
49+ + "http://localhost:9080/syncope-enduser/app/#!/confirmpasswordreset?token="
50+ + "${input.get(0).replaceAll(' ', '%20')}"
51+ + "If you did not request this reset, just ignore the present e-mail. Best regards." ;
52+
53+ private static final String OPTIN_TEMPLATE =
54+ "<html> <body> <h3>Hi ${user.getPlainAttr(\" firstname\" ).get().values[0]} "
55+ + "${user.getPlainAttr(\" surname\" ).get().values[0]}, welcome to Syncope!</h3>"
56+ + "<p> Your username is ${user.username}.<br/>"
57+ + "Your email address is ${user.getPlainAttr(\" email\" ).get().values[0]}."
58+ + "Your email address inside a <a href=\" http://localhost/?email="
59+ + "${user.getPlainAttr(\" email\" ).get().values[0].replace('@', '%40')}\" >link</a>.</p>"
60+ + "<p>This message was sent to the following recipients: <ul>\n $$ for (recipient: recipients) {\n "
61+ + " <li>${recipient.getPlainAttr(\" email\" ).get().values[0]}</li>\n $$ }\n </ul>\n "
62+ + " because one of the following events occurred: <ul>\n $$ for (event: events) {\n "
63+ + " <li>${event}</li>\n $$ }\n </ul>\n </p> \n $$ if (!empty(user.memberships)) {\n "
64+ + " You have been provided with the following groups:\n <ul>\n "
65+ + " $$ for(membership : user.memberships) {\n <li>${membership.groupName}</li>\n $$ }\n "
66+ + " </ul>\n $$ }\n </body> </html>" ;
5067
5168 private static String evaluate (final String template , final Map <String , Object > jexlVars ) {
5269 StringWriter writer = new StringWriter ();
@@ -58,10 +75,7 @@ private static String evaluate(final String template, final Map<String, Object>
5875
5976 @ Test
6077 public void confirmPasswordReset () throws IOException {
61- String htmlBody = evaluate (
62- mailTemplateDAO .find ("confirmPasswordReset" ).getHTMLTemplate (),
63- new HashMap <>());
64-
78+ String htmlBody = evaluate (CONFIRM_PASSWORD_RESET_TEMPLATE , new HashMap <>());
6579 assertNotNull (htmlBody );
6680 }
6781
@@ -79,17 +93,15 @@ public void requestPasswordReset() throws IOException {
7993 input .add (token );
8094 ctx .put ("input" , input );
8195
82- String htmlBody = evaluate (
83- mailTemplateDAO .find ("requestPasswordReset" ).getHTMLTemplate (),
84- ctx );
96+ String textBody = evaluate (REQUEST_PASSWORD_RESET_TEMPLATE , ctx );
8597
86- assertNotNull (htmlBody );
87- assertTrue (htmlBody .contains ("a password reset was request for " + username + '.' ));
88- assertFalse (htmlBody .contains (
89- "http://localhost:9080/syncope-enduser/confirmpasswordreset?token="
98+ assertNotNull (textBody );
99+ assertTrue (textBody .contains ("a password reset was request for " + username + "." ));
100+ assertFalse (textBody .contains (
101+ "http://localhost:9080/syncope-enduser/app/#!/ confirmpasswordreset?token="
90102 + token ));
91- assertTrue (htmlBody .contains (
92- "http://localhost:9080/syncope-enduser/confirmpasswordreset?token="
103+ assertTrue (textBody .contains (
104+ "http://localhost:9080/syncope-enduser/app/#!/ confirmpasswordreset?token="
93105 + token .replaceAll (" " , "%20" )));
94106 }
95107
@@ -115,15 +127,16 @@ public void optin() throws IOException {
115127 recipient .getPlainAttr ("email" ).get ().getValues ().set (0 , "another@syncope.apache.org" );
116128 ctx .put ("recipients" , List .of (recipient ));
117129
118- String htmlBody = evaluate (
119- mailTemplateDAO . find ( "optin" ). getHTMLTemplate (),
120- ctx );
130+ ctx . put ( "events" , List . of ( "event1" ));
131+
132+ String htmlBody = evaluate ( OPTIN_TEMPLATE , ctx );
121133
122134 assertNotNull (htmlBody );
123135
124136 assertTrue (htmlBody .contains ("Hi John Doe," ));
125137 assertTrue (htmlBody .contains ("Your email address is john.doe@syncope.apache.org." ));
126138 assertTrue (htmlBody .contains ("<li>another@syncope.apache.org</li>" ));
127139 assertTrue (htmlBody .contains ("<li>a group</li>" ));
140+ assertTrue (htmlBody .contains ("<li>event1</li>" ));
128141 }
129142}
0 commit comments