/
EmailTestSample.java
67 lines (58 loc) · 2.49 KB
/
EmailTestSample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package fr.sii.ogham.sample.test;
import static com.icegreen.greenmail.util.ServerSetupTest.SMTP;
import static fr.sii.ogham.testing.assertion.OghamAssertions.assertThat;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
import java.io.IOException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import com.icegreen.greenmail.junit4.GreenMailRule;
import fr.sii.ogham.core.builder.MessagingBuilder;
import fr.sii.ogham.core.exception.MessagingException;
import fr.sii.ogham.core.service.MessagingService;
import fr.sii.ogham.email.message.Email;
public class EmailTestSample {
private MessagingService oghamService;
@Rule
public final GreenMailRule greenMail = new GreenMailRule(SMTP); // <1>
@Before
public void setUp() throws IOException {
oghamService = MessagingBuilder.standard()
.environment()
.properties()
.set("ogham.email.from.default-value", "Sender Name <test.sender@sii.fr>")
.set("mail.smtp.host", SMTP.getBindAddress()) // <2>
.set("mail.smtp.port", String.valueOf(SMTP.getPort())) // <3>
.and()
.and()
.build();
}
@Test
public void simple() throws MessagingException, javax.mail.MessagingException {
// @formatter:off
oghamService.send(new Email()
.subject("Simple")
.body().string("string body")
.to("Recipient Name <recipient@sii.fr>"));
assertThat(greenMail).receivedMessages() // <4>
.count(is(1)) // <5>
.message(0) // <6>
.subject(is("Simple")) // <7>
.from()
.address(hasItems("test.sender@sii.fr")) // <8>
.personal(hasItems("Sender Name")).and() // <9>
.to()
.address(hasItems("recipient@sii.fr")) // <10>
.personal(hasItems("Recipient Name")).and() // <11>
.body()
.contentAsString(is("string body")) // <12>
.contentType(startsWith("text/plain")).and() // <13>
.alternative(nullValue()) // <14>
.attachments(emptyIterable()); // <15>
// @formatter:on
}
}