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 Profile profile;
|
||||
final String account;
|
||||
final Template subject;
|
||||
final Template textBody;
|
||||
final Template htmlBody;
|
||||
final @Nullable Template subject;
|
||||
final @Nullable Template textBody;
|
||||
final @Nullable Template htmlBody;
|
||||
final boolean attachPayload;
|
||||
|
||||
final EmailService emailService;
|
||||
|
||||
public EmailAction(ESLogger logger, @Nullable Transform transform, EmailService emailService, Email emailPrototype, Authentication auth, Profile profile,
|
||||
String account, Template subject, Template textBody, Template htmlBody, boolean attachPayload) {
|
||||
public EmailAction(ESLogger logger, @Nullable Transform transform, EmailService emailService, Email emailPrototype,
|
||||
Authentication auth, Profile profile, String account, @Nullable Template subject,
|
||||
@Nullable Template textBody, @Nullable Template htmlBody, boolean attachPayload) {
|
||||
|
||||
super(logger, transform);
|
||||
this.emailService = emailService;
|
||||
|
@ -74,8 +75,8 @@ public class EmailAction extends Action<EmailAction.Result> {
|
|||
.copyFrom(emailPrototype);
|
||||
|
||||
email.id(ctx.id());
|
||||
email.subject(subject.render(model));
|
||||
email.textBody(textBody.render(model));
|
||||
email.subject(subject != null ? subject.render(model) : "");
|
||||
email.textBody(textBody != null ? textBody.render(model) : "");
|
||||
|
||||
if (htmlBody != null) {
|
||||
email.htmlBody(htmlBody.render(model));
|
||||
|
|
|
@ -59,8 +59,8 @@ public class EmailActionTests extends ElasticsearchTestCase {
|
|||
Authentication auth = new Authentication("user", "passwd");
|
||||
Profile profile = randomFrom(Profile.values());
|
||||
|
||||
Template subject = mock(Template.class);
|
||||
Template textBody = mock(Template.class);
|
||||
Template subject = randomBoolean() ? null : mock(Template.class);
|
||||
Template textBody = randomBoolean() ? null : mock(Template.class);
|
||||
Template htmlBody = randomBoolean() ? null : mock(Template.class);
|
||||
boolean attachPayload = randomBoolean();
|
||||
Transform transform = randomBoolean() ? null : mock(Transform.class);
|
||||
|
@ -98,8 +98,12 @@ public class EmailActionTests extends ElasticsearchTestCase {
|
|||
.put("scheduled_fire_time", now).build())
|
||||
.build();
|
||||
|
||||
when(subject.render(expectedModel)).thenReturn("_subject");
|
||||
when(textBody.render(expectedModel)).thenReturn("_text_body");
|
||||
if (subject != null) {
|
||||
when(subject.render(expectedModel)).thenReturn("_subject");
|
||||
}
|
||||
if (textBody != null) {
|
||||
when(textBody.render(expectedModel)).thenReturn("_text_body");
|
||||
}
|
||||
if (htmlBody != null) {
|
||||
when (htmlBody.render(expectedModel)).thenReturn("_html_body");
|
||||
}
|
||||
|
@ -112,8 +116,8 @@ public class EmailActionTests extends ElasticsearchTestCase {
|
|||
Email actualEmail = ((EmailAction.Result.Success) result).email();
|
||||
assertThat(actualEmail.id(), is(ctxId));
|
||||
assertThat(actualEmail, notNullValue());
|
||||
assertThat(actualEmail.subject(), is("_subject"));
|
||||
assertThat(actualEmail.textBody(), is("_text_body"));
|
||||
assertThat(actualEmail.subject(), is(subject == null ? "" : "_subject"));
|
||||
assertThat(actualEmail.textBody(), is(textBody == null ? "" : "_text_body"));
|
||||
if (htmlBody != null) {
|
||||
assertThat(actualEmail.htmlBody(), is("_html_body"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue