本文整理汇总了Java中com.icegreen.greenmail.util.GreenMail.getReceivedMessages方法的典型用法代码示例。如果您正苦于以下问题:Java GreenMail.getReceivedMessages方法的具体用法?Java GreenMail.getReceivedMessages怎么用?Java GreenMail.getReceivedMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.icegreen.greenmail.util.GreenMail
的用法示例。
在下文中一共展示了GreenMail.getReceivedMessages方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPipelineStoppedWithMail
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
@Test(timeout = 20000)
public void testPipelineStoppedWithMail() throws Exception {
Runner runner = pipelineManager.getRunner( TestUtil.PIPELINE_WITH_EMAIL, "0");
runner.start("admin");
waitForState(runner, PipelineStatus.RUNNING);
((AsyncRunner)runner).getRunner().prepareForStop("admin");
((AsyncRunner)runner).getRunner().stop("admin");
waitForState(runner, PipelineStatus.STOPPED);
//wait for email
GreenMail mailServer = TestUtil.TestRuntimeModule.getMailServer();
while(mailServer.getReceivedMessages().length < 1) {
ThreadUtil.sleep(100);
}
String headers = GreenMailUtil.getHeaders(mailServer.getReceivedMessages()[0]);
Assert.assertTrue(headers.contains("To: foo, bar"));
Assert.assertTrue(headers.contains("Subject: StreamsSets Data Collector Alert - " +
TestUtil.PIPELINE_TITLE_WITH_EMAIL + " - STOPPED"));
Assert.assertTrue(headers.contains("From: [email protected]"));
Assert.assertNotNull(GreenMailUtil.getBody(mailServer.getReceivedMessages()[0]));
mailServer.reset();
}
示例2: testPipelineFinishWithMail
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
@Test(timeout = 20000)
public void testPipelineFinishWithMail() throws Exception {
Runner runner = pipelineManager.getRunner( TestUtil.PIPELINE_WITH_EMAIL, "0");
runner.start("admin");
waitForState(runner, PipelineStatus.RUNNING);
assertNull(runner.getState().getMetrics());
TestUtil.EMPTY_OFFSET = true;
waitForState(runner, PipelineStatus.FINISHED);
assertNotNull(runner.getState().getMetrics());
//wait for email
GreenMail mailServer = TestUtil.TestRuntimeModule.getMailServer();
while(mailServer.getReceivedMessages().length < 1) {
ThreadUtil.sleep(100);
}
String headers = GreenMailUtil.getHeaders(mailServer.getReceivedMessages()[0]);
Assert.assertTrue(headers.contains("To: foo, bar"));
Assert.assertTrue(headers.contains("Subject: StreamsSets Data Collector Alert - " +
TestUtil.PIPELINE_TITLE_WITH_EMAIL + " - FINISHED"));
Assert.assertTrue(headers.contains("From: [email protected]"));
Assert.assertNotNull(GreenMailUtil.getBody(mailServer.getReceivedMessages()[0]));
mailServer.reset();
}
示例3: testThis
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
private void testThis() throws InterruptedException {
exc = null;
final GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP);
greenMail.setUser("[email protected]","[email protected]");
greenMail.start();
final Thread sendThread = new Thread() {
public void run() {
try {
sendMail("[email protected]", "[email protected]", "abc", "def", ServerSetupTest.SMTP);
} catch (final Throwable e) {
exc = new RuntimeException(e);
}
}
};
sendThread.start();
greenMail.waitForIncomingEmail(3000, 1);
final MimeMessage[] emails = greenMail.getReceivedMessages();
assertEquals(1, emails.length);
greenMail.stop();
sendThread.join(10000);
if (exc != null) {
throw exc;
}
}
示例4: testSendProvisioningSuccessEmailSMTPS
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
@Ignore
@Test
public void testSendProvisioningSuccessEmailSMTPS() throws IOException, MessagingException {
//To run this test, please download the greenmail.jks from the following link:
// https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/resources/greenmail.jks
// and put into the /cert/trusted directory, and set the mail.transport.protocol variable to smtps.
greenMail = new GreenMail(ServerSetupTest.SMTPS);
greenMail.start();
//GIVEN
String content = getFileContent("mail/cluster-installer-mail-success").replaceAll("\\n", "");
String subject = String.format("%s cluster installation", NAME_OF_THE_CLUSTER);
//WHEN
emailSenderService.sendProvisioningSuccessEmail("[email protected]", "xxx", "123.123.123.123", NAME_OF_THE_CLUSTER, false);
//THEN
greenMail.waitForIncomingEmail(5000, 1);
Message[] messages = greenMail.getReceivedMessages();
Assert.assertEquals(1, messages.length);
Assert.assertEquals(subject, messages[0].getSubject());
Assert.assertTrue(String.valueOf(messages[0].getContent()).replaceAll("\\n", "").replaceAll("\\r", "").contains(content));
}
示例5: waitForEmailAndExtractUrl
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
public static String waitForEmailAndExtractUrl(GreenMail smtpServer) throws IOException, MessagingException {
smtpServer.waitForIncomingEmail(1);
Message[] messages = smtpServer.getReceivedMessages();
smtpServer.reset();
assertEquals(1, messages.length);
return extractUrlFromMail(messages[0]);
}
示例6: sendsEmaiLToSmtpServer
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
/**
* SendEmail can send an email envelope to the SMTP server.
* @throws Exception If something goes wrong.
*/
@Test
public void sendsEmaiLToSmtpServer() throws Exception {
String bind = "localhost";
int port = this.port();
GreenMail server = this.smtpServer(bind, port);
server.start();
SendEmail se = new SendEmail(
new Postman.Default(
new SMTP(
new Token("", "")
.access(new Protocol.SMTP(bind, port))
)
),
new Envelope.MIME()
.with(new StSender("Charles Michael <[email protected]>"))
.with(new StRecipient("[email protected]"))
.with(new StSubject("test subject: test email"))
.with(new EnPlain("hello, how are you? This is a test email..."))
);
try {
se.perform(Mockito.mock(Command.class), Mockito.mock(Logger.class));
final MimeMessage[] messages = server.getReceivedMessages();
assertTrue(messages.length == 1);
for (final Message msg : messages) {
assertTrue(msg.getFrom()[0].toString().contains("<[email protected]>"));
assertTrue(msg.getSubject().contains("test email"));
}
} finally {
server.stop();
}
}
示例7: sendsEmailFromGivenUser
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
/**
* SendEmail can send an email when username, password, host and port are specified.
* @throws Exception If something goes wrong.
*/
@Test
public void sendsEmailFromGivenUser() throws Exception {
String bind = "localhost";
int port = this.port();
GreenMail server = this.smtpServer(bind, port);
server.start();
System.setProperty("charles.smtp.username","mihai");
System.setProperty("charles.smtp.password","");
System.setProperty("charles.smtp.host","localhost");
System.setProperty("charles.smtp.port", String.valueOf(port));
SendEmail se = new SendEmail("[email protected]", "hello", "hello, how are you?");
try {
se.perform(Mockito.mock(Command.class), Mockito.mock(Logger.class));
final MimeMessage[] messages = server.getReceivedMessages();
assertTrue(messages.length == 1);
for (final Message msg : messages) {
assertTrue(msg.getFrom()[0].toString().contains("mihai"));
assertTrue(msg.getSubject().contains("hello"));
}
} finally {
server.stop();
}
}
示例8: testSend
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
@Test
public void testSend() throws MessagingException, IOException {
GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
try {
greenMail.start();
//Use random content to avoid potential residual lingering problems
final String subject = GreenMailUtil.random();
final String body = GreenMailUtil.random();
sendTestMails(subject, body); // Place your sending code here
//wait for max 5s for 1 email to arrive
//waitForIncomingEmail() is useful if you're sending stuff asynchronously in a separate thread
assertTrue(greenMail.waitForIncomingEmail(5000, 2));
//Retrieve using GreenMail API
Message[] messages = greenMail.getReceivedMessages();
assertEquals(2, messages.length);
// Simple message
assertEquals(subject, messages[0].getSubject());
assertEquals(body, GreenMailUtil.getBody(messages[0]).trim());
//if you send content as a 2 part multipart...
assertTrue(messages[1].getContent() instanceof MimeMultipart);
MimeMultipart mp = (MimeMultipart) messages[1].getContent();
assertEquals(2, mp.getCount());
assertEquals("body1", GreenMailUtil.getBody(mp.getBodyPart(0)).trim());
assertEquals("body2", GreenMailUtil.getBody(mp.getBodyPart(1)).trim());
} finally {
greenMail.stop();
}
}
示例9: sendsEmailToTheServerThroughSmtps
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
/**
* SMTPS postman can send an email to the server through SMTPS wire.
* @throws Exception If fails
*/
@Test
public void sendsEmailToTheServerThroughSmtps() throws Exception {
final String bind = "localhost";
final int received = 1;
final int port = SmtpsTest.port();
final int timeout = 3000;
Security.setProperty(
"ssl.SocketFactory.provider",
DummySSLSocketFactory.class.getName()
);
final ServerSetup setup = new ServerSetup(
port, bind, ServerSetup.PROTOCOL_SMTPS
);
setup.setServerStartupTimeout(timeout);
final GreenMail server = new GreenMail(setup);
server.start();
try {
new Postman.Default(
new Smtps(
new Token("", "")
.access(new Protocol.Smtps(bind, port))
)
).send(
new Envelope.Safe(
new Envelope.Mime()
.with(new StSender("from <[email protected]>"))
.with(new StRecipient("to", "[email protected]"))
.with(new StSubject("test subject: test me"))
.with(new EnPlain("hello"))
)
);
final MimeMessage[] messages = server.getReceivedMessages();
MatcherAssert.assertThat(
messages.length, Matchers.is(received)
);
for (final Message msg : messages) {
MatcherAssert.assertThat(
msg.getFrom()[0].toString(),
Matchers.containsString("<[email protected]>")
);
MatcherAssert.assertThat(
msg.getSubject(), Matchers.containsString("test me")
);
}
} finally {
server.stop();
}
}
示例10: sendsEmailToSmtpServer
import com.icegreen.greenmail.util.GreenMail; //导入方法依赖的package包/类
/**
* SMTP postman can send email through SMTP wire.
* @throws Exception If fails
*/
@Test
public void sendsEmailToSmtpServer() throws Exception {
final String bind = "localhost";
final int received = 3;
final int port = SmtpTest.port();
final int timeout = 3000;
final ServerSetup setup = new ServerSetup(
port, bind, ServerSetup.PROTOCOL_SMTP
);
setup.setServerStartupTimeout(timeout);
final GreenMail server = new GreenMail(setup);
server.start();
try {
new Postman.Default(
new Smtp(
new Token("", "")
.access(new Protocol.Smtp(bind, port))
)
).send(
new Envelope.Safe(
new Envelope.Mime()
.with(new StSender("from <test-[email protected]>"))
.with(new StRecipient("to", "[email protected]"))
.with(new StCc(new InternetAddress("cc <[email protected]>")))
.with(new StBcc("bcc <[email protected]>"))
.with(new StSubject("test subject: test me"))
.with(new EnPlain("hello"))
.with(new EnHtml("<p>how are you?</p>"))
)
);
final MimeMessage[] messages = server.getReceivedMessages();
MatcherAssert.assertThat(
messages.length,
Matchers.is(received)
);
for (final Message msg : messages) {
MatcherAssert.assertThat(
msg.getFrom()[0].toString(),
Matchers.containsString("<[email protected]>")
);
MatcherAssert.assertThat(
msg.getSubject(),
Matchers.containsString("test me")
);
}
} finally {
server.stop();
}
}