Fixed NPE when email action has no subject or text body
Fixes elastic/elasticsearch#137 Original commit: elastic/x-pack-elasticsearch@7f575657f3
This commit is contained in:
parent
f5c48576bc
commit
5903ea7493
|
@ -38,15 +38,16 @@ public class EmailAction extends Action<EmailAction.Result> {
|
||||||
final Authentication auth;
|
final Authentication auth;
|
||||||
final Profile profile;
|
final Profile profile;
|
||||||
final String account;
|
final String account;
|
||||||
final Template subject;
|
final @Nullable Template subject;
|
||||||
final Template textBody;
|
final @Nullable Template textBody;
|
||||||
final Template htmlBody;
|
final @Nullable Template htmlBody;
|
||||||
final boolean attachPayload;
|
final boolean attachPayload;
|
||||||
|
|
||||||
final EmailService emailService;
|
final EmailService emailService;
|
||||||
|
|
||||||
public EmailAction(ESLogger logger, @Nullable Transform transform, EmailService emailService, Email emailPrototype, Authentication auth, Profile profile,
|
public EmailAction(ESLogger logger, @Nullable Transform transform, EmailService emailService, Email emailPrototype,
|
||||||
String account, Template subject, Template textBody, Template htmlBody, boolean attachPayload) {
|
Authentication auth, Profile profile, String account, @Nullable Template subject,
|
||||||
|
@Nullable Template textBody, @Nullable Template htmlBody, boolean attachPayload) {
|
||||||
|
|
||||||
super(logger, transform);
|
super(logger, transform);
|
||||||
this.emailService = emailService;
|
this.emailService = emailService;
|
||||||
|
@ -74,8 +75,8 @@ public class EmailAction extends Action<EmailAction.Result> {
|
||||||
.copyFrom(emailPrototype);
|
.copyFrom(emailPrototype);
|
||||||
|
|
||||||
email.id(ctx.id());
|
email.id(ctx.id());
|
||||||
email.subject(subject.render(model));
|
email.subject(subject != null ? subject.render(model) : "");
|
||||||
email.textBody(textBody.render(model));
|
email.textBody(textBody != null ? textBody.render(model) : "");
|
||||||
|
|
||||||
if (htmlBody != null) {
|
if (htmlBody != null) {
|
||||||
email.htmlBody(htmlBody.render(model));
|
email.htmlBody(htmlBody.render(model));
|
||||||
|
|
|
@ -59,8 +59,8 @@ public class EmailActionTests extends ElasticsearchTestCase {
|
||||||
Authentication auth = new Authentication("user", "passwd");
|
Authentication auth = new Authentication("user", "passwd");
|
||||||
Profile profile = randomFrom(Profile.values());
|
Profile profile = randomFrom(Profile.values());
|
||||||
|
|
||||||
Template subject = mock(Template.class);
|
Template subject = randomBoolean() ? null : mock(Template.class);
|
||||||
Template textBody = mock(Template.class);
|
Template textBody = randomBoolean() ? null : mock(Template.class);
|
||||||
Template htmlBody = randomBoolean() ? null : mock(Template.class);
|
Template htmlBody = randomBoolean() ? null : mock(Template.class);
|
||||||
boolean attachPayload = randomBoolean();
|
boolean attachPayload = randomBoolean();
|
||||||
Transform transform = randomBoolean() ? null : mock(Transform.class);
|
Transform transform = randomBoolean() ? null : mock(Transform.class);
|
||||||
|
@ -98,8 +98,12 @@ public class EmailActionTests extends ElasticsearchTestCase {
|
||||||
.put("scheduled_fire_time", now).build())
|
.put("scheduled_fire_time", now).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
when(subject.render(expectedModel)).thenReturn("_subject");
|
if (subject != null) {
|
||||||
when(textBody.render(expectedModel)).thenReturn("_text_body");
|
when(subject.render(expectedModel)).thenReturn("_subject");
|
||||||
|
}
|
||||||
|
if (textBody != null) {
|
||||||
|
when(textBody.render(expectedModel)).thenReturn("_text_body");
|
||||||
|
}
|
||||||
if (htmlBody != null) {
|
if (htmlBody != null) {
|
||||||
when (htmlBody.render(expectedModel)).thenReturn("_html_body");
|
when (htmlBody.render(expectedModel)).thenReturn("_html_body");
|
||||||
}
|
}
|
||||||
|
@ -112,8 +116,8 @@ public class EmailActionTests extends ElasticsearchTestCase {
|
||||||
Email actualEmail = ((EmailAction.Result.Success) result).email();
|
Email actualEmail = ((EmailAction.Result.Success) result).email();
|
||||||
assertThat(actualEmail.id(), is(ctxId));
|
assertThat(actualEmail.id(), is(ctxId));
|
||||||
assertThat(actualEmail, notNullValue());
|
assertThat(actualEmail, notNullValue());
|
||||||
assertThat(actualEmail.subject(), is("_subject"));
|
assertThat(actualEmail.subject(), is(subject == null ? "" : "_subject"));
|
||||||
assertThat(actualEmail.textBody(), is("_text_body"));
|
assertThat(actualEmail.textBody(), is(textBody == null ? "" : "_text_body"));
|
||||||
if (htmlBody != null) {
|
if (htmlBody != null) {
|
||||||
assertThat(actualEmail.htmlBody(), is("_html_body"));
|
assertThat(actualEmail.htmlBody(), is("_html_body"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue