1+ package com .auth0 .json .mgmt ;
2+
3+ import com .auth0 .json .JsonMatcher ;
4+ import com .auth0 .json .JsonTest ;
5+ import org .junit .Test ;
6+
7+ import static org .hamcrest .MatcherAssert .assertThat ;
8+ import static org .hamcrest .Matchers .is ;
9+ import static org .hamcrest .Matchers .notNullValue ;
10+
11+ public class EmailTemplateTest extends JsonTest <EmailTemplate > {
12+
13+ private static final String json = "{\" template\" : \" welcome_email\" , \" from\" : \" you@auth0.com\" , \" subject\" : \" Some subject\" , \" syntax\" : \" liquid\" , \" body\" : \" <html> </html>\" , \" enabled\" : true}" ;
14+
15+ @ Test
16+ public void shouldSerialize () throws Exception {
17+ EmailTemplate template = new EmailTemplate ();
18+ template .setResultUrl ("https://auth0.com" );
19+ template .setUrlLifetimeInSeconds (993311 );
20+ template .setBody ("SOME HTML" );
21+ template .setEnabled (false );
22+ template .setSyntax ("html" );
23+ template .setSubject ("Hello world" );
24+ template .setFrom ("me@auth0.com" );
25+ template .setName ("farewell" );
26+
27+ String serialized = toJSON (template );
28+ assertThat (serialized , is (notNullValue ()));
29+ assertThat (serialized , JsonMatcher .hasEntry ("resultUrl" , "https://auth0.com" ));
30+ assertThat (serialized , JsonMatcher .hasEntry ("urlLifetimeInSeconds" , 993311 ));
31+ assertThat (serialized , JsonMatcher .hasEntry ("body" , "SOME HTML" ));
32+ assertThat (serialized , JsonMatcher .hasEntry ("enabled" , false ));
33+ assertThat (serialized , JsonMatcher .hasEntry ("syntax" , "html" ));
34+ assertThat (serialized , JsonMatcher .hasEntry ("subject" , "Hello world" ));
35+ assertThat (serialized , JsonMatcher .hasEntry ("from" , "me@auth0.com" ));
36+ assertThat (serialized , JsonMatcher .hasEntry ("template" , "farewell" ));
37+ }
38+
39+ @ Test
40+ public void shouldDeserialize () throws Exception {
41+ EmailTemplate template = fromJSON (json , EmailTemplate .class );
42+
43+ assertThat (template , is (notNullValue ()));
44+ assertThat (template .getName (), is ("welcome_email" ));
45+ assertThat (template .getFrom (), is ("you@auth0.com" ));
46+ assertThat (template .getSubject (), is ("Some subject" ));
47+ assertThat (template .getSyntax (), is ("liquid" ));
48+ assertThat (template .getBody (), is ("<html> </html>" ));
49+ assertThat (template .isEnabled (), is (true ));
50+ }
51+
52+ @ Test
53+ public void shouldHaveDefaults () {
54+ EmailTemplate template = new EmailTemplate ();
55+ assertThat (template .getSyntax (), is ("liquid" ));
56+ }
57+ }
0 commit comments