JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost(NetworkAddressUtil.LOOPBACK_ADDRESS);
sender.setProtocol(JavaMailSenderImpl.DEFAULT_PROTOCOL);
sender.setPort(port);
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("from@com.springsource.insight.plugin.mail");
message.setTo("to@com.springsource.insight.plugin.mail");
message.setCc("cc@com.springsource.insight.plugin.mail");
message.setBcc("bcc@com.springsource.insight.plugin.mail");
Date now = new Date(System.currentTimeMillis());
message.setSentDate(now);
message.setSubject(now.toString());
message.setText("Test at " + now.toString());
sender.send(message);
Operation op = getLastEntered();
assertNotNull("No operation extracted", op);
assertEquals("Mismatched operation type", MailDefinitions.SEND_OPERATION, op.getType());
assertEquals("Mismatched protocol", sender.getProtocol(), op.get(MailDefinitions.SEND_PROTOCOL, String.class));
assertEquals("Mismatched host", sender.getHost(), op.get(MailDefinitions.SEND_HOST, String.class));
if (port == -1) {
assertEquals("Mismatched default port", 25, op.getInt(MailDefinitions.SEND_PORT, (-1)));
} else {
assertEquals("Mismatched send port", sender.getPort(), op.getInt(MailDefinitions.SEND_PORT, (-1)));
}
if (getAspect().collectExtraInformation()) {
assertAddresses(op, MailDefinitions.SEND_SENDERS, 1);
assertAddresses(op, MailDefinitions.SEND_RECIPS, 3);
OperationMap details = op.get(MailDefinitions.SEND_DETAILS, OperationMap.class);
assertNotNull("No details extracted", details);
assertEquals("Mismatched subject", message.getSubject(), details.get(MailDefinitions.SEND_SUBJECT, String.class));
}
}