本文整理汇总了Java中org.subethamail.wiser.Wiser.stop方法的典型用法代码示例。如果您正苦于以下问题:Java Wiser.stop方法的具体用法?Java Wiser.stop怎么用?Java Wiser.stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.subethamail.wiser.Wiser
的用法示例。
在下文中一共展示了Wiser.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
final Wiser wiser = new Wiser();
wiser.setPort(2500);
wiser.start();
final SmtpSender mailer = new SmtpSender("localhost", 2500, "test", "asdf", "localhost", SmtpSender.Security.TRY_TLS);
final MessageStruct msg = new MessageStruct();
msg.Sender = "[email protected]";
msg.Recipient = "[email protected]";
msg.Subject = "Test";
msg.Message = "The message.";
msg.MailId = 0L;
try (final SmtpSender.Connection conn = mailer.getConnection()) {
mailer.send(conn, msg);
}
wiser.stop();
try (final SmtpSender.Connection conn = mailer.getConnection()) {
throw new AssertionError("Connection should fail now that there is no running mail server.");
} catch (final Exception ex) {
// Expected.
}
}
示例2: testSendMessage
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
/**
* Test that a Mailer can be retrieved via the KEWServiceLocator and can be used
* to send an e-mail message to the SMTP server.
*/
@Test
public void testSendMessage() {
// Initialize SMTP server
Wiser smtpServer = new Wiser();
smtpServer.setPort(55000);
smtpServer.start();
// Test that a Mailer can be retrieved via the KEWServiceLocator
Mailer mailer = null;
mailer = CoreApiServiceLocator.getMailer();
assertNotNull(mailer);
// Test that an e-mail message gets sent to the SMTP server
mailer.sendEmail(new EmailFrom(sender), new EmailTo(recipient), new EmailSubject(subject), new EmailBody(messageBody), false);
Assert.assertEquals(1, smtpServer.getMessages().size());
// Shutdown the SMTP server
smtpServer.stop();
}
示例3: testExecute
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testExecute() throws Exception {
// start SMTP Server
Wiser wiser = new Wiser();
wiser.setPort(2525);
wiser.start();
passwordHintAction.setUsername("user");
assertEquals("success", passwordHintAction.execute());
assertFalse(passwordHintAction.hasActionErrors());
// verify an account information e-mail was sent
wiser.stop();
assertTrue(wiser.getMessages().size() == 1);
// verify that success messages are in the request
assertNotNull(passwordHintAction.getSession().getAttribute("messages"));
}
示例4: testSend
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testSend() throws Exception {
// mock smtp server
Wiser wiser = new Wiser();
// set the port to a random value so there's no conflicts between tests
int port = 2525 + (int) (Math.random() * 100);
mailSender.setPort(port);
wiser.setPort(port);
wiser.start();
Date dte = new Date();
this.mailMessage.setTo("[email protected]");
String emailSubject = "grepster testSend: " + dte;
String emailBody = "Body of the grepster testSend message sent at: "
+ dte;
this.mailMessage.setSubject(emailSubject);
this.mailMessage.setText(emailBody);
this.mailEngine.send(this.mailMessage);
wiser.stop();
assertTrue(wiser.getMessages().size() == 1);
WiserMessage wm = wiser.getMessages().get(0);
assertEquals(emailSubject, wm.getMimeMessage().getSubject());
assertEquals(emailBody, wm.getMimeMessage().getContent());
}
示例5: testTimeout
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
/** */
@Test
public void testTimeout() throws Exception {
Wiser wiser = new Wiser();
wiser.setPort(PORT);
wiser.getServer().setConnectionTimeout(1000);
wiser.start();
SMTPClient client = new SMTPClient("localhost", PORT);
client.sendReceive("HELO foo");
Thread.sleep(2000);
try {
client.sendReceive("HELO bar");
fail();
} catch (SocketException e) {
// expected
} finally {
wiser.stop();
}
}
示例6: testRequestRecoveryToken
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testRequestRecoveryToken() throws Exception {
String username = "admin";
MockHttpServletRequest request = newGet("/updatePassword");
request.addParameter("username", username);
// start SMTP Server
Wiser wiser = new Wiser();
wiser.setPort(getSmtpPort());
wiser.start();
controller.requestRecoveryToken(username, request);
// verify an account information e-mail was sent
wiser.stop();
assertTrue(wiser.getMessages().size() == 1);
// verify that success messages are in the session
assertNotNull(request.getSession().getAttribute(Constants.SUCCESS_MESSAGES_KEY));
}
示例7: testResetPassword
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testResetPassword() throws Exception {
String username = "admin";
User user = userManager.getUserByUsername(username);
String token = userManager.generateRecoveryToken(user);
String password = "new-pass";
MockHttpServletRequest request = newGet("/updatePassword");
request.addParameter("username", username);
request.addParameter("token", token);
request.addParameter("password", password);
Wiser wiser = new Wiser();
wiser.setPort(getSmtpPort());
wiser.start();
ModelAndView mav = controller.onSubmit(username, token, null, password, request);
wiser.stop();
assertTrue(wiser.getMessages().size() == 1);
assertNotNull(request.getSession().getAttribute(Constants.SUCCESS_MESSAGES_KEY));
assertNull(request.getSession().getAttribute(Constants.ERRORS_MESSAGES_KEY));
}
示例8: testExecute
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testExecute() throws Exception {
MockHttpServletRequest request = newGet("/passwordHint.html");
request.addParameter("username", "user");
// start SMTP Server
Wiser wiser = new Wiser();
wiser.setPort(getSmtpPort());
wiser.start();
c.handleRequest(request);
// verify an account information e-mail was sent
wiser.stop();
assertTrue(wiser.getMessages().size() == 1);
// verify that success messages are in the session
assertNotNull(request.getSession().getAttribute(Constants.SUCCESS_MESSAGES_KEY));
}
示例9: testSend
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testSend() throws Exception {
// mock smtp server
Wiser wiser = new Wiser();
// set the port to a random value so there's no conflicts between tests
int port = 2525 + (int)(Math.random() * 100);
mailSender.setPort(port);
wiser.setPort(port);
wiser.start();
Date dte = new Date();
this.mailMessage.setTo("[email protected]");
String emailSubject = "grepster testSend: " + dte;
String emailBody = "Body of the grepster testSend message sent at: " + dte;
this.mailMessage.setSubject(emailSubject);
this.mailMessage.setText(emailBody);
this.mailEngine.send(this.mailMessage);
wiser.stop();
assertTrue(wiser.getMessages().size() == 1);
WiserMessage wm = wiser.getMessages().get(0);
assertEquals(emailSubject, wm.getMimeMessage().getSubject());
assertEquals(emailBody, wm.getMimeMessage().getContent());
}
示例10: testConsumeRecoveryToken
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testConsumeRecoveryToken() throws Exception {
final User user = userManager.getUserByUsername("user");
final Integer version = user.getVersion();
final String token = passwordTokenManager.generateRecoveryToken(user);
Assert.assertNotNull(token);
Assert.assertTrue(passwordTokenManager.isRecoveryTokenValid(user, token));
// start SMTP Server
final Wiser wiser = new Wiser();
wiser.setPort(smtpPort);
wiser.start();
userManager.updatePassword(user.getUsername(), null, token, "user", "");
wiser.stop();
assertTrue(wiser.getMessages().size() == 1);
Assert.assertTrue(user.getVersion() > version);
Assert.assertFalse(passwordTokenManager.isRecoveryTokenValid(user, token));
}
示例11: testSendMessageWithAttachment
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testSendMessageWithAttachment() throws Exception {
final String ATTACHMENT_NAME = "boring-attachment.txt";
// mock smtp server
Wiser wiser = new Wiser();
int port = 2525 + (int) (Math.random() * 100);
mailSender.setPort(port);
wiser.setPort(port);
wiser.start();
Date dte = new Date();
String emailSubject = "grepster testSendMessageWithAttachment: " + dte;
String emailBody = "Body of the grepster testSendMessageWithAttachment message sent at: "
+ dte;
ClassPathResource cpResource = new ClassPathResource(
"/test-attachment.txt");
mailEngine.sendMessage(new String[] { "[email protected]" }, mailMessage
.getFrom(), cpResource, emailBody, emailSubject,
ATTACHMENT_NAME);
wiser.stop();
assertTrue(wiser.getMessages().size() == 1);
WiserMessage wm = wiser.getMessages().get(0);
MimeMessage mm = wm.getMimeMessage();
Object o = wm.getMimeMessage().getContent();
assertTrue(o instanceof MimeMultipart);
MimeMultipart multi = (MimeMultipart) o;
int numOfParts = multi.getCount();
boolean hasTheAttachment = false;
for (int i = 0; i < numOfParts; i++) {
BodyPart bp = multi.getBodyPart(i);
String disp = bp.getDisposition();
if (disp == null) { // the body of the email
Object innerContent = bp.getContent();
MimeMultipart innerMulti = (MimeMultipart) innerContent;
assertEquals(emailBody, innerMulti.getBodyPart(0).getContent());
} else if (disp.equals(Part.ATTACHMENT)) { // the attachment to the
// email
hasTheAttachment = true;
assertEquals(ATTACHMENT_NAME, bp.getFileName());
} else {
fail("Did not expect to be able to get here.");
}
}
assertTrue(hasTheAttachment);
assertEquals(emailSubject, mm.getSubject());
}
示例12: startStop
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
/** */
private void startStop(boolean pause) throws Exception
{
Wiser wiser = new Wiser();
wiser.setPort(PORT);
wiser.start();
if (pause)
Thread.sleep(1000);
wiser.stop();
this.counter++;
}
示例13: testSendMessageWithAttachment
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testSendMessageWithAttachment() throws Exception {
final String ATTACHMENT_NAME = "boring-attachment.txt";
//mock smtp server
Wiser wiser = new Wiser();
int port = 2525 + (int)(Math.random() * 100);
mailSender.setPort(port);
wiser.setPort(port);
wiser.start();
Date dte = new Date();
String emailSubject = "grepster testSendMessageWithAttachment: " + dte;
String emailBody = "Body of the grepster testSendMessageWithAttachment message sent at: " + dte;
ClassPathResource cpResource = new ClassPathResource("/test-attachment.txt");
// a null from should work
mailEngine.sendMessage(new String[] {
"[email protected]"
}, null, cpResource, emailBody, emailSubject, ATTACHMENT_NAME);
mailEngine.sendMessage(new String[] {
"[email protected]"
}, mailMessage.getFrom(), cpResource, emailBody, emailSubject, ATTACHMENT_NAME);
wiser.stop();
// one without and one with from
assertTrue(wiser.getMessages().size() == 2);
WiserMessage wm = wiser.getMessages().get(0);
MimeMessage mm = wm.getMimeMessage();
Object o = wm.getMimeMessage().getContent();
assertTrue(o instanceof MimeMultipart);
MimeMultipart multi = (MimeMultipart)o;
int numOfParts = multi.getCount();
boolean hasTheAttachment = false;
for (int i = 0; i < numOfParts; i++) {
BodyPart bp = multi.getBodyPart(i);
String disp = bp.getDisposition();
if (disp == null) { //the body of the email
Object innerContent = bp.getContent();
MimeMultipart innerMulti = (MimeMultipart)innerContent;
assertEquals(emailBody, innerMulti.getBodyPart(0).getContent());
} else if (disp.equals(Part.ATTACHMENT)) { //the attachment to the email
hasTheAttachment = true;
assertEquals(ATTACHMENT_NAME, bp.getFileName());
} else {
fail("Did not expect to be able to get here.");
}
}
assertTrue(hasTheAttachment);
assertEquals(emailSubject, mm.getSubject());
}
示例14: testActivate
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testActivate() throws Exception {
// start SMTP Server
Wiser wiser = new Wiser();
wiser.setPort(getSmtpPort());
wiser.start();
doc = tester.renderPage("passwordRecoveryToken/admin");
// verify an account information e-mail was sent
wiser.stop();
assertTrue(wiser.getMessages().size() == 1);
assertTextPresent(doc, "A password reset link was sent to your registered email address.");
}
示例15: testNewUserSignup
import org.subethamail.wiser.Wiser; //导入方法依赖的package包/类
@Test
public void testNewUserSignup() {
doc = tester.renderPage("Signup");
Element form = doc.getElementById("form");
assertNotNull("form exists", form);
fieldValues.put("username", "self-registered");
fieldValues.put("password", "Password1");
fieldValues.put("confirmPassword", "Password1");
fieldValues.put("firstName", "First");
fieldValues.put("lastName", "Last");
fieldValues.put("email", "[email protected]");
fieldValues.put("website", "http://raibledesigns.com");
fieldValues.put("passwordHint", "Password is one with you.");
fieldValues.put("city", "Denver");
fieldValues.put("state", "CO");
fieldValues.put("country", "USA");
fieldValues.put("postalCode", "80210");
// start SMTP Server
Wiser wiser = new Wiser();
wiser.setPort(getSmtpPort());
wiser.start();
TestableResponse response = tester.submitFormAndReturnResponse(form, fieldValues);
assertFalse(response.getOutput().contains("exception"));
// verify an account information e-mail was sent
assertEquals(1, wiser.getMessages().size());
wiser.stop();
SecurityContextHolder.getContext().setAuthentication(null);
}