Java Code Examples for org.springframework.mail.MailSendException#printStackTrace()

The following examples show how to use org.springframework.mail.MailSendException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaMailSenderTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void failedMailServerConnect() {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost(null);
	sender.setUsername("username");
	sender.setPassword("password");
	SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
	try {
		sender.send(simpleMessage1);
		fail("Should have thrown MailSendException");
	}
	catch (MailSendException ex) {
		// expected
		ex.printStackTrace();
		assertTrue(ex.getFailedMessages() != null);
		assertEquals(1, ex.getFailedMessages().size());
		assertSame(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
		assertSame(ex.getCause(), ex.getFailedMessages().values().iterator().next());
	}
}
 
Example 2
Source File: JavaMailSenderTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void failedMailServerClose() {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("");
	sender.setUsername("username");
	sender.setPassword("password");
	SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
	try {
		sender.send(simpleMessage1);
		fail("Should have thrown MailSendException");
	}
	catch (MailSendException ex) {
		// expected
		ex.printStackTrace();
		assertTrue(ex.getFailedMessages() != null);
		assertEquals(0, ex.getFailedMessages().size());
	}
}
 
Example 3
Source File: JavaMailSenderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void failedMailServerConnect() {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost(null);
	sender.setUsername("username");
	sender.setPassword("password");
	SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
	try {
		sender.send(simpleMessage1);
		fail("Should have thrown MailSendException");
	}
	catch (MailSendException ex) {
		// expected
		ex.printStackTrace();
		assertTrue(ex.getFailedMessages() != null);
		assertEquals(1, ex.getFailedMessages().size());
		assertSame(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
		assertSame(ex.getCause(), ex.getFailedMessages().values().iterator().next());
	}
}
 
Example 4
Source File: JavaMailSenderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void failedMailServerClose() {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("");
	sender.setUsername("username");
	sender.setPassword("password");
	SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
	try {
		sender.send(simpleMessage1);
		fail("Should have thrown MailSendException");
	}
	catch (MailSendException ex) {
		// expected
		ex.printStackTrace();
		assertTrue(ex.getFailedMessages() != null);
		assertEquals(0, ex.getFailedMessages().size());
	}
}
 
Example 5
Source File: JavaMailSenderTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void failedMailServerConnect() throws Exception {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost(null);
	sender.setUsername("username");
	sender.setPassword("password");
	SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
	try {
		sender.send(simpleMessage1);
		fail("Should have thrown MailSendException");
	}
	catch (MailSendException ex) {
		// expected
		ex.printStackTrace();
		assertTrue(ex.getFailedMessages() != null);
		assertEquals(1, ex.getFailedMessages().size());
		assertSame(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
		assertSame(ex.getCause(), ex.getFailedMessages().values().iterator().next());
	}
}
 
Example 6
Source File: JavaMailSenderTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void failedMailServerClose() throws Exception {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("");
	sender.setUsername("username");
	sender.setPassword("password");
	SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
	try {
		sender.send(simpleMessage1);
		fail("Should have thrown MailSendException");
	}
	catch (MailSendException ex) {
		// expected
		ex.printStackTrace();
		assertTrue(ex.getFailedMessages() != null);
		assertEquals(0, ex.getFailedMessages().size());
	}
}
 
Example 7
Source File: JavaMailSenderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void failedSimpleMessage() throws MessagingException {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("host");
	sender.setUsername("username");
	sender.setPassword("password");

	SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
	simpleMessage1.setTo("[email protected]");
	simpleMessage1.setSubject("fail");
	SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
	simpleMessage2.setTo("[email protected]");

	try {
		sender.send(simpleMessage1, simpleMessage2);
	}
	catch (MailSendException ex) {
		ex.printStackTrace();
		assertEquals("host", sender.transport.getConnectedHost());
		assertEquals("username", sender.transport.getConnectedUsername());
		assertEquals("password", sender.transport.getConnectedPassword());
		assertTrue(sender.transport.isCloseCalled());
		assertEquals(1, sender.transport.getSentMessages().size());
		assertEquals(new InternetAddress("[email protected]"), sender.transport.getSentMessage(0).getAllRecipients()[0]);
		assertEquals(1, ex.getFailedMessages().size());
		assertEquals(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
		Object subEx = ex.getFailedMessages().values().iterator().next();
		assertTrue(subEx instanceof MessagingException);
		assertEquals("failed", ((MessagingException) subEx).getMessage());
	}
}
 
Example 8
Source File: JavaMailSenderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void failedMimeMessage() throws MessagingException {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("host");
	sender.setUsername("username");
	sender.setPassword("password");

	MimeMessage mimeMessage1 = sender.createMimeMessage();
	mimeMessage1.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
	mimeMessage1.setSubject("fail");
	MimeMessage mimeMessage2 = sender.createMimeMessage();
	mimeMessage2.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));

	try {
		sender.send(mimeMessage1, mimeMessage2);
	}
	catch (MailSendException ex) {
		ex.printStackTrace();
		assertEquals("host", sender.transport.getConnectedHost());
		assertEquals("username", sender.transport.getConnectedUsername());
		assertEquals("password", sender.transport.getConnectedPassword());
		assertTrue(sender.transport.isCloseCalled());
		assertEquals(1, sender.transport.getSentMessages().size());
		assertEquals(mimeMessage2, sender.transport.getSentMessage(0));
		assertEquals(1, ex.getFailedMessages().size());
		assertEquals(mimeMessage1, ex.getFailedMessages().keySet().iterator().next());
		Object subEx = ex.getFailedMessages().values().iterator().next();
		assertTrue(subEx instanceof MessagingException);
		assertEquals("failed", ((MessagingException) subEx).getMessage());
	}
}
 
Example 9
Source File: JavaMailSenderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void failedSimpleMessage() throws MessagingException {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("host");
	sender.setUsername("username");
	sender.setPassword("password");

	SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
	simpleMessage1.setTo("[email protected]");
	simpleMessage1.setSubject("fail");
	SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
	simpleMessage2.setTo("[email protected]");

	try {
		sender.send(simpleMessage1, simpleMessage2);
	}
	catch (MailSendException ex) {
		ex.printStackTrace();
		assertEquals("host", sender.transport.getConnectedHost());
		assertEquals("username", sender.transport.getConnectedUsername());
		assertEquals("password", sender.transport.getConnectedPassword());
		assertTrue(sender.transport.isCloseCalled());
		assertEquals(1, sender.transport.getSentMessages().size());
		assertEquals(new InternetAddress("[email protected]"), sender.transport.getSentMessage(0).getAllRecipients()[0]);
		assertEquals(1, ex.getFailedMessages().size());
		assertEquals(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
		Object subEx = ex.getFailedMessages().values().iterator().next();
		assertTrue(subEx instanceof MessagingException);
		assertEquals("failed", ((MessagingException) subEx).getMessage());
	}
}
 
Example 10
Source File: JavaMailSenderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void failedMimeMessage() throws MessagingException {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("host");
	sender.setUsername("username");
	sender.setPassword("password");

	MimeMessage mimeMessage1 = sender.createMimeMessage();
	mimeMessage1.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
	mimeMessage1.setSubject("fail");
	MimeMessage mimeMessage2 = sender.createMimeMessage();
	mimeMessage2.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));

	try {
		sender.send(mimeMessage1, mimeMessage2);
	}
	catch (MailSendException ex) {
		ex.printStackTrace();
		assertEquals("host", sender.transport.getConnectedHost());
		assertEquals("username", sender.transport.getConnectedUsername());
		assertEquals("password", sender.transport.getConnectedPassword());
		assertTrue(sender.transport.isCloseCalled());
		assertEquals(1, sender.transport.getSentMessages().size());
		assertEquals(mimeMessage2, sender.transport.getSentMessage(0));
		assertEquals(1, ex.getFailedMessages().size());
		assertEquals(mimeMessage1, ex.getFailedMessages().keySet().iterator().next());
		Object subEx = ex.getFailedMessages().values().iterator().next();
		assertTrue(subEx instanceof MessagingException);
		assertEquals("failed", ((MessagingException) subEx).getMessage());
	}
}
 
Example 11
Source File: JavaMailSenderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void failedSimpleMessage() throws Exception {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("host");
	sender.setUsername("username");
	sender.setPassword("password");

	SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
	simpleMessage1.setTo("[email protected]");
	simpleMessage1.setSubject("fail");
	SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
	simpleMessage2.setTo("[email protected]");

	try {
		sender.send(simpleMessage1, simpleMessage2);
	}
	catch (MailSendException ex) {
		ex.printStackTrace();
		assertEquals("host", sender.transport.getConnectedHost());
		assertEquals("username", sender.transport.getConnectedUsername());
		assertEquals("password", sender.transport.getConnectedPassword());
		assertTrue(sender.transport.isCloseCalled());
		assertEquals(1, sender.transport.getSentMessages().size());
		assertEquals(new InternetAddress("[email protected]"), sender.transport.getSentMessage(0).getAllRecipients()[0]);
		assertEquals(1, ex.getFailedMessages().size());
		assertEquals(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
		Object subEx = ex.getFailedMessages().values().iterator().next();
		assertTrue(subEx instanceof MessagingException);
		assertEquals("failed", ((MessagingException) subEx).getMessage());
	}
}
 
Example 12
Source File: JavaMailSenderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void fFailedMimeMessage() throws Exception {
	MockJavaMailSender sender = new MockJavaMailSender();
	sender.setHost("host");
	sender.setUsername("username");
	sender.setPassword("password");

	MimeMessage mimeMessage1 = sender.createMimeMessage();
	mimeMessage1.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
	mimeMessage1.setSubject("fail");
	MimeMessage mimeMessage2 = sender.createMimeMessage();
	mimeMessage2.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));

	try {
		sender.send(mimeMessage1, mimeMessage2);
	}
	catch (MailSendException ex) {
		ex.printStackTrace();
		assertEquals("host", sender.transport.getConnectedHost());
		assertEquals("username", sender.transport.getConnectedUsername());
		assertEquals("password", sender.transport.getConnectedPassword());
		assertTrue(sender.transport.isCloseCalled());
		assertEquals(1, sender.transport.getSentMessages().size());
		assertEquals(mimeMessage2, sender.transport.getSentMessage(0));
		assertEquals(1, ex.getFailedMessages().size());
		assertEquals(mimeMessage1, ex.getFailedMessages().keySet().iterator().next());
		Object subEx = ex.getFailedMessages().values().iterator().next();
		assertTrue(subEx instanceof MessagingException);
		assertEquals("failed", ((MessagingException) subEx).getMessage());
	}
}