-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mail-connector): check htmlBody and/or body is null and throw an …
…error (#3796) * fix(mail-connector): check htmlBody and/or body is null and throw an error if not throw an error, connector will retry it over and over again. * chore(mail-connector): build the assertation inside the `SmtpSendMail` record * test(mail-connector): adding unit test to validate `isEmailMessageValid` * chore(mail-connector): run mvn spotless to format the `SmtpSendEmailTest` class * chore(mail-connector): use mvn:licence to add the licence to the file
- Loading branch information
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...rc/test/java/io/camunda/connector/email/outbound/protocols/actions/SmtpSendEmailTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. Licensed under a proprietary license. | ||
* See the License.txt file for more information. You may not use this file | ||
* except in compliance with the proprietary license. | ||
*/ | ||
package io.camunda.connector.email.outbound.protocols.actions; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class SmtpSendEmailTest { | ||
|
||
@Test | ||
void isEmailMessageValidPlainTextWithBody() { | ||
SmtpSendEmail smtpSendEmail = mockSmtpSendEmail(ContentType.PLAIN, "text", null); | ||
assertTrue(smtpSendEmail.isEmailMessageValid()); | ||
} | ||
|
||
@Test | ||
void isEmailMessageNotValidPlainTextWithoutBody() { | ||
SmtpSendEmail smtpSendEmail = mockSmtpSendEmail(ContentType.PLAIN, null, null); | ||
assertFalse(smtpSendEmail.isEmailMessageValid()); | ||
} | ||
|
||
@Test | ||
void isEmailMessageValidHtmlTextWithBody() { | ||
SmtpSendEmail smtpSendEmail = mockSmtpSendEmail(ContentType.HTML, null, "text"); | ||
assertTrue(smtpSendEmail.isEmailMessageValid()); | ||
} | ||
|
||
@Test | ||
void isEmailMessageNotValidHtmlWithoutBody() { | ||
SmtpSendEmail smtpSendEmail = mockSmtpSendEmail(ContentType.HTML, null, null); | ||
assertFalse(smtpSendEmail.isEmailMessageValid()); | ||
} | ||
|
||
@Test | ||
void isEmailMessageValidMultiWithBody() { | ||
SmtpSendEmail smtpSendEmail = mockSmtpSendEmail(ContentType.MULTIPART, "text", "text2"); | ||
assertTrue(smtpSendEmail.isEmailMessageValid()); | ||
} | ||
|
||
@Test | ||
void isEmailMessageNotValidHtmlTextWithoutBothBodies() { | ||
SmtpSendEmail smtpSendEmail = mockSmtpSendEmail(ContentType.MULTIPART, null, null); | ||
assertFalse(smtpSendEmail.isEmailMessageValid()); | ||
} | ||
|
||
@Test | ||
void isEmailMessageNotValidMultiWithoutHtmlBody() { | ||
SmtpSendEmail smtpSendEmail = mockSmtpSendEmail(ContentType.MULTIPART, "text", null); | ||
assertFalse(smtpSendEmail.isEmailMessageValid()); | ||
} | ||
|
||
@Test | ||
void isEmailMessageNotValidMultiWithoutBody() { | ||
SmtpSendEmail smtpSendEmail = mockSmtpSendEmail(ContentType.MULTIPART, null, "text"); | ||
assertFalse(smtpSendEmail.isEmailMessageValid()); | ||
} | ||
|
||
private SmtpSendEmail mockSmtpSendEmail(ContentType contentType, String body, String htmlBody) { | ||
return new SmtpSendEmail("", "", "", "", null, "", contentType, body, htmlBody, null); | ||
} | ||
} |