Skip to content

Commit

Permalink
Fix Mail Service (Test) and remove Integration Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sayoungestguy committed Sep 6, 2024
1 parent 0b95799 commit ad8f0f4
Show file tree
Hide file tree
Showing 12 changed files with 3,265 additions and 3,250 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<sonar-maven-plugin.version>4.0.0.4121</sonar-maven-plugin.version>
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
<springdoc-openapi-starter-webmvc-api.version>2.5.0</springdoc-openapi-starter-webmvc-api.version>
<sonar.organization>sayoungestguy</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ private void sendEmailSync(String to, String subject, String content, boolean is
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, StandardCharsets.UTF_8.name());
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
String SenderMail = "MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net";
message.setFrom(SenderMail);
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
Expand Down
20 changes: 16 additions & 4 deletions src/main/resources/config/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,23 @@ spring:
liquibase:
# Remove 'faker' if you do not want the sample data to be loaded automatically
contexts: dev, faker
# mail:
# host: localhost
# port: 25
# username:
# password:
mail:
host: localhost
port: 25
username:
password:
host: smtp.mailersend.net
port: 587
username: MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net
password: zTuZ0pxazgHfOWPK
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
messages:
cache-duration: PT1S # 1 second, see the ISO 8601 standard
thymeleaf:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ management:
enabled: true
health:
mail:
enabled: false # When using the MailService, configure an SMTP server and set this to true
enabled: true # When using the MailService, configure an SMTP server and set this to true
prometheus:
metrics:
export:
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/com/teamsixnus/scaleup/service/MailServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testSendEmail() throws Exception {
MimeMessage message = messageCaptor.getValue();
assertThat(message.getSubject()).isEqualTo("testSubject");
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent()).isInstanceOf(String.class);
assertThat(message.getContent()).hasToString("testContent");
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8");
Expand All @@ -82,7 +82,7 @@ void testSendHtmlEmail() throws Exception {
MimeMessage message = messageCaptor.getValue();
assertThat(message.getSubject()).isEqualTo("testSubject");
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent()).isInstanceOf(String.class);
assertThat(message.getContent()).hasToString("testContent");
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
Expand All @@ -99,7 +99,7 @@ void testSendMultipartEmail() throws Exception {
part.writeTo(aos);
assertThat(message.getSubject()).isEqualTo("testSubject");
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent()).isInstanceOf(Multipart.class);
assertThat(aos).hasToString("\r\ntestContent");
assertThat(part.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8");
Expand All @@ -116,7 +116,7 @@ void testSendMultipartHtmlEmail() throws Exception {
part.writeTo(aos);
assertThat(message.getSubject()).isEqualTo("testSubject");
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent()).isInstanceOf(Multipart.class);
assertThat(aos).hasToString("\r\ntestContent");
assertThat(part.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
Expand All @@ -133,7 +133,7 @@ void testSendEmailFromTemplate() throws Exception {
MimeMessage message = messageCaptor.getValue();
assertThat(message.getSubject()).isEqualTo("test title");
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent().toString()).isEqualToNormalizingNewlines("<html>test title, http://127.0.0.1:8080, john</html>\n");
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Expand All @@ -148,7 +148,7 @@ void testSendActivationEmail() throws Exception {
verify(javaMailSender).send(messageCaptor.capture());
MimeMessage message = messageCaptor.getValue();
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent().toString()).isNotEmpty();
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Expand All @@ -163,7 +163,7 @@ void testCreationEmail() throws Exception {
verify(javaMailSender).send(messageCaptor.capture());
MimeMessage message = messageCaptor.getValue();
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent().toString()).isNotEmpty();
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Expand All @@ -178,7 +178,7 @@ void testSendPasswordResetMail() throws Exception {
verify(javaMailSender).send(messageCaptor.capture());
MimeMessage message = messageCaptor.getValue();
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent().toString()).isNotEmpty();
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Expand Down
Loading

0 comments on commit ad8f0f4

Please sign in to comment.