use of org.apache.mailet.Mail in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet_service_Test method testService_ProcessThrowsSmtpAgentException_AssertExceptionAndGhostState.
public void testService_ProcessThrowsSmtpAgentException_AssertExceptionAndGhostState() throws Exception {
final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
final SmtpAgent mockAgent = mock(SmtpAgent.class);
final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
when(mockMail.getRecipients()).thenReturn(null);
when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
doThrow(new SmtpAgentException(SmtpAgentError.Unknown, "Just Passing Through")).when(mockAgent).processMessage((MimeMessage) any(), (NHINDAddressCollection) any(), (NHINDAddress) any());
mockMail.setMessage(mimeMsg);
NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
mailet.agent = mockAgent;
boolean exceptionOccured = false;
try {
mailet.service(mockMail);
} catch (SmtpAgentException e) {
assertEquals(SmtpAgentError.Unknown, e.getError());
assertEquals("Just Passing Through", e.getMessage());
exceptionOccured = true;
}
assertFalse(exceptionOccured);
assertEquals(Mail.GHOST, mockMail.getState());
}
use of org.apache.mailet.Mail in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet_service_Test method testService_UseToHeader_AssertRecipientsUsed.
public void testService_UseToHeader_AssertRecipientsUsed() throws Exception {
final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
final SmtpAgent mockAgent = mock(SmtpAgent.class);
when(mockAgent.processMessage((MimeMessage) any(), (NHINDAddressCollection) any(), (NHINDAddress) any())).thenAnswer(new Answer<MessageProcessResult>() {
public MessageProcessResult answer(InvocationOnMock invocation) throws Throwable {
usedRecipients = (NHINDAddressCollection) invocation.getArguments()[1];
return new MessageProcessResult(new DefaultMessageEnvelope(new Message(mimeMsg)), null);
}
});
final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
when(mockMail.getRecipients()).thenReturn(null);
when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
mockMail.setMessage(mimeMsg);
NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
mailet.agent = mockAgent;
mailet.service(mockMail);
assertNotNull(usedRecipients);
assertEquals(1, usedRecipients.size());
assertEquals("externUser1@starugh-stateline.com", usedRecipients.iterator().next().toString());
}
use of org.apache.mailet.Mail in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet_service_Test method testService_ProcessIsNull_AssertGhostState.
public void testService_ProcessIsNull_AssertGhostState() throws Exception {
final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
final SmtpAgent mockAgent = mock(SmtpAgent.class);
final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
when(mockMail.getRecipients()).thenReturn(null);
when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
mockMail.setMessage(mimeMsg);
NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
mailet.agent = mockAgent;
mailet.service(mockMail);
assertEquals(Mail.GHOST, mockMail.getState());
}
use of org.apache.mailet.Mail in project nhin-d by DirectProject.
the class RecipAndSenderIsNotLocalTest method testMatch_LocalSender_LocalAndRemoteRcpt_AssertRemoteRcptReturned.
public void testMatch_LocalSender_LocalAndRemoteRcpt_AssertRemoteRcptReturned() throws Exception {
final Mail mockMail = mock(Mail.class);
when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
when(mockMail.getRecipients()).thenReturn(Arrays.asList(new MailAddress("you@cerner.com"), new MailAddress("someone@remoteMail.com")));
final MatcherConfig newConfig = mock(MatcherConfig.class);
when(newConfig.getCondition()).thenReturn("cerner.com");
RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
matcher.init(newConfig);
Collection<MailAddress> matchAddresses = matcher.match(mockMail);
assertEquals(1, matchAddresses.size());
assertEquals("someone@remoteMail.com", matchAddresses.iterator().next().toString());
}
use of org.apache.mailet.Mail in project nhin-d by DirectProject.
the class RecipAndSenderIsNotLocalTest method testMatch_LocalSender_LocalRcpt_AssertNoneReturned.
public void testMatch_LocalSender_LocalRcpt_AssertNoneReturned() throws Exception {
final Mail mockMail = mock(Mail.class);
when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
when(mockMail.getRecipients()).thenReturn(Arrays.asList(new MailAddress("you@cerner.com")));
final MatcherConfig newConfig = mock(MatcherConfig.class);
when(newConfig.getCondition()).thenReturn("cerner.com");
RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
matcher.init(newConfig);
Collection<MailAddress> matchAddresses = matcher.match(mockMail);
assertEquals(0, matchAddresses.size());
}
Aggregations