Search in sources :

Example 1 with FileTypeMap

use of jakarta.activation.FileTypeMap in project spring-framework by spring-projects.

the class JavaMailSenderTests method javaMailSenderWithMimeMessageHelperAndSpecificEncoding.

@Test
public void javaMailSenderWithMimeMessageHelperAndSpecificEncoding() throws MessagingException {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setUsername("username");
    sender.setPassword("password");
    MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage(), "UTF-8");
    assertThat(message.getEncoding()).isEqualTo("UTF-8");
    FileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
    message.setFileTypeMap(fileTypeMap);
    assertThat(message.getFileTypeMap()).isEqualTo(fileTypeMap);
    message.setTo("you@mail.org");
    sender.send(message.getMimeMessage());
    assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
    assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
    assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
    assertThat(sender.transport.isCloseCalled()).isTrue();
    assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
    assertThat(sender.transport.getSentMessage(0)).isEqualTo(message.getMimeMessage());
}
Also used : FileTypeMap(jakarta.activation.FileTypeMap) Test(org.junit.jupiter.api.Test)

Example 2 with FileTypeMap

use of jakarta.activation.FileTypeMap in project spring-framework by spring-projects.

the class JavaMailSenderTests method javaMailSenderWithMimeMessageHelperAndDefaultEncoding.

@Test
public void javaMailSenderWithMimeMessageHelperAndDefaultEncoding() throws MessagingException {
    MockJavaMailSender sender = new MockJavaMailSender();
    sender.setHost("host");
    sender.setUsername("username");
    sender.setPassword("password");
    sender.setDefaultEncoding("UTF-8");
    FileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
    sender.setDefaultFileTypeMap(fileTypeMap);
    MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage());
    assertThat(message.getEncoding()).isEqualTo("UTF-8");
    assertThat(message.getFileTypeMap()).isEqualTo(fileTypeMap);
    message.setTo("you@mail.org");
    sender.send(message.getMimeMessage());
    assertThat(sender.transport.getConnectedHost()).isEqualTo("host");
    assertThat(sender.transport.getConnectedUsername()).isEqualTo("username");
    assertThat(sender.transport.getConnectedPassword()).isEqualTo("password");
    assertThat(sender.transport.isCloseCalled()).isTrue();
    assertThat(sender.transport.getSentMessages().size()).isEqualTo(1);
    assertThat(sender.transport.getSentMessage(0)).isEqualTo(message.getMimeMessage());
}
Also used : FileTypeMap(jakarta.activation.FileTypeMap) Test(org.junit.jupiter.api.Test)

Aggregations

FileTypeMap (jakarta.activation.FileTypeMap)2 Test (org.junit.jupiter.api.Test)2