forked from mailjet/mailjet-apiv3-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendIT.java
More file actions
70 lines (59 loc) · 3.03 KB
/
SendIT.java
File metadata and controls
70 lines (59 loc) · 3.03 KB
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
68
69
70
package com.mailjet.client;
import com.mailjet.client.errors.MailjetException;
import com.mailjet.client.resource.Email;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
public class SendIT {
@Test
public void sendEmailV3() throws MailjetException {
// arrange
MailjetClient mailjetClient = TestHelper.getClient();
String senderEmail = TestHelper.getValidSenderEmail(mailjetClient);
MailjetRequest mailjetRequest = new MailjetRequest(Email.resource)
.property(Email.FROMEMAIL, senderEmail)
.property(Email.FROMNAME, "Your Mailjet Pilot")
.property(Email.RECIPIENTS, new JSONArray()
.put(new JSONObject()
.put("Email", senderEmail)
.put("Name", "Passenger 1")
)
)
.property(Email.SUBJECT, "Your email flight plan!")
.property(Email.TEXTPART, "Dear passenger, welcome to Mailjet! May the delivery force be with you!")
.property(Email.HTMLPART, "<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!");
// act
MailjetResponse mailjetResponse = mailjetClient.post(mailjetRequest);
// assert
Assert.assertEquals(200, mailjetResponse.getStatus());
Assert.assertEquals(senderEmail, mailjetResponse.getData().getJSONObject(0).getString("Email"));
}
@Test
public void sendEmailV3Async() throws MailjetException, ExecutionException, InterruptedException {
// arrange
MailjetClient mailjetClient = TestHelper.getClient();
String senderEmail = TestHelper.getValidSenderEmail(mailjetClient);
MailjetRequest mailjetRequest = new MailjetRequest(Email.resource)
.property(Email.FROMEMAIL, senderEmail)
.property(Email.FROMNAME, "Your Mailjet Pilot")
.property(Email.RECIPIENTS, new JSONArray()
.put(new JSONObject()
.put("Email", senderEmail)
.put("Name", "Passenger 1")
)
)
.property(Email.SUBJECT, "Your email flight plan!")
.property(Email.TEXTPART, "Dear passenger, welcome to Mailjet! May the delivery force be with you!")
.property(Email.HTMLPART, "<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!");
// act
CompletableFuture<MailjetResponse> responseFuture = mailjetClient.postAsync(mailjetRequest);
MailjetResponse mailjetResponse = responseFuture.get();
// assert
Assert.assertEquals(200, mailjetResponse.getStatus());
Assert.assertEquals(senderEmail, mailjetResponse.getData().getJSONObject(0).getString("Email"));
}
}