Skip to content

Commit 26f0cea

Browse files
committed
change default for syntax. add json tests
1 parent 36a220c commit 26f0cea

3 files changed

Lines changed: 65 additions & 2 deletions

File tree

src/main/java/com/auth0/json/mgmt/EmailTemplate.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public class EmailTemplate {
2929
@JsonProperty("enabled")
3030
private Boolean enabled;
3131

32+
public EmailTemplate() {
33+
//Only here to set the syntax default value
34+
this.syntax = "liquid";
35+
}
36+
3237
/**
3338
* Getter for the name of the template.
3439
*
@@ -139,6 +144,7 @@ public String getSyntax() {
139144

140145
/**
141146
* Sets for the syntax to be used in the template's code.
147+
* Default value is 'liquid'
142148
*
143149
* @param syntax the syntax to be used in the template's code.
144150
*/

src/test/java/com/auth0/client/mgmt/EmailTemplatesEntityTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ public void shouldPatchEmailTemplate() throws Exception {
9999
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
100100

101101
Map<String, Object> body = bodyFromRequest(recordedRequest);
102-
assertThat(body.size(), is(3));
102+
assertThat(body.size(), is(4));
103103
assertThat(body, hasEntry("resultUrl", (Object) "https://somewhere.com"));
104104
assertThat(body, hasEntry("body", (Object) "<html>New</html>"));
105+
assertThat(body, hasEntry("syntax", (Object) "liquid"));
105106
assertThat(body, hasEntry("urlLifetimeInSeconds", (Object) 123));
106107
assertThat(body, not(hasKey("template")));
107108
assertThat(body, not(hasKey("from")));
108-
assertThat(body, not(hasKey("syntax")));
109109
assertThat(body, not(hasKey("enabled")));
110110

111111
assertThat(response, is(notNullValue()));
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
 (0)