-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new methods to retrieve parameter values from a Mail instance
- Loading branch information
Showing
4 changed files
with
109 additions
and
30 deletions.
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
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
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
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 |
---|---|---|
|
@@ -3,10 +3,7 @@ | |
import com.github.tomakehurst.wiremock.client.MappingBuilder; | ||
import com.github.tomakehurst.wiremock.client.RequestPatternBuilder; | ||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import net.sargue.mailgun.Configuration; | ||
import net.sargue.mailgun.MailBuilder; | ||
import net.sargue.mailgun.MailRequestCallback; | ||
import net.sargue.mailgun.Response; | ||
import net.sargue.mailgun.*; | ||
import org.apache.commons.codec.binary.Base64; | ||
import org.apache.http.NameValuePair; | ||
import org.apache.http.client.utils.URLEncodedUtils; | ||
|
@@ -23,6 +20,7 @@ | |
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
import static com.google.common.collect.Lists.newArrayList; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.junit.Assert.*; | ||
|
||
|
@@ -84,20 +82,22 @@ private void verifyMessageSent(NameValuePair... parameters) { | |
public void basicText() { | ||
stubFor(expectedBasicPost().willReturn(aResponse().withStatus(200))); | ||
|
||
Response response = MailBuilder.using(configuration) | ||
.to("[email protected]") | ||
.subject("This is a plain text test") | ||
.text("Hello world!") | ||
.build() | ||
.send(); | ||
String to = "[email protected]"; | ||
Mail mail = MailBuilder.using(configuration) | ||
.to(to) | ||
.subject("This is a plain text test") | ||
.text("Hello world!") | ||
.build(); | ||
Response response = mail.send(); | ||
|
||
assertEquals(mail.getFirstValue("to"), to); | ||
assertEquals(mail.getValues("to"), newArrayList(to)); | ||
assertTrue(response.isOk()); | ||
assertEquals(Response.ResponseType.OK, | ||
response.responseType()); | ||
assertEquals(Response.ResponseType.OK, response.responseType()); | ||
assertEquals(200, response.responseCode()); | ||
|
||
verifyMessageSent( | ||
param("to", "[email protected]"), | ||
param("to", to), | ||
param("subject", "This is a plain text test"), | ||
param("text", "Hello world!") | ||
); | ||
|
@@ -234,27 +234,43 @@ public void withNullName() { | |
public void sendBasicTestMode() { | ||
stubFor(expectedBasicPost().willReturn(aResponse().withStatus(200))); | ||
|
||
Response response = MailBuilder.using(configuration) | ||
.from("[email protected]") | ||
.from("Random account", "[email protected]") | ||
.to("[email protected]") | ||
.cc("[email protected]") | ||
.cc("Named CC", "[email protected]") | ||
.bcc("[email protected]") | ||
.bcc("Named BCC", "[email protected]") | ||
.parameter("o:testmode", "yes") | ||
.build() | ||
.send(); | ||
String to = "[email protected]"; | ||
String cc1 = "[email protected]"; | ||
String cc2Name = "Named CC"; | ||
String cc2Mail = "[email protected]"; | ||
String bcc1 = "[email protected]"; | ||
String bcc2Name = "Named BCC"; | ||
String bcc2Mail = "[email protected]"; | ||
Mail mail = MailBuilder.using(configuration) | ||
.from("[email protected]") | ||
.from("Random account", "[email protected]") | ||
.to(to) | ||
.cc(cc1) | ||
.cc(cc2Name, cc2Mail) | ||
.bcc(bcc1) | ||
.bcc(bcc2Name, bcc2Mail) | ||
.parameter("o:testmode", "yes") | ||
.build(); | ||
Response response = mail.send(); | ||
|
||
assertEquals(mail.getFirstValue("to"), to); | ||
assertEquals(mail.getValues("to"), newArrayList(to)); | ||
assertEquals(mail.getFirstValue("cc"), cc1); | ||
assertEquals(mail.getValues("cc"), | ||
newArrayList(cc1, cc2Name + " <" + cc2Mail + ">")); | ||
assertEquals(mail.getFirstValue("bcc"), bcc1); | ||
assertEquals(mail.getValues("bcc"), | ||
newArrayList(bcc1, bcc2Name + " <" + bcc2Mail + ">")); | ||
assertTrue(response.isOk()); | ||
|
||
verifyMessageSent( | ||
param("from", "[email protected]"), | ||
param("from", mail("Random account", "[email protected]")), | ||
param("to", "[email protected]"), | ||
param("cc", "[email protected]"), | ||
param("cc", mail("Named CC", "[email protected]")), | ||
param("bcc", "[email protected]"), | ||
param("bcc", mail("Named BCC", "[email protected]")), | ||
param("to", to), | ||
param("cc", cc1), | ||
param("cc", mail(cc2Name, cc2Mail)), | ||
param("bcc", bcc1), | ||
param("bcc", mail(bcc2Name, bcc2Mail)), | ||
param("o:testmode", "yes") | ||
); | ||
} | ||
|